forked from zencoder/m3u8
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support custom tag decode/encode * add unit tests * go fmt * add go.mod * add writer tests, breakup custom interface * update readme * add comments to exports * parse custom tags first * update CustomDecoder.Segment to CustomDecoder.SegmentTag * Add badge of godoc.org for the awesome-go * Fix formatting with gofmt Also copyrights updated. Refs to issue grafov#151. * Fix comments by golint recommendations Refs to issue grafov#151. * Simplify with gofmt Refs to issue grafov#151. * Fix comments accordingly with golint advices Refs to issue grafov#151. * Integrate with deepsource.io It bring us more code quality analyzers. Refs grafov#151. * Add deepsource.io badge Refs grafov#151. * Add awesome-go badge Refs to issue grafov#151. * Try vanity import to work w/ travis * remove coveralls from fork Co-authored-by: Matthew Neil <[email protected]> Co-authored-by: Lei Gao <[email protected]> Co-authored-by: Alexander I.Grafov <[email protected]>
- Loading branch information
1 parent
08b2d91
commit 6485cdb
Showing
17 changed files
with
935 additions
and
172 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version = 1 | ||
|
||
test_patterns = [ | ||
"*_test.go" | ||
] | ||
|
||
exclude_patterns = [ | ||
"vendor/**" | ||
] | ||
|
||
[[analyzers]] | ||
name = "go" | ||
enabled = true | ||
|
||
[analyzers.meta] | ||
import_path = "github.com/grafov/m3u8" |
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 |
---|---|---|
|
@@ -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
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,52 @@ | ||
package template | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/grafov/m3u8" | ||
) | ||
|
||
// #CUSTOM-PLAYLIST-TAG:<number> | ||
|
||
// CustomPlaylistTag 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:" | ||
} | ||
|
||
// Decode decodes the input line. The 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 | ||
} | ||
|
||
// SegmentTag is a playlist tag example. | ||
func (tag *CustomPlaylistTag) SegmentTag() bool { | ||
return false | ||
} | ||
|
||
// Encode formats the structure to the text result. | ||
func (tag *CustomPlaylistTag) Encode() *bytes.Buffer { | ||
buf := new(bytes.Buffer) | ||
|
||
buf.WriteString(tag.TagName()) | ||
buf.WriteString(strconv.Itoa(tag.Number)) | ||
|
||
return buf | ||
} | ||
|
||
// String implements Stringer interface. | ||
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,79 @@ | ||
package template | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
"github.com/grafov/m3u8" | ||
) | ||
|
||
// #CUSTOM-SEGMENT-TAG:<attribute-list> | ||
|
||
// CustomSegmentTag 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:" | ||
} | ||
|
||
// Decode decodes the input string to the internal structure. The 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 | ||
} | ||
|
||
// SegmentTag is a playlist tag example. | ||
func (tag *CustomSegmentTag) SegmentTag() bool { | ||
return true | ||
} | ||
|
||
// Encode encodes the structure to the text result. | ||
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 | ||
} | ||
|
||
// String implements Stringer interface. | ||
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 |
Oops, something went wrong.