Make comments, segments, and renditions arrays.
Comments, EXTINF tags, and EXT-STREAM-INF tags get turned into an array in the outputted format.
Showing
1 changed file
with
30 additions
and
15 deletions
1 | /***** Start *****/ | 1 | /***** Start *****/ |
2 | start | 2 | start |
3 | = tags:lines+ .* { | 3 | = tags:lines+ .* { |
4 | var obj = {}; | 4 | var obj = {}, |
5 | tags.forEach(function(tag) { for (var p in tag) { obj[p] = tag[p]; }}); | 5 | choices = { |
6 | segments: 1, | ||
7 | comments: 1, | ||
8 | renditions: 1 | ||
9 | }; | ||
10 | tags.forEach(function(tag) { | ||
11 | for (var p in tag) { | ||
12 | if (p in choices) { | ||
13 | if (Object.prototype.toString.call(obj[p]) === '[object Array]') { | ||
14 | obj[p].push(tag[p]); | ||
15 | } else { | ||
16 | obj[p] = [tag[p]]; | ||
17 | } | ||
18 | } else { | ||
19 | obj[p] = tag[p]; | ||
20 | } | ||
21 | } | ||
22 | }); | ||
6 | return obj; | 23 | return obj; |
7 | } | 24 | } |
8 | 25 | ||
9 | lines | 26 | lines |
10 | = comment:comment _ { var obj = {}; obj["comment" + line] = comment; return obj; } | 27 | = comment:comment _ { var obj = {}; obj["comments"] = comment; return obj; } |
11 | / ! comment tag:tag _ { return tag; } | 28 | / ! comment tag:tag _ { return tag; } |
12 | 29 | ||
13 | tag | 30 | tag |
... | @@ -41,14 +58,13 @@ m3uTag | ... | @@ -41,14 +58,13 @@ m3uTag |
41 | 58 | ||
42 | extinfTag | 59 | extinfTag |
43 | = tag:'#EXTINF' ":" duration:number "," optional:extinfOptionalParts _ file:mediaFile { | 60 | = tag:'#EXTINF' ":" duration:number "," optional:extinfOptionalParts _ file:mediaFile { |
44 | var fileObj = {}; | 61 | return {segments: { |
45 | fileObj[tag + line] = { | 62 | byteRange: optional.byteRange, |
46 | byteRange: optional.byteRange, | 63 | title: optional.title, |
47 | title: optional.title, | 64 | duration: duration, |
48 | duration: duration, | 65 | file: file |
49 | file: file | 66 | } |
50 | }; | 67 | }; |
51 | return fileObj; | ||
52 | } | 68 | } |
53 | 69 | ||
54 | byteRangeTag | 70 | byteRangeTag |
... | @@ -80,12 +96,11 @@ mediaTag | ... | @@ -80,12 +96,11 @@ mediaTag |
80 | 96 | ||
81 | streamInfTag | 97 | streamInfTag |
82 | = tag:'#EXT-X-STREAM-INF' ":" attrs:streamInfAttrs _ file:mediaFile? { | 98 | = tag:'#EXT-X-STREAM-INF' ":" attrs:streamInfAttrs _ file:mediaFile? { |
83 | var fileObj = {}; | 99 | return {renditions: { |
84 | fileObj[file] = { | 100 | attributes: attrs, |
85 | attributes: attrs, | 101 | file: file |
86 | file: file | 102 | } |
87 | }; | 103 | }; |
88 | return fileObj; | ||
89 | } | 104 | } |
90 | 105 | ||
91 | discontinuityTag | 106 | discontinuityTag | ... | ... |
-
Please register or sign in to post a comment