]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/hrti.py
[ie/mlbtv] Fix extraction (#10296)
[yt-dlp.git] / yt_dlp / extractor / hrti.py
index 773ae0c9a7f0b84eafdb1d6e77cc8ced95bcb940..84e3867d34f02474197db6af5f4734fcf2ee18a8 100644 (file)
@@ -1,13 +1,13 @@
 import json
 
 from .common import InfoExtractor
-from ..compat import compat_HTTPError
+from ..networking import Request
+from ..networking.exceptions import HTTPError
 from ..utils import (
-    clean_html,
     ExtractorError,
+    clean_html,
     int_or_none,
     parse_age_limit,
-    sanitized_Request,
     try_get,
 )
 
@@ -28,21 +28,21 @@ class HRTiBaseIE(InfoExtractor):
 
     def _initialize_pre_login(self):
         init_data = {
-            'application_publication_id': self._APP_PUBLICATION_ID
+            'application_publication_id': self._APP_PUBLICATION_ID,
         }
 
         uuid = self._download_json(
             self._API_URL, None, note='Downloading uuid',
             errnote='Unable to download uuid',
-            data=json.dumps(init_data).encode('utf-8'))['uuid']
+            data=json.dumps(init_data).encode())['uuid']
 
         app_data = {
             'uuid': uuid,
             'application_publication_id': self._APP_PUBLICATION_ID,
-            'application_version': self._APP_VERSION
+            'application_version': self._APP_VERSION,
         }
 
-        req = sanitized_Request(self._API_URL, data=json.dumps(app_data).encode('utf-8'))
+        req = Request(self._API_URL, data=json.dumps(app_data).encode())
         req.get_method = lambda: 'PUT'
 
         resources = self._download_json(
@@ -71,17 +71,17 @@ def _perform_login(self, username, password):
         try:
             auth_info = self._download_json(
                 self._login_url, None, note='Logging in', errnote='Unable to log in',
-                data=json.dumps(auth_data).encode('utf-8'))
+                data=json.dumps(auth_data).encode())
         except ExtractorError as e:
-            if isinstance(e.cause, compat_HTTPError) and e.cause.code == 406:
-                auth_info = self._parse_json(e.cause.read().encode('utf-8'), None)
+            if isinstance(e.cause, HTTPError) and e.cause.status == 406:
+                auth_info = self._parse_json(e.cause.response.read().encode(), None)
             else:
                 raise
 
         error_message = auth_info.get('error', {}).get('message')
         if error_message:
             raise ExtractorError(
-                '%s said: %s' % (self.IE_NAME, error_message),
+                f'{self.IE_NAME} said: {error_message}',
                 expected=True)
 
         self._token = auth_info['secure_streaming_token']
@@ -133,7 +133,7 @@ def _real_extract(self, url):
         display_id = mobj.group('display_id') or video_id
 
         video = self._download_json(
-            '%s/video_id/%s/format/json' % (self._search_url, video_id),
+            f'{self._search_url}/video_id/{video_id}/format/json',
             display_id, 'Downloading video metadata JSON')['video'][0]
 
         title_info = video['title']
@@ -144,7 +144,6 @@ def _real_extract(self, url):
         formats = self._extract_m3u8_formats(
             m3u8_url, display_id, 'mp4', entry_protocol='m3u8_native',
             m3u8_id='hls')
-        self._sort_formats(formats)
 
         description = clean_html(title_info.get('summary_long'))
         age_limit = parse_age_limit(video.get('parental_control', {}).get('rating'))
@@ -189,13 +188,13 @@ def _real_extract(self, url):
         display_id = mobj.group('display_id') or category_id
 
         response = self._download_json(
-            '%s/category_id/%s/format/json' % (self._search_url, category_id),
+            f'{self._search_url}/category_id/{category_id}/format/json',
             display_id, 'Downloading video metadata JSON')
 
         video_ids = try_get(
             response, lambda x: x['video_listings'][0]['alternatives'][0]['list'],
             list) or [video['id'] for video in response.get('videos', []) if video.get('id')]
 
-        entries = [self.url_result('hrti:%s' % video_id) for video_id in video_ids]
+        entries = [self.url_result(f'hrti:{video_id}') for video_id in video_ids]
 
         return self.playlist_result(entries, category_id, display_id)