]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/peertube.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / peertube.py
index 1e22f24e3f5588813cff8018708ac74b4b23a653..68e15737b978a52d64e3be21ea861858e69aeade 100644 (file)
@@ -1,12 +1,10 @@
-# 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,
@@ -86,6 +84,7 @@ class PeerTubeIE(InfoExtractor):
                             maindreieck-tv\.de|
                             mani\.tube|
                             manicphase\.me|
+                            media\.fsfe\.org|
                             media\.gzevd\.de|
                             media\.inno3\.cricket|
                             media\.kaitaia\.life|
@@ -1058,6 +1057,7 @@ class PeerTubeIE(InfoExtractor):
                     )
                     (?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',
@@ -1159,16 +1159,15 @@ def _extract_peertube_url(webpage, source_url):
                 '>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(
@@ -1234,7 +1233,6 @@ def _real_extract(self, url):
             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:
@@ -1386,8 +1384,7 @@ def _extract_playlist(self, host, type, id):
         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 = info.get('thumbnailPath')
-        thumbnail = f'https://{host}{thumbnail}' if thumbnail else None
+        thumbnail = format_field(info, 'thumbnailPath', f'https://{host}%s')
 
         entries = OnDemandPagedList(functools.partial(
             self.fetch_page, host, id, type), self._PAGE_SIZE)