]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/mlb.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / mlb.py
index 2f0f2deabcee0ebdfb3fc808aeb1dc8b2c43b728..8a693dc0be6a050b1fa4ffd5759f1d995583d307 100644 (file)
@@ -54,7 +54,6 @@ def _real_extract(self, url):
                         'width': int(mobj.group(1)),
                     })
                 formats.append(f)
-        self._sort_formats(formats)
 
         thumbnails = []
         for cut in (try_get(feed, lambda x: x['image']['cuts'], list) or []):
@@ -204,7 +203,7 @@ def _extract_mlb_subtitles(feed, language):
 
     def _download_video_data(self, display_id):
         return self._download_json(
-            'http://content.mlb.com/mlb/item/id/v1/%s/details/web-v1.json' % display_id,
+            f'http://content.mlb.com/mlb/item/id/v1/{display_id}/details/web-v1.json',
             display_id)
 
 
@@ -228,7 +227,7 @@ class MLBVideoIE(MLBBaseIE):
 
     @classmethod
     def suitable(cls, url):
-        return False if MLBIE.suitable(url) else super(MLBVideoIE, cls).suitable(url)
+        return False if MLBIE.suitable(url) else super().suitable(url)
 
     @staticmethod
     def _get_feed(video):
@@ -269,7 +268,7 @@ def _download_video_data(self, display_id):
     timestamp
     title
   }
-}''' % display_id,
+}''' % display_id,  # noqa: UP031
             })['data']['mediaPlayback'][0]
 
 
@@ -301,14 +300,14 @@ def _perform_login(self, username, password):
             'https://ids.mlb.com/oauth2/aus1m088yK07noBfh356/v1/token', None,
             headers={
                 'User-Agent': 'okhttp/3.12.1',
-                'Content-Type': 'application/x-www-form-urlencoded'
+                'Content-Type': 'application/x-www-form-urlencoded',
             }, data=data.encode())['access_token']
 
         entitlement = self._download_webpage(
-            f'https://media-entitlement.mlb.com/api/v3/jwt?os=Android&appname=AtBat&did={str(uuid.uuid4())}', None,
+            f'https://media-entitlement.mlb.com/api/v3/jwt?os=Android&appname=AtBat&did={uuid.uuid4()}', None,
             headers={
                 'User-Agent': 'okhttp/3.12.1',
-                'Authorization': f'Bearer {access_token}'
+                'Authorization': f'Bearer {access_token}',
             })
 
         data = f'grant_type=urn:ietf:params:oauth:grant-type:token-exchange&subject_token={entitlement}&subject_token_type=urn:ietf:params:oauth:token-type:jwt&platform=android-tv'
@@ -317,7 +316,7 @@ def _perform_login(self, username, password):
             headers={
                 'Accept': 'application/json',
                 'Authorization': 'Bearer bWxidHYmYW5kcm9pZCYxLjAuMA.6LZMbH2r--rbXcgEabaDdIslpo4RyZrlVfWZhsAgXIk',
-                'Content-Type': 'application/x-www-form-urlencoded'
+                'Content-Type': 'application/x-www-form-urlencoded',
             }, data=data.encode())['access_token']
 
     def _real_extract(self, url):
@@ -332,14 +331,13 @@ def _real_extract(self, url):
                 airing['playbackUrls'][0]['href'].format(scenario='browser~csai'), video_id,
                 headers={
                     'Authorization': self._access_token,
-                    'Accept': 'application/vnd.media-service+json; version=2'
+                    'Accept': 'application/vnd.media-service+json; version=2',
                 })['stream']['complete']
             f, s = self._extract_m3u8_formats_and_subtitles(
                 m3u8_url, video_id, 'mp4', m3u8_id=join_nonempty(airing.get('feedType'), airing.get('feedLanguage')))
             formats.extend(f)
             self._merge_subtitles(s, target=subtitles)
 
-        self._sort_formats(formats)
         return {
             'id': video_id,
             'title': traverse_obj(airings, (..., 'titles', 0, 'episodeName'), get_all=False),
@@ -357,11 +355,11 @@ class MLBArticleIE(InfoExtractor):
         'info_dict': {
             'id': '36db7394-343c-4ea3-b8ca-ead2e61bca9a',
             'title': 'Machado\'s grab draws hilarious irate reaction',
-            'modified_timestamp': 1650130737,
+            'modified_timestamp': 1675888370,
             'description': 'md5:a19d4eb0487b2cb304e9a176f6b67676',
-            'modified_date': '20220416',
+            'modified_date': '20230208',
         },
-        'playlist_count': 2,
+        'playlist_mincount': 2,
     }]
 
     def _real_extract(self, url):
@@ -369,15 +367,13 @@ def _real_extract(self, url):
         webpage = self._download_webpage(url, display_id)
         apollo_cache_json = self._search_json(r'window\.initState\s*=', webpage, 'window.initState', display_id)['apolloCache']
 
-        content_data_id = traverse_obj(
-            apollo_cache_json, ('ROOT_QUERY', lambda k, _: k.startswith('getForgeContent'), 'id'), get_all=False)
-
-        content_real_info = apollo_cache_json[content_data_id]
+        content_real_info = traverse_obj(
+            apollo_cache_json, ('ROOT_QUERY', lambda k, _: k.startswith('getArticle')), get_all=False)
 
         return self.playlist_from_matches(
-            traverse_obj(content_real_info, ('parts', lambda _, v: v['typename'] == 'Video', 'id')),
-            getter=lambda x: f'https://www.mlb.com/video/{apollo_cache_json[x]["slug"]}',
-            ie=MLBVideoIE, playlist_id=content_real_info.get('_translationId'),
+            traverse_obj(content_real_info, ('parts', lambda _, v: v['__typename'] == 'Video' or v['type'] == 'video')),
+            getter=lambda x: f'https://www.mlb.com/video/{x["slug"]}',
+            ie=MLBVideoIE, playlist_id=content_real_info.get('translationId'),
             title=self._html_search_meta('og:title', webpage),
             description=content_real_info.get('summary'),
             modified_timestamp=parse_iso8601(content_real_info.get('lastUpdatedDate')))