1
1
import { flatten } from './utils/list' ;
2
- import { shallowMerge , getAttributes } from './utils/object' ;
2
+ import { getAttributes , merge } from './utils/object' ;
3
3
import { parseDuration } from './utils/time' ;
4
4
import { findChildren , getContent } from './utils/xml' ;
5
5
import resolveUrl from './utils/resolveUrl' ;
@@ -52,7 +52,7 @@ export const getSegmentInformation = (adaptationSet) => {
52
52
const segmentTemplate = findChildren ( adaptationSet , 'SegmentTemplate' ) [ 0 ] ;
53
53
const segmentList = findChildren ( adaptationSet , 'SegmentList' ) [ 0 ] ;
54
54
const segmentUrls = segmentList && findChildren ( segmentList , 'SegmentURL' )
55
- . map ( s => shallowMerge ( { tag : 'SegmentURL' } , getAttributes ( s ) ) ) ;
55
+ . map ( s => merge ( { tag : 'SegmentURL' } , getAttributes ( s ) ) ) ;
56
56
const segmentBase = findChildren ( adaptationSet , 'SegmentBase' ) [ 0 ] ;
57
57
const segmentTimelineParentNode = segmentList || segmentTemplate ;
58
58
const segmentTimeline = segmentTimelineParentNode &&
@@ -78,21 +78,29 @@ export const getSegmentInformation = (adaptationSet) => {
78
78
template . initialization = { sourceURL : template . initialization } ;
79
79
}
80
80
81
- return {
81
+ const segmentInfo = {
82
82
template,
83
83
timeline : segmentTimeline &&
84
84
findChildren ( segmentTimeline , 'S' ) . map ( s => getAttributes ( s ) ) ,
85
- list : segmentList && shallowMerge (
85
+ list : segmentList && merge (
86
86
getAttributes ( segmentList ) ,
87
87
{
88
88
segmentUrls,
89
89
initialization : getAttributes ( segmentInitialization )
90
90
} ) ,
91
- base : segmentBase && shallowMerge (
91
+ base : segmentBase && merge (
92
92
getAttributes ( segmentBase ) , {
93
93
initialization : getAttributes ( segmentInitialization )
94
94
} )
95
95
} ;
96
+
97
+ Object . keys ( segmentInfo ) . forEach ( key => {
98
+ if ( ! segmentInfo [ key ] ) {
99
+ delete segmentInfo [ key ] ;
100
+ }
101
+ } ) ;
102
+
103
+ return segmentInfo ;
96
104
} ;
97
105
98
106
/**
@@ -131,15 +139,16 @@ export const getSegmentInformation = (adaptationSet) => {
131
139
* Callback map function
132
140
*/
133
141
export const inheritBaseUrls =
134
- ( adaptationSetAttributes , adaptationSetBaseUrls , segmentInfo ) => ( representation ) => {
142
+ ( adaptationSetAttributes , adaptationSetBaseUrls , adaptationSetSegmentInfo ) => ( representation ) => {
135
143
const repBaseUrlElements = findChildren ( representation , 'BaseURL' ) ;
136
144
const repBaseUrls = buildBaseUrls ( adaptationSetBaseUrls , repBaseUrlElements ) ;
137
- const attributes = shallowMerge ( adaptationSetAttributes , getAttributes ( representation ) ) ;
145
+ const attributes = merge ( adaptationSetAttributes , getAttributes ( representation ) ) ;
146
+ const representationSegmentInfo = getSegmentInformation ( representation ) ;
138
147
139
148
return repBaseUrls . map ( baseUrl => {
140
149
return {
141
- segmentInfo,
142
- attributes : shallowMerge ( attributes , { baseUrl } )
150
+ segmentInfo : merge ( adaptationSetSegmentInfo , representationSegmentInfo ) ,
151
+ attributes : merge ( attributes , { baseUrl } )
143
152
} ;
144
153
} ) ;
145
154
} ;
@@ -167,20 +176,21 @@ export const inheritBaseUrls =
167
176
* Callback map function
168
177
*/
169
178
export const toRepresentations =
170
- ( periodAttributes , periodBaseUrls ) => ( adaptationSet ) => {
179
+ ( periodAttributes , periodBaseUrls , periodSegmentInfo ) => ( adaptationSet ) => {
171
180
const adaptationSetAttributes = getAttributes ( adaptationSet ) ;
172
181
const adaptationSetBaseUrls = buildBaseUrls ( periodBaseUrls ,
173
182
findChildren ( adaptationSet , 'BaseURL' ) ) ;
174
183
const role = findChildren ( adaptationSet , 'Role' ) [ 0 ] ;
175
184
const roleAttributes = { role : getAttributes ( role ) } ;
176
- const attrs = shallowMerge ( periodAttributes ,
185
+ const attrs = merge ( periodAttributes ,
177
186
adaptationSetAttributes ,
178
187
roleAttributes ) ;
179
188
const segmentInfo = getSegmentInformation ( adaptationSet ) ;
180
189
const representations = findChildren ( adaptationSet , 'Representation' ) ;
190
+ const adaptationSetSegmentInfo = merge ( periodSegmentInfo , segmentInfo ) ;
181
191
182
192
return flatten (
183
- representations . map ( inheritBaseUrls ( attrs , adaptationSetBaseUrls , segmentInfo ) ) ) ;
193
+ representations . map ( inheritBaseUrls ( attrs , adaptationSetBaseUrls , adaptationSetSegmentInfo ) ) ) ;
184
194
} ;
185
195
186
196
/**
@@ -210,10 +220,12 @@ export const toRepresentations =
210
220
*/
211
221
export const toAdaptationSets = ( mpdAttributes , mpdBaseUrls ) => ( period , periodIndex ) => {
212
222
const periodBaseUrls = buildBaseUrls ( mpdBaseUrls , findChildren ( period , 'BaseURL' ) ) ;
213
- const periodAttributes = shallowMerge ( { periodIndex } , mpdAttributes ) ;
223
+ const periodAtt = getAttributes ( period ) ;
224
+ const periodAttributes = merge ( mpdAttributes , periodAtt , { periodIndex } ) ;
214
225
const adaptationSets = findChildren ( period , 'AdaptationSet' ) ;
226
+ const periodSegmentInfo = getSegmentInformation ( period ) ;
215
227
216
- return flatten ( adaptationSets . map ( toRepresentations ( periodAttributes , periodBaseUrls ) ) ) ;
228
+ return flatten ( adaptationSets . map ( toRepresentations ( periodAttributes , periodBaseUrls , periodSegmentInfo ) ) ) ;
217
229
} ;
218
230
219
231
/**
@@ -243,4 +255,3 @@ export const inheritAttributes = (mpd, manifestUri = '') => {
243
255
244
256
return flatten ( periods . map ( toAdaptationSets ( mpdAttributes , mpdBaseUrls ) ) ) ;
245
257
} ;
246
-
0 commit comments