]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/ustream.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / ustream.py
index 1e29cbe224ad73e4e0b03a4a0fba1f090ed3601c..046e3d768c530cff47d72ba1469da06016688f0f 100644 (file)
@@ -1,5 +1,3 @@
-from __future__ import unicode_literals
-
 import random
 import re
 
@@ -9,10 +7,11 @@
     compat_urlparse,
 )
 from ..utils import (
-    encode_data_uri,
     ExtractorError,
-    int_or_none,
+    encode_data_uri,
     float_or_none,
+    int_or_none,
+    join_nonempty,
     mimetype2ext,
     str_or_none,
 )
@@ -21,6 +20,7 @@
 class UstreamIE(InfoExtractor):
     _VALID_URL = r'https?://(?:www\.)?(?:ustream\.tv|video\.ibm\.com)/(?P<type>recorded|embed|embed/recorded)/(?P<id>\d+)'
     IE_NAME = 'ustream'
+    _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?(?:ustream\.tv|video\.ibm\.com)/embed/.+?)\1']
     _TESTS = [{
         'url': 'http://www.ustream.tv/recorded/20274954',
         'md5': '088f151799e8f572f84eb62f17d73e5c',
@@ -72,13 +72,6 @@ class UstreamIE(InfoExtractor):
         'only_matching': True,
     }]
 
-    @staticmethod
-    def _extract_url(webpage):
-        mobj = re.search(
-            r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:www\.)?(?:ustream\.tv|video\.ibm\.com)/embed/.+?)\1', webpage)
-        if mobj is not None:
-            return mobj.group('url')
-
     def _get_stream_info(self, url, video_id, app_id_ver, extra_note=None):
         def num_to_hex(n):
             return hex(n)[2:]
@@ -139,8 +132,8 @@ def resolve_dash_template(template, idx, chunk_hash):
             content_type = stream['contentType']
             kind = content_type.split('/')[0]
             f = {
-                'format_id': '-'.join(filter(None, [
-                    'dash', kind, str_or_none(stream.get('bitrate'))])),
+                'format_id': join_nonempty(
+                    'dash', kind, str_or_none(stream.get('bitrate'))),
                 'protocol': 'http_dash_segments',
                 # TODO: generate a MPD doc for external players?
                 'url': encode_data_uri(b'<MPD/>', 'text/xml'),
@@ -165,7 +158,7 @@ def resolve_dash_template(template, idx, chunk_hash):
         return formats
 
     def _real_extract(self, url):
-        m = re.match(self._VALID_URL, url)
+        m = self._match_valid_url(url)
         video_id = m.group('id')
 
         # some sites use this embed format (see: https://github.com/ytdl-org/youtube-dl/issues/2990)
@@ -217,8 +210,6 @@ def _real_extract(self, url):
                 formats.extend(self._parse_segmented_mp4(dash_streams))
             '''
 
-        self._sort_formats(formats)
-
         description = video.get('description')
         timestamp = int_or_none(video.get('created_at'))
         duration = float_or_none(video.get('length'))
@@ -258,7 +249,7 @@ class UstreamChannelIE(InfoExtractor):
     }
 
     def _real_extract(self, url):
-        m = re.match(self._VALID_URL, url)
+        m = self._match_valid_url(url)
         display_id = m.group('slug')
         webpage = self._download_webpage(url, display_id)
         channel_id = self._html_search_meta('ustream:channel_id', webpage)