This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformats.go
121 lines (109 loc) · 3.01 KB
/
formats.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package vimego
type VideoFormats struct {
Progressive ProgressiveFormats `json:"progressive"`
Dash *DashFormat `json:"dash"`
Hls *HlsFormat `json:"hls"`
}
type ProgressiveFormats []*ProgressiveFormat
func (p ProgressiveFormats) Len() int {
return len(p)
}
func (p ProgressiveFormats) Less(a, b int) bool {
return p[a].Width < p[b].Width
}
func (p ProgressiveFormats) Swap(a, b int) {
p[a], p[b] = p[b], p[a]
}
// Best returns the ProgressiveFormat with the hightest resolution.
func (p ProgressiveFormats) Best() *ProgressiveFormat {
if len(p) != 0 {
return p[len(p)-1]
}
return nil
}
// Worst returns the ProgressiveFormat with the lowest resolution.
func (p ProgressiveFormats) Worst() *ProgressiveFormat {
if len(p) != 0 {
return p[0]
}
return nil
}
type ProgressiveFormat struct {
Profile int `json:"profile,string"`
Width int `json:"width"`
Mime string `json:"mime"`
Fps int `json:"fps"`
URL string `json:"url"`
Cdn string `json:"cdn"`
Quality string `json:"quality"`
Origin string `json:"origin"`
Height int `json:"height"`
}
type DashFormat struct {
SeparateAv bool `json:"separate_av"`
DefaultCdn string `json:"default_cdn"`
Cdns struct {
AkfireInterconnectQuic struct {
URL string `json:"url"`
Origin string `json:"origin"`
AvcURL string `json:"avc_url"`
} `json:"akfire_interconnect_quic"`
FastlySkyfire struct {
URL string `json:"url"`
Origin string `json:"origin"`
AvcURL string `json:"avc_url"`
} `json:"fastly_skyfire"`
} `json:"cdns"`
}
// Url returns the URL for the video stream.
func (s *DashFormat) Url() string {
switch s.DefaultCdn {
case "akfire_interconnect_quic":
return s.Cdns.AkfireInterconnectQuic.URL
case "fastly_skyfire":
return s.Cdns.FastlySkyfire.URL
default:
// fallback
if s.Cdns.AkfireInterconnectQuic.URL != "" {
return s.Cdns.AkfireInterconnectQuic.URL
}
if s.Cdns.FastlySkyfire.URL != "" {
return s.Cdns.FastlySkyfire.URL
}
}
return ""
}
type HlsFormat struct {
SeparateAv bool `json:"separate_av"`
DefaultCdn string `json:"default_cdn"`
Cdns struct {
AkfireInterconnectQuic struct {
URL string `json:"url"`
Origin string `json:"origin"`
AvcURL string `json:"avc_url"`
} `json:"akfire_interconnect_quic"`
FastlySkyfire struct {
URL string `json:"url"`
Origin string `json:"origin"`
AvcURL string `json:"avc_url"`
} `json:"fastly_skyfire"`
} `json:"cdns"`
}
// Url returns the URL for the .m3u8 playlist.
func (s *HlsFormat) Url() string {
switch s.DefaultCdn {
case "akfire_interconnect_quic":
return s.Cdns.AkfireInterconnectQuic.URL
case "fastly_skyfire":
return s.Cdns.FastlySkyfire.URL
default:
// fallback
if s.Cdns.AkfireInterconnectQuic.URL != "" {
return s.Cdns.AkfireInterconnectQuic.URL
}
if s.Cdns.FastlySkyfire.URL != "" {
return s.Cdns.FastlySkyfire.URL
}
}
return ""
}