-# coding: utf-8
-from __future__ import unicode_literals
-
+import functools
import re
from .common import InfoExtractor
from ..compat import compat_str
from ..utils import (
+ format_field,
int_or_none,
parse_resolution,
str_or_none,
unified_timestamp,
url_or_none,
urljoin,
+ OnDemandPagedList,
)
maindreieck-tv\.de|
mani\.tube|
manicphase\.me|
+ media\.fsfe\.org|
media\.gzevd\.de|
media\.inno3\.cricket|
media\.kaitaia\.life|
)
(?P<id>%s)
''' % (_INSTANCES_RE, _UUID_RE)
+ _EMBED_REGEX = [r'''(?x)<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//{_INSTANCES_RE}/videos/embed/{cls._UUID_RE})''']
_TESTS = [{
'url': 'https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d',
'md5': '8563064d245a4be5705bddb22bb00a28',
'uploader': 'Framasoft',
'uploader_id': '3',
'uploader_url': 'https://framatube.org/accounts/framasoft',
- 'channel': 'Les vidéos de Framasoft',
- 'channel_id': '2',
- 'channel_url': 'https://framatube.org/video-channels/bf54d359-cfad-4935-9d45-9d6be93f63e8',
+ 'channel': 'A propos de PeerTube',
+ 'channel_id': '2215',
+ 'channel_url': 'https://framatube.org/video-channels/joinpeertube',
'language': 'en',
'license': 'Attribution - Share Alike',
'duration': 113,
'uploader': 'Drew DeVault',
}
}, {
- 'url': 'https://peertube.tamanoir.foucry.net/videos/watch/0b04f13d-1e18-4f1d-814e-4979aa7c9c44',
+ 'url': 'https://peertube.debian.social/videos/watch/0b04f13d-1e18-4f1d-814e-4979aa7c9c44',
'only_matching': True,
}, {
# nsfw
- 'url': 'https://tube.22decembre.eu/videos/watch/9bb88cd3-9959-46d9-9ab9-33d2bb704c39',
+ 'url': 'https://vod.ksite.de/videos/watch/9bb88cd3-9959-46d9-9ab9-33d2bb704c39',
'only_matching': True,
}, {
- 'url': 'https://tube.22decembre.eu/videos/embed/fed67262-6edb-4d1c-833b-daa9085c71d7',
+ 'url': 'https://vod.ksite.de/videos/embed/fed67262-6edb-4d1c-833b-daa9085c71d7',
'only_matching': True,
}, {
- 'url': 'https://tube.openalgeria.org/api/v1/videos/c1875674-97d0-4c94-a058-3f7e64c962e8',
+ 'url': 'https://peertube.tv/api/v1/videos/c1875674-97d0-4c94-a058-3f7e64c962e8',
'only_matching': True,
}, {
- 'url': 'peertube:video.blender.org:b37a5b9f-e6b5-415c-b700-04a5cd6ec205',
+ 'url': 'peertube:framatube.org:b37a5b9f-e6b5-415c-b700-04a5cd6ec205',
'only_matching': True,
}]
'>We are sorry but it seems that PeerTube is not compatible with your web browser.<')):
return 'peertube:%s:%s' % mobj.group('host', 'id')
- @staticmethod
- def _extract_urls(webpage, source_url):
- entries = re.findall(
- r'''(?x)<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)?//%s/videos/embed/%s)'''
- % (PeerTubeIE._INSTANCES_RE, PeerTubeIE._UUID_RE), webpage)
- if not entries:
- peertube_url = PeerTubeIE._extract_peertube_url(webpage, source_url)
- if peertube_url:
- entries = [peertube_url]
- return entries
+ @classmethod
+ def _extract_embed_urls(cls, url, webpage):
+ embeds = tuple(super()._extract_embed_urls(url, webpage))
+ if embeds:
+ return embeds
+
+ peertube_url = cls._extract_peertube_url(webpage, url)
+ if peertube_url:
+ return [peertube_url]
def _call_api(self, host, video_id, path, note=None, errnote=None, fatal=True):
return self._download_json(
else:
f['fps'] = int_or_none(file_.get('fps'))
formats.append(f)
- self._sort_formats(formats)
description = video.get('description')
if description and len(description) >= 250:
'subtitles': subtitles,
'webpage_url': webpage_url,
}
+
+
+class PeerTubePlaylistIE(InfoExtractor):
+ IE_NAME = 'PeerTube:Playlist'
+ _TYPES = {
+ 'a': 'accounts',
+ 'c': 'video-channels',
+ 'w/p': 'video-playlists',
+ }
+ _VALID_URL = r'''(?x)
+ https?://(?P<host>%s)/(?P<type>(?:%s))/
+ (?P<id>[^/]+)
+ ''' % (PeerTubeIE._INSTANCES_RE, '|'.join(_TYPES.keys()))
+ _TESTS = [{
+ 'url': 'https://peertube.tux.ovh/w/p/3af94cba-95e8-4b74-b37a-807ab6d82526',
+ 'info_dict': {
+ 'id': '3af94cba-95e8-4b74-b37a-807ab6d82526',
+ 'description': 'playlist',
+ 'timestamp': 1611171863,
+ 'title': 'playlist',
+ },
+ 'playlist_mincount': 6,
+ }, {
+ 'url': 'https://peertube.tux.ovh/w/p/wkyqcQBnsvFxtUB2pkYc1e',
+ 'info_dict': {
+ 'id': 'wkyqcQBnsvFxtUB2pkYc1e',
+ 'description': 'Cette liste de vidéos contient uniquement les jeux qui peuvent être terminés en une seule vidéo.',
+ 'title': 'Let\'s Play',
+ 'timestamp': 1604147331,
+ },
+ 'playlist_mincount': 6,
+ }, {
+ 'url': 'https://peertube.debian.social/w/p/hFdJoTuyhNJVa1cDWd1d12',
+ 'info_dict': {
+ 'id': 'hFdJoTuyhNJVa1cDWd1d12',
+ 'description': 'Diversas palestras do Richard Stallman no Brasil.',
+ 'title': 'Richard Stallman no Brasil',
+ 'timestamp': 1599676222,
+ },
+ 'playlist_mincount': 9,
+ }, {
+ 'url': 'https://peertube2.cpy.re/a/chocobozzz/videos',
+ 'info_dict': {
+ 'id': 'chocobozzz',
+ 'timestamp': 1553874564,
+ 'title': 'chocobozzz',
+ },
+ 'playlist_mincount': 2,
+ }, {
+ 'url': 'https://framatube.org/c/bf54d359-cfad-4935-9d45-9d6be93f63e8/videos',
+ 'info_dict': {
+ 'id': 'bf54d359-cfad-4935-9d45-9d6be93f63e8',
+ 'timestamp': 1519917377,
+ 'title': 'Les vidéos de Framasoft',
+ },
+ 'playlist_mincount': 345,
+ }, {
+ 'url': 'https://peertube2.cpy.re/c/blender_open_movies@video.blender.org/videos',
+ 'info_dict': {
+ 'id': 'blender_open_movies@video.blender.org',
+ 'timestamp': 1542287810,
+ 'title': 'Official Blender Open Movies',
+ },
+ 'playlist_mincount': 11,
+ }]
+ _API_BASE = 'https://%s/api/v1/%s/%s%s'
+ _PAGE_SIZE = 30
+
+ def call_api(self, host, name, path, base, **kwargs):
+ return self._download_json(
+ self._API_BASE % (host, base, name, path), name, **kwargs)
+
+ def fetch_page(self, host, id, type, page):
+ page += 1
+ video_data = self.call_api(
+ host, id,
+ f'/videos?sort=-createdAt&start={self._PAGE_SIZE * (page - 1)}&count={self._PAGE_SIZE}&nsfw=both',
+ type, note=f'Downloading page {page}').get('data', [])
+ for video in video_data:
+ shortUUID = video.get('shortUUID') or try_get(video, lambda x: x['video']['shortUUID'])
+ video_title = video.get('name') or try_get(video, lambda x: x['video']['name'])
+ yield self.url_result(
+ f'https://{host}/w/{shortUUID}', PeerTubeIE.ie_key(),
+ video_id=shortUUID, video_title=video_title)
+
+ def _extract_playlist(self, host, type, id):
+ info = self.call_api(host, id, '', type, note='Downloading playlist information', fatal=False)
+
+ playlist_title = info.get('displayName')
+ playlist_description = info.get('description')
+ playlist_timestamp = unified_timestamp(info.get('createdAt'))
+ channel = try_get(info, lambda x: x['ownerAccount']['name']) or info.get('displayName')
+ channel_id = try_get(info, lambda x: x['ownerAccount']['id']) or info.get('id')
+ thumbnail = format_field(info, 'thumbnailPath', f'https://{host}%s')
+
+ entries = OnDemandPagedList(functools.partial(
+ self.fetch_page, host, id, type), self._PAGE_SIZE)
+
+ return self.playlist_result(
+ entries, id, playlist_title, playlist_description,
+ timestamp=playlist_timestamp, channel=channel, channel_id=channel_id, thumbnail=thumbnail)
+
+ def _real_extract(self, url):
+ type, host, id = self._match_valid_url(url).group('type', 'host', 'id')
+ type = self._TYPES[type]
+ return self._extract_playlist(host, type, id)