forked from rylio/ytdl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson.go
158 lines (141 loc) · 4.56 KB
/
json.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package ytdl
import (
"strings"
)
type playerConfig struct {
Assets struct {
JS string `json:"js"`
} `json:"assets"`
Args struct {
Status string `json:"status"`
Errorcode string `json:"errorcode"`
Reason string `json:"reason"`
PlayerResponse string `json:"player_response"`
URLEncodedFmtStreamMap string `json:"url_encoded_fmt_stream_map"`
AdaptiveFmts string `json:"adaptive_fmts"`
Dashmpd string `json:"dashmpd"`
} `json:"args"`
}
type formatInfo struct {
Itag int `json:"itag"`
MimeType string `json:"mimeType"`
Bitrate int `json:"bitrate"`
Width int `json:"width"`
Height int `json:"height"`
LastModified string `json:"lastModified"`
ContentLength string `json:"contentLength"`
Quality string `json:"quality"`
QualityLabel string `json:"qualityLabel"`
ProjectionType string `json:"projectionType"`
AverageBitrate int `json:"averageBitrate"`
AudioQuality string `json:"audioQuality"`
ApproxDurationMs string `json:"approxDurationMs"`
AudioSampleRate string `json:"audioSampleRate"`
AudioChannels int `json:"audioChannels"`
Cipher *string `json:"cipher"`
SignatureCipher *string `json:"signatureCipher"`
URL string `json:"url"`
Index *Range `json:"indexRange,omitempty"`
Init *Range `json:"initRange,omitempty"`
Codecs string `json:"codecs,omitempty"`
FPS int `json:"fps,omitempty"`
}
type playerResponse struct {
PlayabilityStatus struct {
Status string `json:"status"`
Reason string `json:"reason"`
} `json:"playabilityStatus"`
StreamingData struct {
ExpiresInSeconds string `json:"expiresInSeconds"`
Formats []formatInfo `json:"formats"`
AdaptiveFormats []formatInfo `json:"adaptiveFormats"`
DashManifestUrl string `json:"dashManifestUrl"`
HlsManifestUrl string `json:"hlsManifestUrl"`
} `json:"streamingData"`
VideoDetails struct {
Title string `json:"title"`
Author string `json:"author"`
LengthSeconds string `json:"lengthSeconds"`
Keywords []string `json:"keywords"`
ViewCount string `json:"viewCount"`
} `json:"videoDetails"`
Microformat struct {
Renderer struct {
ViewCount string `json:"viewCount"`
PublishDate string `json:"publishDate"`
UploadDate string `json:"uploadDate"`
} `json:"playerMicroformatRenderer"`
} `json:"microformat"`
}
type representation struct {
Itag int `xml:"id,attr"`
Height int `xml:"height,attr"`
URL string `xml:"BaseURL"`
}
type initialData struct {
Contents struct {
TwoColumnWatchNextResults struct {
Results struct {
Results struct {
Contents []struct {
VideoSecondaryInfoRenderer struct {
Owner struct {
VideoOwnerRenderer struct {
Thumbnail struct {
Thumbnails []struct {
URL string `json:"url"`
Width int `json:"width"`
Height int `json:"height"`
} `json:"thumbnails"`
} `json:"thumbnail"`
Title Content `json:"title"`
SubscriberCountText Content `json:"subscriberCountText"`
TrackingParams string `json:"trackingParams"`
} `json:"videoOwnerRenderer"`
} `json:"owner"`
Description Content `json:"description"`
MetadataRowContainer struct {
MetadataRowContainerRenderer struct {
Rows MetadataRows `json:"rows"`
} `json:"metadataRowContainerRenderer"`
} `json:"metadataRowContainer"`
} `json:"videoSecondaryInfoRenderer,omitempty"`
} `json:"contents"`
} `json:"results"`
} `json:"results"`
} `json:"twoColumnWatchNextResults"`
} `json:"contents"`
}
type Content struct {
SimpleText *string `json:"simpleText,omitempty"`
Lines []struct {
Text string `json:"text,omitempty"`
} `json:"runs"`
}
func (c *Content) String() string {
if c.SimpleText != nil {
return *c.SimpleText
}
var sb strings.Builder
for i := range c.Lines {
sb.WriteString(c.Lines[i].Text)
}
return sb.String()
}
type MetadataRows []struct {
MetadataRowRenderer struct {
Title Content `json:"title"`
Contents []Content `json:"contents"`
} `json:"metadataRowRenderer,omitempty"`
}
func (rows MetadataRows) Get(title string) string {
for i := range rows {
row := &rows[i]
if row.MetadataRowRenderer.Title.String() == title {
if contents := row.MetadataRowRenderer.Contents; len(contents) > 0 {
return contents[0].String()
}
}
}
return ""
}