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 if len(video.FormatStreams) == 0 {
23 return ""
24 }
25 return video.FormatStreams[0].URL
26}
27
28func NewVideoBuffer(b *bytes.Buffer, l int64) *VideoBuffer {
29 d := new(bytes.Buffer)
30 d.Write(b.Bytes())
31
32 return &VideoBuffer{Buffer: d, Length: l}
33}
34
35func (vb *VideoBuffer) Clone() *VideoBuffer {
36 return NewVideoBuffer(vb.Buffer, vb.Length)
37}
38
39func (vb *VideoBuffer) ValidateLength() bool {
40 return vb.Length > 0 && vb.Length == int64(vb.Buffer.Len())
41}