Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple custom tags with the same name #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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