src/globals/globals.go (view raw)
1package globals
2
3import (
4 "bytes"
5 "fmt"
6 "html/template"
7 "net/http"
8 "strconv"
9 "strings"
10 "time"
11
12 "github.com/birabittoh/myks"
13 "github.com/kkdai/youtube/v2"
14 "github.com/utking/extemplate"
15)
16
17var (
18 Debug bool
19 Proxy bool
20 Port string
21
22 C = http.DefaultClient
23 YT = youtube.Client{}
24 XT = extemplate.New().Funcs(funcMap)
25
26 KS = myks.New[youtube.Video](3 * time.Hour)
27 PKS *myks.KeyStore[bytes.Buffer]
28
29 AdminUser string
30 AdminPass string
31
32 funcMap = template.FuncMap{"parseFormat": parseFormat}
33)
34
35func parseFormat(f youtube.Format) (res string) {
36 isAudio := f.QualityLabel == ""
37
38 if isAudio {
39 bitrate := f.AverageBitrate
40 if bitrate == 0 {
41 bitrate = f.Bitrate
42 }
43 res = strconv.Itoa(bitrate/1000) + "kbps"
44 } else {
45 res = f.QualityLabel
46 }
47
48 mime := strings.Split(f.MimeType, ";")
49 res += " - " + mime[0]
50
51 codecs := " (" + strings.Split(mime[1], "\"")[1] + ")"
52
53 if isAudio {
54 return res + " - audio only" + codecs
55 }
56
57 res += fmt.Sprintf(" (%d FPS)", f.FPS)
58
59 if f.AudioChannels == 0 {
60 res += " - video only"
61 }
62
63 res += codecs
64 return
65}