make attribute lists return a proper object
Showing
1 changed file
with
68 additions
and
14 deletions
... | @@ -97,7 +97,7 @@ mediaTag | ... | @@ -97,7 +97,7 @@ mediaTag |
97 | streamInfTag | 97 | streamInfTag |
98 | = tag:'#EXT-X-STREAM-INF' ":" attrs:streamInfAttrs _ url:mediaURL? { | 98 | = tag:'#EXT-X-STREAM-INF' ":" attrs:streamInfAttrs _ url:mediaURL? { |
99 | return {renditions: { | 99 | return {renditions: { |
100 | attributes: JSON.stringify(attrs), | 100 | attributes: attrs, |
101 | url: url | 101 | url: url |
102 | } | 102 | } |
103 | }; | 103 | }; |
... | @@ -135,8 +135,17 @@ mediaURL | ... | @@ -135,8 +135,17 @@ mediaURL |
135 | / ! tag file:[ -~]+ { return file.join(''); } | 135 | / ! tag file:[ -~]+ { return file.join(''); } |
136 | 136 | ||
137 | keyAttributes | 137 | keyAttributes |
138 | = attrs:(keyAttribute (attrSeparator streamInfAttrs)*) | 138 | = (attr:keyAttribute rest:(attrSeparator streamInfAttrs)*) { |
139 | / attrs:keyAttribute? | 139 | return rest.reduce(function(prev, curr) { |
140 | var p, | ||
141 | currentItem = curr.pop(); | ||
142 | for (p in currentItem) { | ||
143 | prev[p] = currentItem[p]; | ||
144 | }; | ||
145 | return prev; | ||
146 | }, attr); | ||
147 | } | ||
148 | / attr:keyAttribute? { return [attr]; } | ||
140 | 149 | ||
141 | keyAttribute | 150 | keyAttribute |
142 | = "METHOD" "=" method:keyMethod { return {keyMethod: method}; } | 151 | = "METHOD" "=" method:keyMethod { return {keyMethod: method}; } |
... | @@ -151,8 +160,17 @@ keyMethod | ... | @@ -151,8 +160,17 @@ keyMethod |
151 | / "SAMPLE-AES" | 160 | / "SAMPLE-AES" |
152 | 161 | ||
153 | mediaAttributes | 162 | mediaAttributes |
154 | = attrs:(mediaAttribute (attrSeparator mediaAttribute)*) | 163 | = (attr:mediaAttribute rest:(attrSeparator mediaAttribute)*) { |
155 | / attrs:mediaAttribute? | 164 | return rest.reduce(function(prev, curr) { |
165 | var p, | ||
166 | currentItem = curr.pop(); | ||
167 | for (p in currentItem) { | ||
168 | prev[p] = currentItem[p]; | ||
169 | }; | ||
170 | return prev; | ||
171 | }, attr); | ||
172 | } | ||
173 | / attr:mediaAttribute? { return [attr] } | ||
156 | 174 | ||
157 | mediaAttribute | 175 | mediaAttribute |
158 | = "TYPE" "=" type:mediaTypes { return {type: type}; } | 176 | = "TYPE" "=" type:mediaTypes { return {type: type}; } |
... | @@ -168,8 +186,17 @@ mediaAttribute | ... | @@ -168,8 +186,17 @@ mediaAttribute |
168 | / "CHARACTERISTICS" "=" characteristics:quotedString { return {characteristics: characteristics}; } | 186 | / "CHARACTERISTICS" "=" characteristics:quotedString { return {characteristics: characteristics}; } |
169 | 187 | ||
170 | streamInfAttrs | 188 | streamInfAttrs |
171 | = attrs:(streamInfAttr (attrSeparator streamInfAttr)*) | 189 | = (attr:streamInfAttr rest:(attrSeparator streamInfAttr)*) { |
172 | / attrs:streamInfAttr? | 190 | return rest.reduce(function(prev, curr) { |
191 | var p, | ||
192 | currentItem = curr.pop(); | ||
193 | for (p in currentItem) { | ||
194 | prev[p] = currentItem[p]; | ||
195 | }; | ||
196 | return prev; | ||
197 | }, attr); | ||
198 | } | ||
199 | / attr:streamInfAttr? | ||
173 | 200 | ||
174 | streamInfAttr | 201 | streamInfAttr |
175 | = streamInfSharedAttr | 202 | = streamInfSharedAttr |
... | @@ -186,24 +213,51 @@ streamInfSharedAttr | ... | @@ -186,24 +213,51 @@ streamInfSharedAttr |
186 | / "VIDEO" "=" video:quotedString { return {video: video}; } | 213 | / "VIDEO" "=" video:quotedString { return {video: video}; } |
187 | 214 | ||
188 | mapAttributes | 215 | mapAttributes |
189 | = attrs:(mapAttribute (attrSeparator mapAttribute)*) | 216 | = (attr:mapAttribute rest:(attrSeparator mapAttribute)*) { |
190 | / attrs:mapAttribute? | 217 | return rest.reduce(function(prev, curr) { |
218 | var p, | ||
219 | currentItem = curr.pop(); | ||
220 | for (p in currentItem) { | ||
221 | prev[p] = currentItem[p]; | ||
222 | }; | ||
223 | return prev; | ||
224 | }, attr); | ||
225 | } | ||
226 | / attr:mapAttribute? | ||
191 | 227 | ||
192 | mapAttribute | 228 | mapAttribute |
193 | = "URI" "=" uri:quotedString { return {uri: uri}; } | 229 | = "URI" "=" uri:quotedString { return {uri: uri}; } |
194 | / "BYTERANGE" "=" byteRange:quotedString { return {byterange: byterange}; } | 230 | / "BYTERANGE" "=" byteRange:quotedString { return {byterange: byterange}; } |
195 | 231 | ||
196 | iframeStreamAttrs | 232 | iframeStreamAttrs |
197 | = attrs:(iframeStreamAttr (attrSeparator iframeStreamAttr)*) | 233 | = (attr:iframeStreamAttr rest:(attrSeparator iframeStreamAttr)*) { |
198 | / attrs:iframeStreamAttr? | 234 | return rest.reduce(function(prev, curr) { |
235 | var p, | ||
236 | currentItem = curr.pop(); | ||
237 | for (p in currentItem) { | ||
238 | prev[p] = currentItem[p]; | ||
239 | }; | ||
240 | return prev; | ||
241 | }, attr); | ||
242 | } | ||
243 | / attr:iframeStreamAttr? | ||
199 | 244 | ||
200 | iframeStreamAttr | 245 | iframeStreamAttr |
201 | = streamInfSharedAttr | 246 | = streamInfSharedAttr |
202 | / "URI" "=" uri:quotedString { return {uri: uri}; } | 247 | / "URI" "=" uri:quotedString { return {uri: uri}; } |
203 | 248 | ||
204 | startAttributes | 249 | startAttributes |
205 | = attrs:(startAttribute (attrSeparator startAttribute)*) | 250 | = (attr:startAttribute rest:(attrSeparator startAttribute)*) { |
206 | / attrs:startAttribute? | 251 | return rest.reduce(function(prev, curr) { |
252 | var p, | ||
253 | currentItem = curr.pop(); | ||
254 | for (p in currentItem) { | ||
255 | prev[p] = currentItem[p]; | ||
256 | }; | ||
257 | return prev; | ||
258 | }, attr); | ||
259 | } | ||
260 | / attr:startAttribute? | ||
207 | 261 | ||
208 | startAttribute | 262 | startAttribute |
209 | = "TIME-OFFSET" "=" timeOffset:number { return {timeOffset: timeOffset}; } | 263 | = "TIME-OFFSET" "=" timeOffset:number { return {timeOffset: timeOffset}; } |
... | @@ -224,7 +278,7 @@ playlistType | ... | @@ -224,7 +278,7 @@ playlistType |
224 | / "VOD" | 278 | / "VOD" |
225 | 279 | ||
226 | attrSeparator | 280 | attrSeparator |
227 | = "," nonbreakingWhitespace | 281 | = "," nonbreakingWhitespace { return; } |
228 | 282 | ||
229 | /***** Date *****/ | 283 | /***** Date *****/ |
230 | 284 | ... | ... |
-
Please register or sign in to post a comment