Skip to content

Commit

Permalink
Allow multiple custom tags with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
grihabor committed Nov 21, 2019
1 parent 2ce07e6 commit 7ff919e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (p *MasterPlaylist) DecodeFrom(reader io.Reader, strict bool) error {
func (p *MasterPlaylist) WithCustomDecoders(customDecoders []CustomDecoder) Playlist {
// Create the map if it doesn't already exist
if p.Custom == nil {
p.Custom = make(map[string]CustomTag)
p.Custom = make([]CustomTag, 0)
}

p.customDecoders = customDecoders
Expand Down Expand Up @@ -282,7 +282,7 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st
return err
}

p.Custom[t.TagName()] = t
p.Custom = append(p.Custom, t)
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,23 @@ func TestDecodeMasterPlaylistWithCustomTags(t *testing.T) {
} else {
// we have the same count, lets confirm its the right tags
for _, expectedTag := range testCase.expectedPlaylistTags {
if _, ok := pp.Custom[expectedTag]; !ok {
if !findCustomTag(pp.Custom, expectedTag) {
t.Errorf("Did not parse custom tag %s", expectedTag)
}
}
}
}
}

func findCustomTag(tags []CustomTag, targetName string) bool {
for _, t := range tags {
if t.TagName() == targetName {
return true
}
}
return false
}

func TestDecodeMediaPlaylistWithCustomTags(t *testing.T) {
cases := []struct {
src string
Expand Down
2 changes: 1 addition & 1 deletion structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type MasterPlaylist struct {
buf bytes.Buffer
ver uint8
independentSegments bool
Custom map[string]CustomTag
Custom []CustomTag
customDecoders []CustomDecoder
}

Expand Down
4 changes: 2 additions & 2 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
// SetCustomTag sets the provided tag on the master playlist for its TagName
func (p *MasterPlaylist) SetCustomTag(tag CustomTag) {
if p.Custom == nil {
p.Custom = make(map[string]CustomTag)
p.Custom = make([]CustomTag, 0)
}

p.Custom[tag.TagName()] = tag
p.Custom = append(p.Custom, tag)
}

// Version returns the current playlist version number
Expand Down

0 comments on commit 7ff919e

Please sign in to comment.