Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
parse custom tags first
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Neil committed Jun 26, 2019
1 parent 23b66b5 commit e08fbda
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st

line = strings.TrimSpace(line)

// check for custom tags first to allow custom parsing of existing tags
if p.Custom != nil {
for _, v := range p.customDecoders {
if strings.HasPrefix(line, v.TagName()) {
t, err := v.Decode(line)

if strict && err != nil {
return err
}

p.Custom[t.TagName()] = t
}
}
}

switch {
case line == "#EXTM3U": // start tag first
state.m3u = true
Expand Down Expand Up @@ -425,20 +440,7 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st
}
}
case strings.HasPrefix(line, "#"):
// if we have custom tags, check for those here, otherwise comments are ignored
if p.Custom != nil {
for _, v := range p.customDecoders {
if strings.HasPrefix(line, v.TagName()) {
t, err := v.Decode(line)

if strict && err != nil {
return err
}

p.Custom[t.TagName()] = t
}
}
}
// comments are ignored
}
return err
}
Expand All @@ -448,6 +450,27 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l
var err error

line = strings.TrimSpace(line)

// check for custom tags first to allow custom parsing of existing tags
if p.Custom != nil {
for _, v := range p.customDecoders {
if strings.HasPrefix(line, v.TagName()) {
t, err := v.Decode(line)

if strict && err != nil {
return err
}

if v.Segment() {
state.tagCustom = true
state.custom[v.TagName()] = t
} else {
p.Custom[v.TagName()] = t
}
}
}
}

switch {
case !state.tagInf && strings.HasPrefix(line, "#EXTINF:"):
state.tagInf = true
Expand Down Expand Up @@ -793,25 +816,7 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l
state.tagWV = true
}
case strings.HasPrefix(line, "#"):
// if we have custom tags, check for those here, otherwise comments are ignored
if p.Custom != nil {
for _, v := range p.customDecoders {
if strings.HasPrefix(line, v.TagName()) {
t, err := v.Decode(line)

if strict && err != nil {
return err
}

if v.Segment() {
state.tagCustom = true
state.custom[v.TagName()] = t
} else {
p.Custom[v.TagName()] = t
}
}
}
}
// comments are ignored
}
return err
}
Expand Down

0 comments on commit e08fbda

Please sign in to comment.