Skip to content

Commit

Permalink
Fix not to remove TYPE and GROUP-ID from map
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfish-shogi committed Dec 18, 2024
1 parent 6144826 commit fc17a45
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
10 changes: 7 additions & 3 deletions master_playlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 22 additions & 0 deletions master_playlist_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"], `"`)
Expand All @@ -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"], `"`)
Expand Down

0 comments on commit fc17a45

Please sign in to comment.