]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/streamable.py
[ie/bitchute] Fix extractors (#10301)
[yt-dlp.git] / yt_dlp / extractor / streamable.py
index 808129649cb6820244e51a48bbd97602faa9d997..62ae0ee46cb19cc82e361399f65dbecdb82edf9f 100644 (file)
@@ -1,20 +1,16 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
-import re
-
 from .common import InfoExtractor
 from ..utils import (
     ExtractorError,
     float_or_none,
     int_or_none,
-    try_get,
     parse_codecs,
+    try_get,
 )
 
 
 class StreamableIE(InfoExtractor):
     _VALID_URL = r'https?://streamable\.com/(?:[es]/)?(?P<id>\w+)'
+    _EMBED_REGEX = [r'<iframe[^>]+\bsrc=(?P<q1>[\'"])(?P<url>(?:https?:)?//streamable\.com/.+?)(?P=q1)']
     _TESTS = [
         {
             'url': 'https://streamable.com/dnd1',
@@ -29,7 +25,7 @@ class StreamableIE(InfoExtractor):
                 'upload_date': '20160208',
                 'duration': 61.516,
                 'view_count': int,
-            }
+            },
         },
         # older video without bitrate, width/height, codecs, etc. info
         {
@@ -44,7 +40,7 @@ class StreamableIE(InfoExtractor):
                 'upload_date': '20150311',
                 'duration': 12,
                 'view_count': int,
-            }
+            },
         },
         {
             'url': 'https://streamable.com/e/dnd1',
@@ -53,17 +49,9 @@ class StreamableIE(InfoExtractor):
         {
             'url': 'https://streamable.com/s/okkqk/drxjds',
             'only_matching': True,
-        }
+        },
     ]
 
-    @staticmethod
-    def _extract_url(webpage):
-        mobj = re.search(
-            r'<iframe[^>]+src=(?P<q1>[\'"])(?P<src>(?:https?:)?//streamable\.com/(?:(?!\1).+))(?P=q1)',
-            webpage)
-        if mobj:
-            return mobj.group('src')
-
     def _real_extract(self, url):
         video_id = self._match_id(url)
 
@@ -71,7 +59,7 @@ def _real_extract(self, url):
         # to return video info like the title properly sometimes, and doesn't
         # include info like the video duration
         video = self._download_json(
-            'https://ajax.streamable.com/videos/%s' % video_id, video_id)
+            f'https://ajax.streamable.com/videos/{video_id}', video_id)
 
         # Format IDs:
         # 0 The video is being uploaded
@@ -101,7 +89,6 @@ def _real_extract(self, url):
                 'vcodec': parse_codecs(try_get(info, lambda x: x['input_metadata']['video_codec_name'])).get('vcodec'),
                 'acodec': parse_codecs(try_get(info, lambda x: x['input_metadata']['audio_codec_name'])).get('acodec'),
             })
-        self._sort_formats(formats)
 
         return {
             'id': video_id,
@@ -112,5 +99,5 @@ def _real_extract(self, url):
             'timestamp': float_or_none(video.get('date_added')),
             'duration': float_or_none(video.get('duration')),
             'view_count': int_or_none(video.get('plays')),
-            'formats': formats
+            'formats': formats,
         }