Repository navigation
Expand file tree
/
Copy pathmodels.py
More file actions
256 lines (197 loc) · 7.62 KB
/
Copy pathmodels.py
File metadata and controls
256 lines (197 loc) · 7.62 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
"""Invidious-compatible response models."""
from typing import List, Optional
from pydantic import BaseModel, Field
class Thumbnail(BaseModel):
"""Video thumbnail."""
quality: str
url: str
width: Optional[int] = None
height: Optional[int] = None
class AudioTrack(BaseModel):
"""Audio track metadata."""
id: Optional[str] = None
displayName: Optional[str] = None
isDefault: bool = False
class FormatStream(BaseModel):
"""Muxed video+audio stream."""
url: str
itag: str
type: str
quality: str
container: str
resolution: Optional[str] = None
width: Optional[int] = None
height: Optional[int] = None
encoding: Optional[str] = None
size: Optional[str] = None
fps: Optional[int] = None
httpHeaders: Optional[dict] = None
class AdaptiveFormat(BaseModel):
"""Adaptive (video-only or audio-only) stream."""
url: str
itag: str
type: str
container: str
# Byte ranges ("start-end") of the initialization and index sections, when known
init: Optional[str] = None
index: Optional[str] = None
resolution: Optional[str] = None
width: Optional[int] = None
height: Optional[int] = None
bitrate: Optional[str] = None
clen: Optional[str] = None
encoding: Optional[str] = None
fps: Optional[int] = None
audioTrack: Optional[AudioTrack] = None
audioQuality: Optional[str] = None
httpHeaders: Optional[dict] = None
class Caption(BaseModel):
"""Video caption/subtitle."""
label: str
languageCode: str
url: str
auto_generated: bool = False
class Storyboard(BaseModel):
"""Video storyboard/preview thumbnails."""
# `url` is treated by Yattee clients as a *proxy* endpoint — they append
# `&storyboard=N` to fetch individual sheets. Invidious honors that, but a
# direct `https://i.ytimg.com/.../M0.jpg` URL does not, so the client would
# receive sheet 0 for every timestamp. Leave this unset whenever we don't
# have a real proxy endpoint to hand over; the client then falls back to
# substituting `M$M` in `templateUrl` and fetching sheets directly.
url: Optional[str] = None
templateUrl: str
width: int
height: int
count: int
interval: int
storyboardWidth: int
storyboardHeight: int
storyboardCount: int
class VideoResponse(BaseModel):
"""Full video details response (matches Invidious /api/v1/videos/{id})."""
videoId: str
title: str
description: Optional[str] = None
descriptionHtml: Optional[str] = None
author: str
authorId: str
authorUrl: Optional[str] = None
authorThumbnails: Optional[List[Thumbnail]] = None
subCountText: Optional[str] = None
lengthSeconds: int
published: Optional[int] = None
publishedText: Optional[str] = None
viewCount: Optional[int] = None
likeCount: Optional[int] = None
videoThumbnails: List[Thumbnail] = Field(default_factory=list)
liveNow: bool = False
isUpcoming: bool = False
isShort: Optional[bool] = None
premiereTimestamp: Optional[int] = None
hlsUrl: Optional[str] = None
dashUrl: Optional[str] = None
formatStreams: List[FormatStream] = Field(default_factory=list)
adaptiveFormats: List[AdaptiveFormat] = Field(default_factory=list)
captions: List[Caption] = Field(default_factory=list)
storyboards: List[Storyboard] = Field(default_factory=list)
# Extended fields for external (non-YouTube) sources
extractor: Optional[str] = None # Site identifier (e.g., "vimeo", "twitter")
originalUrl: Optional[str] = None # Original URL for re-extraction on stream expiry
# Recommended videos (only available when using Invidious proxy)
recommendedVideos: Optional[List["VideoListItem"]] = None
# Which extraction path served this response: "invidious", "hybrid" (InnerTube + yt-dlp), "ytdlp"
extractionMethod: Optional[str] = None
class VideoListItem(BaseModel):
"""Video item in search/channel/playlist results."""
type: str = "video"
videoId: str
title: str
description: Optional[str] = None
author: str
authorId: str
authorUrl: Optional[str] = None
lengthSeconds: int
published: Optional[int] = None
publishedText: Optional[str] = None
viewCount: Optional[int] = None
viewCountText: Optional[str] = None
likeCount: Optional[int] = None
videoThumbnails: List[Thumbnail] = Field(default_factory=list)
liveNow: bool = False
isUpcoming: bool = False
isShort: Optional[bool] = None
extractor: Optional[str] = None # Site name (Vimeo, Dailymotion, etc.) for external videos
videoUrl: Optional[str] = None # Original video URL for external videos (for re-extraction)
class ChannelListItem(BaseModel):
"""Channel item in search results."""
type: str = "channel"
authorId: str
author: str
channelHandle: Optional[str] = None
description: Optional[str] = None
subCount: Optional[int] = None
subCountText: Optional[str] = None
videoCount: Optional[int] = None
authorThumbnails: List[Thumbnail] = Field(default_factory=list)
authorVerified: bool = False
class ChannelResponse(BaseModel):
"""Channel details response."""
authorId: str
author: str
description: Optional[str] = None
subCount: Optional[int] = None
totalViews: Optional[int] = None
authorThumbnails: List[Thumbnail] = Field(default_factory=list)
authorBanners: List[Thumbnail] = Field(default_factory=list)
authorVerified: bool = False
class ChannelMetadataRequest(BaseModel):
"""Request body for batch channel metadata endpoint."""
channel_ids: List[str]
class ChannelVideosResponse(BaseModel):
"""Channel videos response (Invidious-compatible)."""
videos: List[VideoListItem] = Field(default_factory=list)
continuation: Optional[str] = None
class ChannelPlaylistsResponse(BaseModel):
"""Channel playlists response (Invidious-compatible)."""
playlists: List["PlaylistListItem"] = Field(default_factory=list)
continuation: Optional[str] = None
class ChannelShortsResponse(BaseModel):
"""Channel shorts response (Invidious-compatible)."""
videos: List[VideoListItem] = Field(default_factory=list)
continuation: Optional[str] = None
class ChannelStreamsResponse(BaseModel):
"""Channel past live streams response (Invidious-compatible)."""
videos: List[VideoListItem] = Field(default_factory=list)
continuation: Optional[str] = None
class ChannelSearchResponse(BaseModel):
"""Channel search results response (Invidious-compatible)."""
videos: List[VideoListItem] = Field(default_factory=list)
continuation: Optional[str] = None
class ChannelExtractResponse(BaseModel):
"""Generic channel extraction response for external (non-YouTube) sites."""
author: str
authorId: str
authorUrl: str # Channel URL for re-extraction
extractor: str # Site name (Vimeo, Dailymotion, TikTok, etc.)
videos: List[VideoListItem] = Field(default_factory=list)
continuation: Optional[str] = None # Page number as string for next request
class PlaylistListItem(BaseModel):
"""Playlist item in search results."""
type: str = "playlist"
playlistId: str
title: str
author: Optional[str] = None
authorId: Optional[str] = None
videoCount: int = 0
playlistThumbnail: Optional[str] = None
videos: List[VideoListItem] = Field(default_factory=list)
class PlaylistResponse(BaseModel):
"""Playlist details response."""
playlistId: str
title: str
description: Optional[str] = None
author: Optional[str] = None
authorId: Optional[str] = None
videoCount: int
videos: List[VideoListItem] = Field(default_factory=list)