]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/mainstreaming.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / mainstreaming.py
index 213a1df5723e9655e05186fddc2213a92d1e0796..fb9350584a33171863e7afce30b167ed09728007 100644 (file)
@@ -1,19 +1,18 @@
 import re
 
 from .common import InfoExtractor
-
 from ..utils import (
     int_or_none,
     js_to_json,
     parse_duration,
     traverse_obj,
     try_get,
-    urljoin
+    urljoin,
 )
 
 
 class MainStreamingIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:webtools-?)?(?P<host>[A-Za-z0-9-]*\.msvdn.net)/(?:embed|amp_embed|content)/(?P<id>\w+)'
+    _VALID_URL = r'https?://(?:webtools-?)?(?P<host>[A-Za-z0-9-]*\.msvdn\.net)/(?:embed|amp_embed|content)/(?P<id>\w+)'
     _EMBED_REGEX = [rf'<iframe[^>]+?src=["\']?(?P<url>{_VALID_URL})["\']?']
     IE_DESC = 'MainStreaming Player'
 
@@ -31,9 +30,9 @@ class MainStreamingIE(InfoExtractor):
             },
             'expected_warnings': [
                 'Ignoring alternative content ID: WDAF1KOWUpH3',
-                'MainStreaming said: Live event is OFFLINE'
+                'MainStreaming said: Live event is OFFLINE',
             ],
-            'skip': 'live stream offline'
+            'skip': 'live stream offline',
         }, {
             # playlist
             'url': 'https://webtools-e18da6642b684f8aa9ae449862783a56.msvdn.net/embed/WDAF1KOWUpH3',
@@ -41,7 +40,7 @@ class MainStreamingIE(InfoExtractor):
                 'id': 'WDAF1KOWUpH3',
                 'title': 'Playlist homepage',
             },
-            'playlist_mincount': 2
+            'playlist_mincount': 2,
         }, {
             # livestream
             'url': 'https://webtools-859c1818ed614cc5b0047439470927b0.msvdn.net/embed/tDoFkZD3T1Lw',
@@ -52,7 +51,7 @@ class MainStreamingIE(InfoExtractor):
                 'ext': 'mp4',
                 'thumbnail': r're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
             },
-            'skip': 'live stream'
+            'skip': 'live stream',
         }, {
             'url': 'https://webtools-f5842579ff984c1c98d63b8d789673eb.msvdn.net/embed/EUlZfGWkGpOd?autoPlay=false',
             'info_dict': {
@@ -62,8 +61,8 @@ class MainStreamingIE(InfoExtractor):
                 'ext': 'mp4',
                 'live_status': 'not_live',
                 'thumbnail': r're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
-                'duration': 1512
-            }
+                'duration': 1512,
+            },
         }, {
             # video without webtools- prefix
             'url': 'https://f5842579ff984c1c98d63b8d789673eb.msvdn.net/embed/MfuWmzL2lGkA?autoplay=false&T=1635860445',
@@ -74,8 +73,8 @@ class MainStreamingIE(InfoExtractor):
                 'ext': 'mp4',
                 'live_status': 'not_live',
                 'thumbnail': r're:https?://[A-Za-z0-9-]*\.msvdn.net/image/\w+/poster',
-                'duration': 789.04
-            }
+                'duration': 789.04,
+            },
         }, {
             # always-on livestream with DVR
             'url': 'https://webtools-f5842579ff984c1c98d63b8d789673eb.msvdn.net/embed/HVvPMzy',
@@ -93,14 +92,14 @@ class MainStreamingIE(InfoExtractor):
         }, {
             # no host
             'url': 'https://webtools.msvdn.net/embed/MfuWmzL2lGkA',
-            'only_matching': True
+            'only_matching': True,
         }, {
             'url': 'https://859c1818ed614cc5b0047439470927b0.msvdn.net/amp_embed/tDoFkZD3T1Lw',
-            'only_matching': True
+            'only_matching': True,
         }, {
             'url': 'https://859c1818ed614cc5b0047439470927b0.msvdn.net/content/tDoFkZD3T1Lw#',
-            'only_matching': True
-        }
+            'only_matching': True,
+        },
     ]
 
     def _playlist_entries(self, host, playlist_content):
@@ -112,7 +111,7 @@ def _playlist_entries(self, host, playlist_content):
                 'id': content_id,
                 'duration': int_or_none(traverse_obj(entry, ('duration', 'totalSeconds'))),
                 'title': entry.get('title'),
-                'url': f'https://{host}/embed/{content_id}'
+                'url': f'https://{host}/embed/{content_id}',
             }
 
     @staticmethod
@@ -197,8 +196,6 @@ def _real_extract(self, url):
             subtitles = self._merge_subtitles(m3u8_subs, mpd_subs)
             formats.extend(m3u8_formats + mpd_formats)
 
-        self._sort_formats(formats)
-
         return {
             'id': video_id,
             'title': title,
@@ -208,5 +205,5 @@ def _real_extract(self, url):
             'duration': parse_duration(content_info.get('duration')),
             'tags': content_info.get('tags'),
             'subtitles': subtitles,
-            'thumbnail': urljoin(self._get_webtools_base_url(host), f'image/{video_id}/poster')
+            'thumbnail': urljoin(self._get_webtools_base_url(host), f'image/{video_id}/poster'),
         }