]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/wimtv.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / wimtv.py
index d7d77c0db0c06344ab4c5bf95945f4de928e0b1e..000d1437f00c6cf7946d2789fe225256b3be53bf 100644 (file)
 class WimTVIE(InfoExtractor):
     _player = None
     _UUID_RE = r'[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}'
-    _VALID_URL = r'''(?x:
+    _VALID_URL = rf'''(?x:
         https?://platform\.wim\.tv/
         (?:
             (?:embed/)?\?
             |\#/webtv/.+?/
         )
         (?P<type>vod|live|cast)[=/]
-        (?P<id>%s).*?)''' % _UUID_RE
+        (?P<id>{_UUID_RE}).*?)'''
     _EMBED_REGEX = [rf'<iframe[^>]+src=["\'](?P<url>{_VALID_URL})']
     _TESTS = [{
         # vod stream
@@ -28,7 +28,7 @@ class WimTVIE(InfoExtractor):
             'ext': 'mp4',
             'title': 'AMA SUPERCROSS 2020 - R2 ST. LOUIS',
             'duration': 6481,
-            'thumbnail': r're:https?://.+?/thumbnail/.+?/720$'
+            'thumbnail': r're:https?://.+?/thumbnail/.+?/720$',
         },
         'params': {
             'skip_download': True,
@@ -66,7 +66,7 @@ def _get_player_data(self):
             'vars': [{
                 'regex': r'appAuth = "(.+?)"',
                 'variable': 'app_auth',
-            }]
+            }],
         }, {
             'url': 'https://platform.wim.tv/common/config/endpointconfig.js',
             'vars': [{
@@ -75,7 +75,7 @@ def _get_player_data(self):
             }, {
                 'regex': r'PRODUCTION_HOSTNAME_THUMB\s*\+\s*"(.+?)"',
                 'variable': 'thumb_server_path',
-            }]
+            }],
         }]
 
         for data in datas:
@@ -83,13 +83,13 @@ def _get_player_data(self):
             for var in data['vars']:
                 val = self._search_regex(var['regex'], temp, msg_id)
                 if not val:
-                    raise ExtractorError('%s not found' % var['variable'])
+                    raise ExtractorError('{} not found'.format(var['variable']))
                 self._player[var['variable']] = val
 
     def _generate_token(self):
         json = self._download_json(
             'https://platform.wim.tv/wimtv-server/oauth/token', 'Token generation',
-            headers={'Authorization': 'Basic %s' % self._player['app_auth']},
+            headers={'Authorization': 'Basic {}'.format(self._player['app_auth'])},
             data=urlencode_postdata({'grant_type': 'client_credentials'}))
         token = json.get('access_token')
         if not token:
@@ -101,7 +101,7 @@ def _generate_thumbnail(self, thumb_id, width='720'):
             return None
         if not self._player.get('thumb_server_path'):
             self._player['thumb_server_path'] = ''
-        return '%s%s/asset/thumbnail/%s/%s' % (
+        return '{}{}/asset/thumbnail/{}/{}'.format(
             self._player['thumb_server'],
             self._player['thumb_server_path'],
             thumb_id, width)
@@ -118,11 +118,11 @@ def _real_extract(self, url):
             is_live = False
         token = self._generate_token()
         json = self._download_json(
-            'https://platform.wim.tv/wimtv-server/api/public/%s/%s/play' % (
-                stream_type, video_id), video_id,
-            headers={'Authorization': 'Bearer %s' % token,
-                     'Content-Type': 'application/json'},
-            data=bytes('{}', 'utf-8'))
+            f'https://platform.wim.tv/wimtv-server/api/public/{stream_type}/{video_id}/play',
+            video_id, headers={
+                'Authorization': f'Bearer {token}',
+                'Content-Type': 'application/json',
+            }, data=b'{}')
 
         formats = []
         for src in json.get('srcs') or []: