summaryrefslogtreecommitdiffstats
path: root/yt_dlp/extractor/mlb.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--yt_dlp/extractor/mlb.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/yt_dlp/extractor/mlb.py b/yt_dlp/extractor/mlb.py
index d715b97..6f67602 100644
--- a/yt_dlp/extractor/mlb.py
+++ b/yt_dlp/extractor/mlb.py
@@ -9,9 +9,10 @@ from ..utils import (
join_nonempty,
parse_duration,
parse_iso8601,
- traverse_obj,
try_get,
+ url_or_none,
)
+from ..utils.traversal import traverse_obj
class MLBBaseIE(InfoExtractor):
@@ -203,7 +204,7 @@ class MLBIE(MLBBaseIE):
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)
@@ -227,7 +228,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):
@@ -268,7 +269,7 @@ class MLBVideoIE(MLBBaseIE):
timestamp
title
}
-}''' % display_id,
+}''' % display_id, # noqa: UP031
})['data']['mediaPlayback'][0]
@@ -300,14 +301,14 @@ class MLBTVIE(InfoExtractor):
'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'
@@ -316,7 +317,7 @@ class MLBTVIE(InfoExtractor):
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):
@@ -326,15 +327,20 @@ class MLBTVIE(InfoExtractor):
video_id)['data']['Airings']
formats, subtitles = [], {}
- for airing in airings:
- m3u8_url = self._download_json(
+ for airing in traverse_obj(airings, lambda _, v: v['playbackUrls'][0]['href']):
+ format_id = join_nonempty('feedType', 'feedLanguage', from_dict=airing)
+ m3u8_url = traverse_obj(self._download_json(
airing['playbackUrls'][0]['href'].format(scenario='browser~csai'), video_id,
- headers={
+ note=f'Downloading {format_id} stream info JSON',
+ errnote=f'Failed to download {format_id} stream info, skipping',
+ fatal=False, headers={
'Authorization': self._access_token,
- 'Accept': 'application/vnd.media-service+json; version=2'
- })['stream']['complete']
+ 'Accept': 'application/vnd.media-service+json; version=2',
+ }), ('stream', 'complete', {url_or_none}))
+ if not m3u8_url:
+ continue
f, s = self._extract_m3u8_formats_and_subtitles(
- m3u8_url, video_id, 'mp4', m3u8_id=join_nonempty(airing.get('feedType'), airing.get('feedLanguage')))
+ m3u8_url, video_id, 'mp4', m3u8_id=format_id, fatal=False)
formats.extend(f)
self._merge_subtitles(s, target=subtitles)