-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from mjneil/custom
Custom Tag Support
- Loading branch information
Showing
14 changed files
with
733 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ to the project. They listed below in an alphabetical order: | |
- Vishal Kumar Tuniki <[email protected]> | ||
- Yevgen Flerko <[email protected]> | ||
- Zac Shenker <[email protected]> | ||
|
||
- Matthew Neil [mjneil](https://github.com/mjneil) | ||
|
||
If you want to be added to this list (or removed for any reason) | ||
just open an issue about it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package template | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/grafov/m3u8" | ||
) | ||
|
||
// #CUSTOM-PLAYLIST-TAG:<number> | ||
|
||
// Implements both CustomTag and CustomDecoder interfaces | ||
type CustomPlaylistTag struct { | ||
Number int | ||
} | ||
|
||
// TagName() should return the full indentifier including the leading '#' and trailing ':' | ||
// if the tag also contains a value or attribute list | ||
func (tag *CustomPlaylistTag) TagName() string { | ||
return "#CUSTOM-PLAYLIST-TAG:" | ||
} | ||
|
||
// line will be the entire matched line, including the identifier | ||
func (tag *CustomPlaylistTag) Decode(line string) (m3u8.CustomTag, error) { | ||
_, err := fmt.Sscanf(line, "#CUSTOM-PLAYLIST-TAG:%d", &tag.Number) | ||
|
||
return tag, err | ||
} | ||
|
||
// This is a playlist tag example | ||
func (tag *CustomPlaylistTag) SegmentTag() bool { | ||
return false | ||
} | ||
|
||
func (tag *CustomPlaylistTag) Encode() *bytes.Buffer { | ||
buf := new(bytes.Buffer) | ||
|
||
buf.WriteString(tag.TagName()) | ||
buf.WriteString(strconv.Itoa(tag.Number)) | ||
|
||
return buf | ||
} | ||
|
||
func (tag *CustomPlaylistTag) String() string { | ||
return tag.Encode().String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package template | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
"github.com/grafov/m3u8" | ||
) | ||
|
||
// #CUSTOM-SEGMENT-TAG:<attribute-list> | ||
|
||
// Implements both CustomTag and CustomDecoder interfaces | ||
type CustomSegmentTag struct { | ||
Name string | ||
Jedi bool | ||
} | ||
|
||
// TagName() should return the full indentifier including the leading '#' and trailing ':' | ||
// if the tag also contains a value or attribute list | ||
func (tag *CustomSegmentTag) TagName() string { | ||
return "#CUSTOM-SEGMENT-TAG:" | ||
} | ||
|
||
// line will be the entire matched line, including the identifier | ||
func (tag *CustomSegmentTag) Decode(line string) (m3u8.CustomTag, error) { | ||
var err error | ||
|
||
// Since this is a Segment tag, we want to create a new tag every time it is decoded | ||
// as there can be one for each segment with | ||
newTag := new(CustomSegmentTag) | ||
|
||
for k, v := range m3u8.DecodeAttributeList(line[20:]) { | ||
switch k { | ||
case "NAME": | ||
newTag.Name = v | ||
case "JEDI": | ||
if v == "YES" { | ||
newTag.Jedi = true | ||
} else if v == "NO" { | ||
newTag.Jedi = false | ||
} else { | ||
err = errors.New("Valid strings for JEDI attribute are YES and NO.") | ||
} | ||
} | ||
} | ||
|
||
return newTag, err | ||
} | ||
|
||
// This is a playlist tag example | ||
func (tag *CustomSegmentTag) SegmentTag() bool { | ||
return true | ||
} | ||
|
||
func (tag *CustomSegmentTag) Encode() *bytes.Buffer { | ||
buf := new(bytes.Buffer) | ||
|
||
if tag.Name != "" { | ||
buf.WriteString(tag.TagName()) | ||
buf.WriteString("NAME=\"") | ||
buf.WriteString(tag.Name) | ||
buf.WriteString("\",JEDI=") | ||
if tag.Jedi { | ||
buf.WriteString("YES") | ||
} else { | ||
buf.WriteString("NO") | ||
} | ||
} | ||
|
||
return buf | ||
} | ||
|
||
func (tag *CustomSegmentTag) String() string { | ||
return tag.Encode().String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/grafov/m3u8 | ||
|
||
go 1.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.