diff --git a/master_playlist.go b/master_playlist.go index 6d2a572..34ce4d3 100644 --- a/master_playlist.go +++ b/master_playlist.go @@ -99,8 +99,6 @@ func DecodeMasterPlaylist(r io.Reader) (*MasterPlaylist, error) { return nil, errors.New("missing GROUP-ID") } typ := attrs["TYPE"] - delete(attrs, "GROUP-ID") - delete(attrs, "TYPE") switch MediaType(typ) { case MediaTypeVideo: if _, ok := playlist.Alternatives.Video[groupID]; !ok { @@ -196,7 +194,13 @@ func (playlist *MasterPlaylist) Encode(w io.Writer) error { } func encodeExtXMedia(w io.Writer, typ MediaType, groupID string, attrs MediaAttrs) error { - _, err := fmt.Fprintf(w, "#%s:TYPE=%s,GROUP-ID=\"%s\",%s\n", TagExtXMedia, typ, groupID, Attributes(attrs).String()) + a := make(Attributes, len(attrs)-2) + for k, v := range attrs { + if k != "TYPE" && k != "GROUP-ID" { + a[k] = v + } + } + _, err := fmt.Fprintf(w, "#%s:TYPE=%s,GROUP-ID=\"%s\",%s\n", TagExtXMedia, typ, groupID, a.String()) return err } diff --git a/master_playlist_tags.go b/master_playlist_tags.go index ea5c730..4362c5f 100644 --- a/master_playlist_tags.go +++ b/master_playlist_tags.go @@ -124,6 +124,17 @@ func (attrs StreamInfAttrs) SetClosedCaptions(closedCaptions string) { // MediaAttrs represents the attributes of the EXT-X-MEDIA tag. type MediaAttrs Attributes +// Type returns the type of the media. +func (attrs MediaAttrs) Type() MediaType { + return MediaType(attrs["TYPE"]) +} + +// SetType sets the type of the media. +// NOTICE: This value is ignored by MasterPlaylist#Encode. +func (attrs MediaAttrs) SetType(mediaType MediaType) { + attrs["TYPE"] = string(mediaType) +} + // URI returns the URI of the media. func (attrs MediaAttrs) URI() string { return strings.Trim(attrs["URI"], `"`) @@ -134,6 +145,17 @@ func (attrs MediaAttrs) SetURI(uri string) { attrs["URI"] = `"` + uri + `"` } +// GroupID returns the group ID of the media. +func (attrs MediaAttrs) GroupID() string { + return strings.Trim(attrs["GROUP-ID"], `"`) +} + +// SetGroupID sets the group ID of the media. +// NOTICE: This value is ignored by MasterPlaylist#Encode. +func (attrs MediaAttrs) SetGroupID(groupID string) { + attrs["GROUP-ID"] = `"` + groupID + `"` +} + // Language returns the language of the media. func (attrs MediaAttrs) Language() string { return strings.Trim(attrs["LANGUAGE"], `"`)