-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblurl.go
62 lines (49 loc) · 1.27 KB
/
blurl.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
53
54
55
56
57
58
59
60
61
62
package main
import (
"bytes"
"compress/zlib"
"encoding/binary"
"encoding/json"
)
type Playlist struct {
Type string `json:"type"`
Language string `json:"language,omitempty"`
URL string `json:"url"`
Data string `json:"data,omitempty"`
Duration int `json:"duration,omitempty"`
}
type BLURL struct {
Playlists []Playlist `json:"playlists"`
Subtitles string `json:"subtitles,omitempty"`
UCP string `json:"ucp,omitempty"`
AudioOnly bool `json:"audioonly,omitempty"`
AspectRatio string `json:"aspectratio,omitempty"`
PartySync bool `json:"partysync"`
LRCS string `json:"lrcs,omitempty"`
Duration int `json:"duration,omitempty"`
}
func encodeBlurl(data *BLURL) ([]byte, error) {
marshaled, err := json.Marshal(data)
if err != nil {
return nil, err
}
return encodeBlurlData(marshaled)
}
func encodeBlurlData(data []byte) ([]byte, error) {
var b bytes.Buffer
writer := zlib.NewWriter(&b)
_, err := writer.Write(data)
if err != nil {
return nil, err
}
err = writer.Close()
if err != nil {
return nil, err
}
deflated := b.Bytes()
w := bytes.NewBuffer([]byte{})
w.WriteString("blul")
_ = binary.Write(w, binary.BigEndian, uint32(len(data)))
w.Write(deflated)
return w.Bytes(), nil
}