]>
jfr.im git - yt-dlp.git/blob - youtube_dlc/extractor/peertube.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
19 class PeerTubeIE(InfoExtractor
):
20 _INSTANCES_RE
= r
'''(?:
21 # Taken from https://instances.joinpeertube.org/instances
22 peertube\.rainbowswingers\.net|
26 videomensoif\.ynh\.fr|
27 peertube\.travelpandas\.eu|
28 peertube\.rachetjay\.fr|
29 peertube\.montecsys\.fr|
32 peertube\.umeahackerspace\.se|
34 video\.monsieurbidouille\.fr|
35 tube\.openalgeria\.org|
37 video\.anormallostpod\.ovh|
38 tube\.crapaud-fou\.org|
42 peertube\.snargol\.com|
47 peertube\.osureplayviewer\.xyz|
48 peertube\.mathieufamily\.ovh|
51 peertube\.fediverse\.ru|
52 peertube\.oiseauroch\.fr|
60 peertube\.chantierlibre\.org|
66 videos\.elbinario\.net|
72 peertube\.gnumeria\.eu\.org|
76 tube\.kalah-france\.org|
80 peertube\.hatthieves\.es|
81 video\.fitchfamily\.org|
86 peertube\.harmoniescreatives\.com|
89 video\.bruitbruit\.com|
90 peertube\.foxfam\.club|
93 peertube\.malbert\.xyz|
94 peertube\.bilange\.ca|
97 peertube\.fedilab\.app|
99 video\.mstddntfdn\.online|
101 peertube\.sl-network\.fr|
102 peertube\.dynlinux\.io|
103 peertube\.david\.durieux\.family|
104 peertube\.linuxrocks\.online|
106 v\.kretschmann\.social|
109 tube\.dragonpsi\.xyz|
110 peertube\.boneheadmedia\.com|
111 videos\.funkwhale\.audio|
113 peertube\.gcaillaut\.fr|
120 peertube\.simounet\.net|
124 peertube\.kerenon\.com|
126 tube\.calculate\.social|
127 peertube\.mckillop\.org|
128 tube\.netzspielplatz\.de|
132 peertube\.stephenson\.cc|
134 peertube\.kajalinifi\.de|
137 peertube\.ffs2play\.fr|
138 peertube\.leboulaire\.ovh|
139 peertube\.tronic-studio\.com|
140 peertube\.public\.cat|
141 peertube\.metalbanana\.net|
143 peertube\.alter-nativ-voll\.de|
145 tube\.worldofhauru\.xyz|
147 peertube\.teleassist\.fr|
150 media\.privacyinternational\.org|
152 video\.halle-leaks\.de|
153 video\.grosskopfgames\.de|
154 peertube\.schaeferit\.de|
155 peertube\.jackbot\.fr|
156 tube\.extinctionrebellion\.fr|
160 peertube\.zergy\.net|
161 peertube\.roflcopter\.fr|
162 peertube\.floss-marketing-school\.com|
164 peertube\.iriseden\.eu|
165 videos\.ubuntu-paris\.org|
166 peertube\.mastodon\.host|
168 peertube\.s2s\.video|
173 peertube\.normandie-libre\.fr|
175 video\.lacaveatonton\.ovh|
177 peertube\.servebeer\.com|
178 peertube\.fedi\.quebec|
183 tube\.unmondemeilleur\.eu|
190 video\.devinberg\.com|
192 peertube\.kosebamse\.com|
193 yunopeertube\.myddns\.me|
194 peertube\.varney\.fr|
195 peertube\.anon-kenkai\.com|
198 videos\.dinofly\.com|
202 video\.heromuster\.com|
203 video\.lemediatv\.fr|
208 pt\.laurentkruger\.fr|
209 video\.monarch-pass\.net|
210 peertube\.artica\.center|
211 video\.alternanet\.fr|
213 fanvid\.stopthatimp\.net|
218 peertube\.mablr\.org|
222 devtube\.dev-wiki\.de|
223 raptube\.antipub\.org|
225 peertube\.mygaia\.org|
227 peertube\.livingutopia\.org|
228 peertube\.the-penguin\.de|
229 tube\.thechangebook\.org|
233 mplayer\.demouliere\.eu|
236 peertube\.zapashcanon\.fr|
237 video\.latavernedejohnjohn\.fr|
238 peertube\.pcservice46\.fr|
239 peertube\.mazzonetto\.eu|
240 video\.irem\.univ-paris-diderot\.fr|
241 video\.livecchi\.cloud|
244 video\.cabane-libre\.org|
245 peertube\.openstreetmap\.fr|
246 videos\.alolise\.org|
252 peertube\.freeforge\.eu|
253 video\.arbitrarion\.com|
254 video\.datsemultimedia\.com|
256 peertube\.ricostrongxxx\.com|
257 docker\.videos\.lecygnenoir\.info|
258 peertube\.togart\.de|
259 tube\.postblue\.info|
260 videos\.domainepublic\.net|
261 peertube\.cyber-tribal\.com|
262 video\.gresille\.org|
263 peertube\.dsmouse\.net|
264 cinema\.yunohost\.support|
265 tube\.theocevaer\.fr|
269 peertube\.metawurst\.space|
272 video\.freeradical\.zone|
275 pt\.kircheneuenburg\.de|
278 videos\.side-ways\.net|
281 video\.taboulisme\.com|
285 video\.monsieur-a\.fr|
286 peertube\.librelois\.fr|
287 videos\.pair2jeux\.tube|
288 videos\.pueseso\.club|
289 peer\.mathdacloud\.ovh|
290 media\.assassinate-you\.net|
292 ptube\.rousset\.nom\.fr|
296 peertube\.makotoworkshop\.org|
297 peertube\.serveur\.slv-valbonne\.fr|
302 pire\.artisanlogiciel\.net|
303 videos\.numerique-en-commun\.fr|
305 video\.die-partei\.social|
307 peertube\.swarm\.solvingmaz\.es|
308 tube\.pericoloso\.ovh|
309 watching\.cypherpunk\.observer|
310 videos\.adhocmusic\.com|
312 peertube\.librelabucm\.org|
313 videos\.numericoop\.fr|
314 peertube\.koehn\.com|
315 peertube\.anarchmusicall\.net|
316 tube\.kampftoast\.de|
318 peertube\.xtenz\.xyz|
321 peertube\.nomagic\.uk|
323 videos\.koumoul\.com|
324 video\.rastapuls\.com|
325 video\.mantlepro\.com|
326 video\.deadsuperhero\.com|
327 peertube\.musicstudio\.pro|
328 peertube\.we-keys\.fr|
329 artitube\.artifaille\.fr|
330 peertube\.ethernia\.net|
334 peertube\.donnadieu\.fr|
335 argos\.aquilenet\.fr|
338 videos\.darckoune\.moe|
339 tube\.traydent\.info|
340 dev\.videos\.lecygnenoir\.info|
341 peertube\.nayya\.org|
343 peertube\.mofgao\.space|
344 video\.lequerrec\.eu|
345 peertube\.amicale\.net|
354 peertube\.heberge\.fr|
356 videos\.cloudfrancois\.fr|
365 videos\.lescommuns\.org|
369 peertube\.nogafa\.org|
370 megatube\.lilomoino\.fr|
371 peertube\.tamanoir\.foucry\.net|
372 peertube\.devosi\.org|
373 peertube\.1312\.media|
374 tube\.bootlicker\.party|
377 tube\.homecomputing\.fr|
378 tube\.ouahpiti\.info|
382 peertube\.gaialabs\.ch|
385 video\.migennes\.net|
388 videos\.iut-orsay\.fr|
389 peertube\.solidev\.net|
391 video\.passageenseine\.fr|
392 videos\.festivalparminous\.org|
393 peertube\.touhoppai\.moe|
395 peer\.hostux\.social|
397 peertube\.walkingmountains\.fr|
399 peertube\.parleur\.net|
400 peertube\.heraut\.eu|
402 peertube\.gegeweb\.eu|
405 tube\.conferences-gesticulees\.net|
406 peertube\.datagueule\.tv|
408 tube\.mochi\.academy|
410 video\.colibris-outilslibres\.org|
418 _UUID_RE
= r
'[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}'
419 _API_BASE
= 'https://%s/api/v1/videos/%s/%s'
420 _VALID_URL
= r
'''(?x)
422 peertube:(?P<host>[^:]+):|
423 https?://(?P<host_2>%s)/(?:videos/(?:watch|embed)|api/v\d/videos)/
426 ''' % (_INSTANCES_RE
, _UUID_RE
)
428 'url': 'https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d',
429 'md5': '9bed8c0137913e17b86334e5885aacff',
431 'id': '9c9de5e8-0a1e-484a-b099-e80766180a6d',
433 'title': 'What is PeerTube?',
434 'description': 'md5:3fefb8dde2b189186ce0719fda6f7b10',
435 'thumbnail': r
're:https?://.*\.(?:jpg|png)',
436 'timestamp': 1538391166,
437 'upload_date': '20181001',
438 'uploader': 'Framasoft',
440 'uploader_url': 'https://framatube.org/accounts/framasoft',
441 'channel': 'Les vidéos de Framasoft',
443 'channel_url': 'https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8',
445 'license': 'Attribution - Share Alike',
449 'dislike_count': int,
450 'tags': ['framasoft', 'peertube'],
451 'categories': ['Science & Technology'],
454 'url': 'https://peertube.tamanoir.foucry.net/videos/watch/0b04f13d-1e18-4f1d-814e-4979aa7c9c44',
455 'only_matching': True,
458 'url': 'https://tube.22decembre.eu/videos/watch/9bb88cd3-9959-46d9-9ab9-33d2bb704c39',
459 'only_matching': True,
461 'url': 'https://tube.22decembre.eu/videos/embed/fed67262-6edb-4d1c-833b-daa9085c71d7',
462 'only_matching': True,
464 'url': 'https://tube.openalgeria.org/api/v1/videos/c1875674-97d0-4c94-a058-3f7e64c962e8',
465 'only_matching': True,
467 'url': 'peertube:video.blender.org:b37a5b9f-e6b5-415c-b700-04a5cd6ec205',
468 'only_matching': True,
472 def _extract_peertube_url(webpage
, source_url
):
474 r
'https?://(?P<host>[^/]+)/videos/(?:watch|embed)/(?P<id>%s)'
475 % PeerTubeIE
._UUID
_RE
, source_url
)
476 if mobj
and any(p
in webpage
for p
in (
478 'There will be other non JS-based clients to access PeerTube',
479 '>We are sorry but it seems that PeerTube is not compatible with your web browser.<')):
480 return 'peertube:%s:%s' % mobj
.group('host', 'id')
483 def _extract_urls(webpage
, source_url
):
484 entries
= re
.findall(
485 r
'''(?x)<iframe[^>]+\bsrc=["\'](?P
<url
>(?
:https?
:)?
//%s/videos
/embed
/%s)'''
486 % (PeerTubeIE._INSTANCES_RE, PeerTubeIE._UUID_RE), webpage)
488 peertube_url = PeerTubeIE._extract_peertube_url(webpage, source_url)
490 entries = [peertube_url]
493 def _call_api(self, host, video_id, path, note=None, errnote=None, fatal=True):
494 return self._download_json(
495 self._API_BASE % (host, video_id, path), video_id,
496 note=note, errnote=errnote, fatal=fatal)
498 def _get_subtitles(self, host, video_id):
499 captions = self._call_api(
500 host, video_id, 'captions', note='Downloading captions JSON',
502 if not isinstance(captions, dict):
504 data = captions.get('data')
505 if not isinstance(data, list):
509 language_id = try_get(e, lambda x: x['language']['id'], compat_str)
510 caption_url = urljoin('https://%s' % host, e.get('captionPath'))
513 subtitles.setdefault(language_id or 'en', []).append({
518 def _real_extract(self, url):
519 mobj = re.match(self._VALID_URL, url)
520 host = mobj.group('host') or mobj.group('host_2')
521 video_id = mobj.group('id')
523 video = self._call_api(
524 host, video_id, '', note='Downloading video JSON')
526 title = video['name']
529 for file_ in video['files']:
530 if not isinstance(file_, dict):
532 file_url = url_or_none(file_.get('fileUrl'))
535 file_size = int_or_none(file_.get('size'))
537 file_, lambda x: x['resolution']['label'], compat_str)
538 f = parse_resolution(format_id)
541 'format_id': format_id,
542 'filesize': file_size,
545 self._sort_formats(formats)
547 full_description = self._call_api(
548 host, video_id, 'description', note='Downloading description JSON',
552 if isinstance(full_description, dict):
553 description = str_or_none(full_description.get('description'))
555 description = video.get('description')
557 subtitles = self.extract_subtitles(host, video_id)
559 def data(section, field, type_):
560 return try_get(video, lambda x: x[section][field], type_)
562 def account_data(field, type_):
563 return data('account', field, type_)
565 def channel_data(field, type_):
566 return data('channel', field, type_)
568 category = data('category', 'label', compat_str)
569 categories = [category] if category else None
571 nsfw = video.get('nsfw')
573 age_limit = 18 if nsfw else 0
580 'description': description,
581 'thumbnail': urljoin(url, video.get('thumbnailPath')),
582 'timestamp': unified_timestamp(video.get('publishedAt')),
583 'uploader': account_data('displayName', compat_str),
584 'uploader_id': str_or_none(account_data('id', int)),
585 'uploader_url': url_or_none(account_data('url', compat_str)),
586 'channel': channel_data('displayName', compat_str),
587 'channel_id': str_or_none(channel_data('id', int)),
588 'channel_url': url_or_none(channel_data('url', compat_str)),
589 'language': data('language', 'id', compat_str),
590 'license': data('licence', 'label', compat_str),
591 'duration': int_or_none(video.get('duration')),
592 'view_count': int_or_none(video.get('views')),
593 'like_count': int_or_none(video.get('likes')),
594 'dislike_count': int_or_none(video.get('dislikes')),
595 'age_limit': age_limit,
596 'tags': try_get(video, lambda x: x['tags'], list),
597 'categories': categories,
599 'subtitles': subtitles