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

Duplicate Data Resulting from Custom Tags #201

Open
slipthebit opened this issue Sep 20, 2023 · 2 comments
Open

Duplicate Data Resulting from Custom Tags #201

slipthebit opened this issue Sep 20, 2023 · 2 comments

Comments

@slipthebit
Copy link

slipthebit commented Sep 20, 2023

CustomTags are parsed in twice when using DecodeWith. This happens because both decodeLineOfMasterPlaylist and decodeLineOfMediaPlaylist are called in decode, and both parse the CustomTags seperatley.

This issue can be observed using the Master Manifest, https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8, and CustomTag example in Issue #160 detailed by @slugalisk.

The Master Manifest includes 5 #EXT-X-MEDIA tags, but DecodeWith produces 10 Values for the CustomTag.

The go-playground link below duplicates the issue as of 9/20/2023 with v0.12.0
https://goplay.tools/snippet/e_p-kLnpqco

@slipthebit
Copy link
Author

slipthebit commented Sep 20, 2023

As a workaround to the issue, I filter out duplicates in the Custom Tag Decode function.

Using the example from Issue #160, I modified the Decode function to be:

func (tag *ExtXMediaTag) Decode(line string) (m3u8.CustomTag, error) {
	val := &ExtXMediaTagValue{}
	
         for k, v := range m3u8.DecodeAttributeList(line) {
		switch k {
		case "TYPE":
			val.Type = v
		case "GROUP-ID":
			val.GroupID = v
		case "CHANNELS":
			val.Channels = v
		case "NAME":
			val.Name = v
		case "LANGUAGE":
			val.Language = v
		case "DEFAULT":
			val.Default = v == "YES"
		case "AUTOSELECT":
			val.AutoSelect = v == "YES"
		case "FORCED":
			val.Forced = v == "YES"
		case "URI":
			val.URI = v
		}
	}
	
         //prevent duplication - ref: https://github.com/grafov/m3u8/issues/201
	dup := false
	for _, t := range tag.Values {
		if *t == *val {
			dup = true
			break
		}
	}

	if !dup { 
		tag.Values = append(tag.Values, val)
	}

	return tag, nil
}

@slipthebit
Copy link
Author

Alternatively, if the playlist type is known, the CustomTags can be added to the playlist itself before decoding.
https://goplay.tools/snippet/COz0f_dEbA9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant