-
Notifications
You must be signed in to change notification settings - Fork 305
/
custom-playlist-tag-template.go
52 lines (40 loc) · 1.17 KB
/
custom-playlist-tag-template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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()
}