invidious/invidious.go (view raw)
1package invidious
2
3import (
4 "bytes"
5 "time"
6
7 "github.com/birabittoh/myks"
8 "github.com/birabittoh/rabbitpipe"
9 "github.com/sirupsen/logrus"
10)
11
12var logger = logrus.New()
13var buffers = myks.New[VideoBuffer](time.Minute)
14var RP = rabbitpipe.New()
15
16type VideoBuffer struct {
17 Buffer *bytes.Buffer
18 Length int64
19}
20
21func GetVideoURL(video rabbitpipe.Video) string {
22 for _, format := range video.FormatStreams {
23 if format.Itag == "18" {
24 return format.URL
25 }
26 }
27 return ""
28}
29
30func NewVideoBuffer(b *bytes.Buffer, l int64) *VideoBuffer {
31 d := new(bytes.Buffer)
32 d.Write(b.Bytes())
33
34 return &VideoBuffer{
35 Buffer: d,
36 Length: l,
37 }
38}
39
40func (vb *VideoBuffer) Clone() *VideoBuffer {
41 return NewVideoBuffer(vb.Buffer, vb.Length)
42}
43
44func (vb *VideoBuffer) ValidateLength() bool {
45 return vb.Length > 0 && vb.Length == int64(vb.Buffer.Len())
46}