]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/tvopengr.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / tvopengr.py
index 667f6660fbceea0a495fa45c86d168f765f24786..e208e57f2f736b197fbba8df15b94b9323b24439 100644 (file)
@@ -1,14 +1,8 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
-import re
-
 from .common import InfoExtractor
 from ..utils import (
     determine_ext,
     get_elements_text_and_html_by_attribute,
-    merge_dicts,
-    unescapeHTML,
+    scale_thumbnails_to_max_format_width,
 )
 
 
@@ -75,24 +69,8 @@ def _extract_formats_and_subs(self, response, video_id):
                 continue
             formats.extend(formats_)
             self._merge_subtitles(subs_, target=subs)
-        self._sort_formats(formats)
         return formats, subs
 
-    @staticmethod
-    def _scale_thumbnails_to_max_width(formats, thumbnails, url_width_re):
-        _keys = ('width', 'height')
-        max_dimensions = max(
-            [tuple(format.get(k) or 0 for k in _keys) for format in formats],
-            default=(0, 0))
-        if not max_dimensions[0]:
-            return thumbnails
-        return [
-            merge_dicts(
-                {'url': re.sub(url_width_re, str(max_dimensions[0]), thumbnail['url'])},
-                dict(zip(_keys, max_dimensions)), thumbnail)
-            for thumbnail in thumbnails
-        ]
-
     def _real_extract(self, url):
         netloc, video_id, display_id = self._match_valid_url(url).group('netloc', 'id', 'slug')
         if netloc.find('tvopen.gr') == -1:
@@ -102,7 +80,7 @@ def _real_extract(self, url):
         info['formats'], info['subtitles'] = self._extract_formats_and_subs(
             self._download_json(self._API_ENDPOINT, video_id, query={'cid': video_id}),
             video_id)
-        info['thumbnails'] = self._scale_thumbnails_to_max_width(
+        info['thumbnails'] = scale_thumbnails_to_max_format_width(
             info['formats'], info['thumbnails'], r'(?<=/imgHandler/)\d+')
         description, _html = next(get_elements_text_and_html_by_attribute('class', 'description', webpage))
         if description and _html.startswith('<span '):
@@ -116,7 +94,7 @@ class TVOpenGrEmbedIE(TVOpenGrBaseIE):
     IE_NAME = 'tvopengr:embed'
     IE_DESC = 'tvopen.gr embedded videos'
     _VALID_URL = r'(?:https?:)?//(?:www\.|cdn\.|)(?:tvopen|ethnos).gr/embed/(?P<id>\d+)'
-    _EMBED_RE = re.compile(rf'''<iframe[^>]+?src=(?P<_q1>["'])(?P<url>{_VALID_URL})(?P=_q1)''')
+    _EMBED_REGEX = [rf'''<iframe[^>]+?src=(?P<_q1>["'])(?P<url>{_VALID_URL})(?P=_q1)''']
 
     _TESTS = [{
         'url': 'https://cdn.ethnos.gr/embed/100963',
@@ -133,11 +111,6 @@ class TVOpenGrEmbedIE(TVOpenGrBaseIE):
         },
     }]
 
-    @classmethod
-    def _extract_urls(cls, webpage):
-        for mobj in cls._EMBED_RE.finditer(webpage):
-            yield unescapeHTML(mobj.group('url'))
-
     def _real_extract(self, url):
         video_id = self._match_id(url)
         return self._return_canonical_url(url, video_id)