-
Notifications
You must be signed in to change notification settings - Fork 0
/
key.go
52 lines (41 loc) · 1.06 KB
/
key.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 m3u8
import (
"fmt"
"strings"
)
func NewKey(line string) (*KeySegment, error) {
/*
type KeySegment struct {
Method string
IV string // Initialization Vector
URI string
KeyFormat string
KeyFormatVersions string
}
*/
item := parseLine(line[len(ExtKey+":"):])
return &KeySegment{
Method: item[METHOD],
IV: item[IV],
URI: item[URI],
KeyFormat: item[KEYFORMAT],
KeyFormatVersions: item[KEYFORMATVERSIONS],
}, nil
}
func (ks *KeySegment) String() string {
var s []string
s = append(s, fmt.Sprintf("%s=%s", METHOD, ks.Method))
if ks.IV != "" {
s = append(s, fmt.Sprintf("%s=%s", IV, ks.IV))
}
if ks.URI != "" {
s = append(s, fmt.Sprintf(`%s="%s"`, URI, ks.URI))
}
if ks.KeyFormat != "" {
s = append(s, fmt.Sprintf(`%s="%s"`, KEYFORMAT, ks.KeyFormat))
}
if ks.KeyFormatVersions != "" {
s = append(s, fmt.Sprintf(`%s="%s"`, KEYFORMATVERSIONS, ks.KeyFormatVersions))
}
return fmt.Sprintf("%s:%s", ExtKey, strings.Join(s, ","))
}