-
Notifications
You must be signed in to change notification settings - Fork 1
/
segment_base.go
62 lines (60 loc) · 1.36 KB
/
segment_base.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 stream
import (
"154.pages.dev/encoding/dash"
"154.pages.dev/log"
"154.pages.dev/stream/mp4"
"154.pages.dev/widevine"
"encoding/hex"
"io"
"log/slog"
"net/http"
"os"
)
func (s Stream) segment_base(ext string, item *dash.Representation) error {
file, err := os.Create(s.Name + ext)
if err != nil {
return err
}
defer file.Close()
res, err := http.Get(item.BaseURL)
if err != nil {
return err
}
defer res.Body.Close()
index, err := item.Index()
if err != nil {
return err
}
dec := make(mp4.Decrypt)
if err := dec.Init(io.LimitReader(res.Body, index), file); err != nil {
return err
}
private_key, err := os.ReadFile(s.Private_Key)
if err != nil {
return err
}
client_ID, err := os.ReadFile(s.Client_ID)
if err != nil {
return err
}
kid, err := item.Default_KID()
if err != nil {
return err
}
pssh, err := item.PSSH()
if err != nil {
return err
}
mod, err := widevine.New_Module(private_key, client_ID, kid, pssh)
if err != nil {
return err
}
key, err := mod.Key(s.Poster)
if err != nil {
return err
}
slog.Debug("*", "key", hex.EncodeToString(key))
log.Set_Transport(slog.LevelDebug)
defer log.Set_Transport(slog.LevelInfo)
return dec.Segment(log.New_Progress(1).Reader(res), file, key)
}