]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/peertube.py
Import Debian changes 2020.01.24-0.1
[youtubedl] / youtube_dl / extractor / peertube.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import compat_str
8 from ..utils import (
9 int_or_none,
10 parse_resolution,
11 try_get,
12 unified_timestamp,
13 url_or_none,
14 urljoin,
15 )
16
17
18 class PeerTubeIE(InfoExtractor):
19 _INSTANCES_RE = r'''(?:
20 # Taken from https://instances.joinpeertube.org/instances
21 peertube\.rainbowswingers\.net|
22 tube\.stanisic\.nl|
23 peer\.suiri\.us|
24 medias\.libox\.fr|
25 videomensoif\.ynh\.fr|
26 peertube\.travelpandas\.eu|
27 peertube\.rachetjay\.fr|
28 peertube\.montecsys\.fr|
29 tube\.eskuero\.me|
30 peer\.tube|
31 peertube\.umeahackerspace\.se|
32 tube\.nx-pod\.de|
33 video\.monsieurbidouille\.fr|
34 tube\.openalgeria\.org|
35 vid\.lelux\.fi|
36 video\.anormallostpod\.ovh|
37 tube\.crapaud-fou\.org|
38 peertube\.stemy\.me|
39 lostpod\.space|
40 exode\.me|
41 peertube\.snargol\.com|
42 vis\.ion\.ovh|
43 videosdulib\.re|
44 v\.mbius\.io|
45 videos\.judrey\.eu|
46 peertube\.osureplayviewer\.xyz|
47 peertube\.mathieufamily\.ovh|
48 www\.videos-libr\.es|
49 fightforinfo\.com|
50 peertube\.fediverse\.ru|
51 peertube\.oiseauroch\.fr|
52 video\.nesven\.eu|
53 v\.bearvideo\.win|
54 video\.qoto\.org|
55 justporn\.cc|
56 video\.vny\.fr|
57 peervideo\.club|
58 tube\.taker\.fr|
59 peertube\.chantierlibre\.org|
60 tube\.ipfixe\.info|
61 tube\.kicou\.info|
62 tube\.dodsorf\.as|
63 videobit\.cc|
64 video\.yukari\.moe|
65 videos\.elbinario\.net|
66 hkvideo\.live|
67 pt\.tux\.tf|
68 www\.hkvideo\.live|
69 FIGHTFORINFO\.com|
70 pt\.765racing\.com|
71 peertube\.gnumeria\.eu\.org|
72 nordenmedia\.com|
73 peertube\.co\.uk|
74 tube\.darfweb\.eu|
75 tube\.kalah-france\.org|
76 0ch\.in|
77 vod\.mochi\.academy|
78 film\.node9\.org|
79 peertube\.hatthieves\.es|
80 video\.fitchfamily\.org|
81 peertube\.ddns\.net|
82 video\.ifuncle\.kr|
83 video\.fdlibre\.eu|
84 tube\.22decembre\.eu|
85 peertube\.harmoniescreatives\.com|
86 tube\.fabrigli\.fr|
87 video\.thedwyers\.co|
88 video\.bruitbruit\.com|
89 peertube\.foxfam\.club|
90 peer\.philoxweb\.be|
91 videos\.bugs\.social|
92 peertube\.malbert\.xyz|
93 peertube\.bilange\.ca|
94 libretube\.net|
95 diytelevision\.com|
96 peertube\.fedilab\.app|
97 libre\.video|
98 video\.mstddntfdn\.online|
99 us\.tv|
100 peertube\.sl-network\.fr|
101 peertube\.dynlinux\.io|
102 peertube\.david\.durieux\.family|
103 peertube\.linuxrocks\.online|
104 peerwatch\.xyz|
105 v\.kretschmann\.social|
106 tube\.otter\.sh|
107 yt\.is\.nota\.live|
108 tube\.dragonpsi\.xyz|
109 peertube\.boneheadmedia\.com|
110 videos\.funkwhale\.audio|
111 watch\.44con\.com|
112 peertube\.gcaillaut\.fr|
113 peertube\.icu|
114 pony\.tube|
115 spacepub\.space|
116 tube\.stbr\.io|
117 v\.mom-gay\.faith|
118 tube\.port0\.xyz|
119 peertube\.simounet\.net|
120 play\.jergefelt\.se|
121 peertube\.zeteo\.me|
122 tube\.danq\.me|
123 peertube\.kerenon\.com|
124 tube\.fab-l3\.org|
125 tube\.calculate\.social|
126 peertube\.mckillop\.org|
127 tube\.netzspielplatz\.de|
128 vod\.ksite\.de|
129 peertube\.laas\.fr|
130 tube\.govital\.net|
131 peertube\.stephenson\.cc|
132 bistule\.nohost\.me|
133 peertube\.kajalinifi\.de|
134 video\.ploud\.jp|
135 video\.omniatv\.com|
136 peertube\.ffs2play\.fr|
137 peertube\.leboulaire\.ovh|
138 peertube\.tronic-studio\.com|
139 peertube\.public\.cat|
140 peertube\.metalbanana\.net|
141 video\.1000i100\.fr|
142 peertube\.alter-nativ-voll\.de|
143 tube\.pasa\.tf|
144 tube\.worldofhauru\.xyz|
145 pt\.kamp\.site|
146 peertube\.teleassist\.fr|
147 videos\.mleduc\.xyz|
148 conf\.tube|
149 media\.privacyinternational\.org|
150 pt\.forty-two\.nl|
151 video\.halle-leaks\.de|
152 video\.grosskopfgames\.de|
153 peertube\.schaeferit\.de|
154 peertube\.jackbot\.fr|
155 tube\.extinctionrebellion\.fr|
156 peertube\.f-si\.org|
157 video\.subak\.ovh|
158 videos\.koweb\.fr|
159 peertube\.zergy\.net|
160 peertube\.roflcopter\.fr|
161 peertube\.floss-marketing-school\.com|
162 vloggers\.social|
163 peertube\.iriseden\.eu|
164 videos\.ubuntu-paris\.org|
165 peertube\.mastodon\.host|
166 armstube\.com|
167 peertube\.s2s\.video|
168 peertube\.lol|
169 tube\.open-plug\.eu|
170 open\.tube|
171 peertube\.ch|
172 peertube\.normandie-libre\.fr|
173 peertube\.slat\.org|
174 video\.lacaveatonton\.ovh|
175 peertube\.uno|
176 peertube\.servebeer\.com|
177 peertube\.fedi\.quebec|
178 tube\.h3z\.jp|
179 tube\.plus200\.com|
180 peertube\.eric\.ovh|
181 tube\.metadocs\.cc|
182 tube\.unmondemeilleur\.eu|
183 gouttedeau\.space|
184 video\.antirep\.net|
185 nrop\.cant\.at|
186 tube\.ksl-bmx\.de|
187 tube\.plaf\.fr|
188 tube\.tchncs\.de|
189 video\.devinberg\.com|
190 hitchtube\.fr|
191 peertube\.kosebamse\.com|
192 yunopeertube\.myddns\.me|
193 peertube\.varney\.fr|
194 peertube\.anon-kenkai\.com|
195 tube\.maiti\.info|
196 tubee\.fr|
197 videos\.dinofly\.com|
198 toobnix\.org|
199 videotape\.me|
200 voca\.tube|
201 video\.heromuster\.com|
202 video\.lemediatv\.fr|
203 video\.up\.edu\.ph|
204 balafon\.video|
205 video\.ivel\.fr|
206 thickrips\.cloud|
207 pt\.laurentkruger\.fr|
208 video\.monarch-pass\.net|
209 peertube\.artica\.center|
210 video\.alternanet\.fr|
211 indymotion\.fr|
212 fanvid\.stopthatimp\.net|
213 video\.farci\.org|
214 v\.lesterpig\.com|
215 video\.okaris\.de|
216 tube\.pawelko\.net|
217 peertube\.mablr\.org|
218 tube\.fede\.re|
219 pytu\.be|
220 evertron\.tv|
221 devtube\.dev-wiki\.de|
222 raptube\.antipub\.org|
223 video\.selea\.se|
224 peertube\.mygaia\.org|
225 video\.oh14\.de|
226 peertube\.livingutopia\.org|
227 peertube\.the-penguin\.de|
228 tube\.thechangebook\.org|
229 tube\.anjara\.eu|
230 pt\.pube\.tk|
231 video\.samedi\.pm|
232 mplayer\.demouliere\.eu|
233 widemus\.de|
234 peertube\.me|
235 peertube\.zapashcanon\.fr|
236 video\.latavernedejohnjohn\.fr|
237 peertube\.pcservice46\.fr|
238 peertube\.mazzonetto\.eu|
239 video\.irem\.univ-paris-diderot\.fr|
240 video\.livecchi\.cloud|
241 alttube\.fr|
242 video\.coop\.tools|
243 video\.cabane-libre\.org|
244 peertube\.openstreetmap\.fr|
245 videos\.alolise\.org|
246 irrsinn\.video|
247 video\.antopie\.org|
248 scitech\.video|
249 tube2\.nemsia\.org|
250 video\.amic37\.fr|
251 peertube\.freeforge\.eu|
252 video\.arbitrarion\.com|
253 video\.datsemultimedia\.com|
254 stoptrackingus\.tv|
255 peertube\.ricostrongxxx\.com|
256 docker\.videos\.lecygnenoir\.info|
257 peertube\.togart\.de|
258 tube\.postblue\.info|
259 videos\.domainepublic\.net|
260 peertube\.cyber-tribal\.com|
261 video\.gresille\.org|
262 peertube\.dsmouse\.net|
263 cinema\.yunohost\.support|
264 tube\.theocevaer\.fr|
265 repro\.video|
266 tube\.4aem\.com|
267 quaziinc\.com|
268 peertube\.metawurst\.space|
269 videos\.wakapo\.com|
270 video\.ploud\.fr|
271 video\.freeradical\.zone|
272 tube\.valinor\.fr|
273 refuznik\.video|
274 pt\.kircheneuenburg\.de|
275 peertube\.asrun\.eu|
276 peertube\.lagob\.fr|
277 videos\.side-ways\.net|
278 91video\.online|
279 video\.valme\.io|
280 video\.taboulisme\.com|
281 videos-libr\.es|
282 tv\.mooh\.fr|
283 nuage\.acostey\.fr|
284 video\.monsieur-a\.fr|
285 peertube\.librelois\.fr|
286 videos\.pair2jeux\.tube|
287 videos\.pueseso\.club|
288 peer\.mathdacloud\.ovh|
289 media\.assassinate-you\.net|
290 vidcommons\.org|
291 ptube\.rousset\.nom\.fr|
292 tube\.cyano\.at|
293 videos\.squat\.net|
294 video\.iphodase\.fr|
295 peertube\.makotoworkshop\.org|
296 peertube\.serveur\.slv-valbonne\.fr|
297 vault\.mle\.party|
298 hostyour\.tv|
299 videos\.hack2g2\.fr|
300 libre\.tube|
301 pire\.artisanlogiciel\.net|
302 videos\.numerique-en-commun\.fr|
303 video\.netsyms\.com|
304 video\.die-partei\.social|
305 video\.writeas\.org|
306 peertube\.swarm\.solvingmaz\.es|
307 tube\.pericoloso\.ovh|
308 watching\.cypherpunk\.observer|
309 videos\.adhocmusic\.com|
310 tube\.rfc1149\.net|
311 peertube\.librelabucm\.org|
312 videos\.numericoop\.fr|
313 peertube\.koehn\.com|
314 peertube\.anarchmusicall\.net|
315 tube\.kampftoast\.de|
316 vid\.y-y\.li|
317 peertube\.xtenz\.xyz|
318 diode\.zone|
319 tube\.egf\.mn|
320 peertube\.nomagic\.uk|
321 visionon\.tv|
322 videos\.koumoul\.com|
323 video\.rastapuls\.com|
324 video\.mantlepro\.com|
325 video\.deadsuperhero\.com|
326 peertube\.musicstudio\.pro|
327 peertube\.we-keys\.fr|
328 artitube\.artifaille\.fr|
329 peertube\.ethernia\.net|
330 tube\.midov\.pl|
331 peertube\.fr|
332 watch\.snoot\.tube|
333 peertube\.donnadieu\.fr|
334 argos\.aquilenet\.fr|
335 tube\.nemsia\.org|
336 tube\.bruniau\.net|
337 videos\.darckoune\.moe|
338 tube\.traydent\.info|
339 dev\.videos\.lecygnenoir\.info|
340 peertube\.nayya\.org|
341 peertube\.live|
342 peertube\.mofgao\.space|
343 video\.lequerrec\.eu|
344 peertube\.amicale\.net|
345 aperi\.tube|
346 tube\.ac-lyon\.fr|
347 video\.lw1\.at|
348 www\.yiny\.org|
349 videos\.pofilo\.fr|
350 tube\.lou\.lt|
351 choob\.h\.etbus\.ch|
352 tube\.hoga\.fr|
353 peertube\.heberge\.fr|
354 video\.obermui\.de|
355 videos\.cloudfrancois\.fr|
356 betamax\.video|
357 video\.typica\.us|
358 tube\.piweb\.be|
359 video\.blender\.org|
360 peertube\.cat|
361 tube\.kdy\.ch|
362 pe\.ertu\.be|
363 peertube\.social|
364 videos\.lescommuns\.org|
365 tv\.datamol\.org|
366 videonaute\.fr|
367 dialup\.express|
368 peertube\.nogafa\.org|
369 megatube\.lilomoino\.fr|
370 peertube\.tamanoir\.foucry\.net|
371 peertube\.devosi\.org|
372 peertube\.1312\.media|
373 tube\.bootlicker\.party|
374 skeptikon\.fr|
375 video\.blueline\.mg|
376 tube\.homecomputing\.fr|
377 tube\.ouahpiti\.info|
378 video\.tedomum\.net|
379 video\.g3l\.org|
380 fontube\.fr|
381 peertube\.gaialabs\.ch|
382 tube\.kher\.nl|
383 peertube\.qtg\.fr|
384 video\.migennes\.net|
385 tube\.p2p\.legal|
386 troll\.tv|
387 videos\.iut-orsay\.fr|
388 peertube\.solidev\.net|
389 videos\.cemea\.org|
390 video\.passageenseine\.fr|
391 videos\.festivalparminous\.org|
392 peertube\.touhoppai\.moe|
393 sikke\.fi|
394 peer\.hostux\.social|
395 share\.tube|
396 peertube\.walkingmountains\.fr|
397 videos\.benpro\.fr|
398 peertube\.parleur\.net|
399 peertube\.heraut\.eu|
400 tube\.aquilenet\.fr|
401 peertube\.gegeweb\.eu|
402 framatube\.org|
403 thinkerview\.video|
404 tube\.conferences-gesticulees\.net|
405 peertube\.datagueule\.tv|
406 video\.lqdn\.fr|
407 tube\.mochi\.academy|
408 media\.zat\.im|
409 video\.colibris-outilslibres\.org|
410 tube\.svnet\.fr|
411 peertube\.video|
412 peertube3\.cpy\.re|
413 peertube2\.cpy\.re|
414 videos\.tcit\.fr|
415 peertube\.cpy\.re
416 )'''
417 _UUID_RE = r'[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}'
418 _VALID_URL = r'''(?x)
419 (?:
420 peertube:(?P<host>[^:]+):|
421 https?://(?P<host_2>%s)/(?:videos/(?:watch|embed)|api/v\d/videos)/
422 )
423 (?P<id>%s)
424 ''' % (_INSTANCES_RE, _UUID_RE)
425 _TESTS = [{
426 'url': 'https://peertube.cpy.re/videos/watch/2790feb0-8120-4e63-9af3-c943c69f5e6c',
427 'md5': '80f24ff364cc9d333529506a263e7feb',
428 'info_dict': {
429 'id': '2790feb0-8120-4e63-9af3-c943c69f5e6c',
430 'ext': 'mp4',
431 'title': 'wow',
432 'description': 'wow such video, so gif',
433 'thumbnail': r're:https?://.*\.(?:jpg|png)',
434 'timestamp': 1519297480,
435 'upload_date': '20180222',
436 'uploader': 'Luclu7',
437 'uploader_id': '7fc42640-efdb-4505-a45d-a15b1a5496f1',
438 'uploder_url': 'https://peertube.nsa.ovh/accounts/luclu7',
439 'license': 'Unknown',
440 'duration': 3,
441 'view_count': int,
442 'like_count': int,
443 'dislike_count': int,
444 'tags': list,
445 'categories': list,
446 }
447 }, {
448 'url': 'https://peertube.tamanoir.foucry.net/videos/watch/0b04f13d-1e18-4f1d-814e-4979aa7c9c44',
449 'only_matching': True,
450 }, {
451 # nsfw
452 'url': 'https://tube.22decembre.eu/videos/watch/9bb88cd3-9959-46d9-9ab9-33d2bb704c39',
453 'only_matching': True,
454 }, {
455 'url': 'https://tube.22decembre.eu/videos/embed/fed67262-6edb-4d1c-833b-daa9085c71d7',
456 'only_matching': True,
457 }, {
458 'url': 'https://tube.openalgeria.org/api/v1/videos/c1875674-97d0-4c94-a058-3f7e64c962e8',
459 'only_matching': True,
460 }, {
461 'url': 'peertube:video.blender.org:b37a5b9f-e6b5-415c-b700-04a5cd6ec205',
462 'only_matching': True,
463 }]
464
465 @staticmethod
466 def _extract_peertube_url(webpage, source_url):
467 mobj = re.match(
468 r'https?://(?P<host>[^/]+)/videos/(?:watch|embed)/(?P<id>%s)'
469 % PeerTubeIE._UUID_RE, source_url)
470 if mobj and any(p in webpage for p in (
471 '<title>PeerTube<',
472 'There will be other non JS-based clients to access PeerTube',
473 '>We are sorry but it seems that PeerTube is not compatible with your web browser.<')):
474 return 'peertube:%s:%s' % mobj.group('host', 'id')
475
476 @staticmethod
477 def _extract_urls(webpage, source_url):
478 entries = re.findall(
479 r'''(?x)<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//%s/videos/embed/%s)'''
480 % (PeerTubeIE._INSTANCES_RE, PeerTubeIE._UUID_RE), webpage)
481 if not entries:
482 peertube_url = PeerTubeIE._extract_peertube_url(webpage, source_url)
483 if peertube_url:
484 entries = [peertube_url]
485 return entries
486
487 def _real_extract(self, url):
488 mobj = re.match(self._VALID_URL, url)
489 host = mobj.group('host') or mobj.group('host_2')
490 video_id = mobj.group('id')
491
492 video = self._download_json(
493 'https://%s/api/v1/videos/%s' % (host, video_id), video_id)
494
495 title = video['name']
496
497 formats = []
498 for file_ in video['files']:
499 if not isinstance(file_, dict):
500 continue
501 file_url = url_or_none(file_.get('fileUrl'))
502 if not file_url:
503 continue
504 file_size = int_or_none(file_.get('size'))
505 format_id = try_get(
506 file_, lambda x: x['resolution']['label'], compat_str)
507 f = parse_resolution(format_id)
508 f.update({
509 'url': file_url,
510 'format_id': format_id,
511 'filesize': file_size,
512 })
513 formats.append(f)
514 self._sort_formats(formats)
515
516 def account_data(field):
517 return try_get(video, lambda x: x['account'][field], compat_str)
518
519 category = try_get(video, lambda x: x['category']['label'], compat_str)
520 categories = [category] if category else None
521
522 nsfw = video.get('nsfw')
523 if nsfw is bool:
524 age_limit = 18 if nsfw else 0
525 else:
526 age_limit = None
527
528 return {
529 'id': video_id,
530 'title': title,
531 'description': video.get('description'),
532 'thumbnail': urljoin(url, video.get('thumbnailPath')),
533 'timestamp': unified_timestamp(video.get('publishedAt')),
534 'uploader': account_data('displayName'),
535 'uploader_id': account_data('uuid'),
536 'uploder_url': account_data('url'),
537 'license': try_get(
538 video, lambda x: x['licence']['label'], compat_str),
539 'duration': int_or_none(video.get('duration')),
540 'view_count': int_or_none(video.get('views')),
541 'like_count': int_or_none(video.get('likes')),
542 'dislike_count': int_or_none(video.get('dislikes')),
543 'age_limit': age_limit,
544 'tags': try_get(video, lambda x: x['tags'], list),
545 'categories': categories,
546 'formats': formats,
547 }