]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mlb.py
3 from .common
import InfoExtractor
13 class MLBBaseIE(InfoExtractor
):
14 def _real_extract(self
, url
):
15 display_id
= self
._match
_id
(url
)
16 video
= self
._download
_video
_data
(display_id
)
17 video_id
= video
['id']
18 title
= video
['title']
19 feed
= self
._get
_feed
(video
)
22 for playback
in (feed
.get('playbacks') or []):
23 playback_url
= playback
.get('url')
26 name
= playback
.get('name')
27 ext
= determine_ext(playback_url
)
29 formats
.extend(self
._extract
_m
3u8_formats
(
30 playback_url
, video_id
, 'mp4',
31 'm3u8_native', m3u8_id
=name
, fatal
=False))
37 mobj
= re
.search(r
'_(\d+)K_(\d+)X(\d+)', name
)
40 'height': int(mobj
.group(3)),
41 'tbr': int(mobj
.group(1)),
42 'width': int(mobj
.group(2)),
44 mobj
= re
.search(r
'_(\d+)x(\d+)_(\d+)_(\d+)K\.mp4', playback_url
)
47 'fps': int(mobj
.group(3)),
48 'height': int(mobj
.group(2)),
49 'tbr': int(mobj
.group(4)),
50 'width': int(mobj
.group(1)),
53 self
._sort
_formats
(formats
)
56 for cut
in (try_get(feed
, lambda x
: x
['image']['cuts'], list) or []):
61 'height': int_or_none(cut
.get('height')),
63 'width': int_or_none(cut
.get('width')),
66 language
= (video
.get('language') or 'EN').lower()
72 'description': video
.get('description'),
73 'duration': parse_duration(feed
.get('duration')),
74 'thumbnails': thumbnails
,
75 'timestamp': parse_iso8601(video
.get(self
._TIMESTAMP
_KEY
)),
76 'subtitles': self
._extract
_mlb
_subtitles
(feed
, language
),
80 class MLBIE(MLBBaseIE
):
83 (?:[\da-z_-]+\.)*mlb\.com/
86 (?:[^/]+/)*video/[^/]+/c-|
88 shared/video/embed/(?:embed|m-internal-embed)\.html|
89 (?:[^/]+/)+(?:play|index)\.jsp|
97 'url': 'https://www.mlb.com/mariners/video/ackleys-spectacular-catch/c-34698933',
98 'md5': '632358dacfceec06bad823b83d21df2d',
102 'title': "Ackley's spectacular catch",
103 'description': 'md5:7f5a981eb4f3cbc8daf2aeffa2215bf0',
105 'timestamp': 1405995000,
106 'upload_date': '20140722',
107 'thumbnail': r
're:^https?://.*\.jpg$',
111 'url': 'https://www.mlb.com/video/stanton-prepares-for-derby/c-34496663',
112 'md5': 'bf2619bf9cacc0a564fc35e6aeb9219f',
116 'title': 'Stanton prepares for Derby',
117 'description': 'md5:d00ce1e5fd9c9069e9c13ab4faedfa57',
119 'timestamp': 1405120200,
120 'upload_date': '20140711',
121 'thumbnail': r
're:^https?://.*\.jpg$',
125 'url': 'https://www.mlb.com/video/cespedes-repeats-as-derby-champ/c-34578115',
126 'md5': '99bb9176531adc600b90880fb8be9328',
130 'title': 'Cespedes repeats as Derby champ',
131 'description': 'md5:08df253ce265d4cf6fb09f581fafad07',
133 'timestamp': 1405414336,
134 'upload_date': '20140715',
135 'thumbnail': r
're:^https?://.*\.jpg$',
139 'url': 'https://www.mlb.com/video/bautista-on-home-run-derby/c-34577915',
140 'md5': 'da8b57a12b060e7663ee1eebd6f330ec',
144 'title': 'Bautista on Home Run Derby',
145 'description': 'md5:b80b34031143d0986dddc64a8839f0fb',
147 'timestamp': 1405405122,
148 'upload_date': '20140715',
149 'thumbnail': r
're:^https?://.*\.jpg$',
153 'url': 'https://www.mlb.com/video/hargrove-homers-off-caldwell/c-1352023483?tid=67793694',
154 'only_matching': True,
157 'url': 'http://m.mlb.com/shared/video/embed/embed.html?content_id=35692085&topic_id=6479266&width=400&height=224&property=mlb',
158 'only_matching': True,
161 'url': 'http://mlb.mlb.com/shared/video/embed/embed.html?content_id=36599553',
162 'only_matching': True,
165 'url': 'http://mlb.mlb.com/es/video/play.jsp?content_id=36599553',
166 'only_matching': True,
169 'url': 'https://www.mlb.com/cardinals/video/piscottys-great-sliding-catch/c-51175783',
170 'only_matching': True,
173 # From http://m.mlb.com/news/article/118550098/blue-jays-kevin-pillar-goes-spidey-up-the-wall-to-rob-tim-beckham-of-a-homer
174 'url': 'http://mlb.mlb.com/shared/video/embed/m-internal-embed.html?content_id=75609783&property=mlb&autoplay=true&hashmode=false&siteSection=mlb/multimedia/article_118550098/article_embed&club=mlb',
175 'only_matching': True,
178 _TIMESTAMP_KEY
= 'date'
181 def _get_feed(video
):
185 def _extract_mlb_subtitles(feed
, language
):
187 for keyword
in (feed
.get('keywordsAll') or []):
188 keyword_type
= keyword
.get('type')
189 if keyword_type
and keyword_type
.startswith('closed_captions_location_'):
190 cc_location
= keyword
.get('value')
192 subtitles
.setdefault(language
, []).append({
197 def _download_video_data(self
, display_id
):
198 return self
._download
_json
(
199 'http://content.mlb.com/mlb/item/id/v1/%s/details/web-v1.json' % display_id
,
203 class MLBVideoIE(MLBBaseIE
):
204 _VALID_URL
= r
'https?://(?:www\.)?mlb\.com/(?:[^/]+/)*video/(?P<id>[^/?&#]+)'
206 'url': 'https://www.mlb.com/mariners/video/ackley-s-spectacular-catch-c34698933',
207 'md5': '632358dacfceec06bad823b83d21df2d',
209 'id': 'c04a8863-f569-42e6-9f87-992393657614',
211 'title': "Ackley's spectacular catch",
212 'description': 'md5:7f5a981eb4f3cbc8daf2aeffa2215bf0',
214 'timestamp': 1405995000,
215 'upload_date': '20140722',
216 'thumbnail': r
're:^https?://.+',
219 _TIMESTAMP_KEY
= 'timestamp'
222 def suitable(cls
, url
):
223 return False if MLBIE
.suitable(url
) else super(MLBVideoIE
, cls
).suitable(url
)
226 def _get_feed(video
):
227 return video
['feeds'][0]
230 def _extract_mlb_subtitles(feed
, language
):
232 for cc_location
in (feed
.get('closedCaptions') or []):
233 subtitles
.setdefault(language
, []).append({
237 def _download_video_data(self
, display_id
):
238 # https://www.mlb.com/data-service/en/videos/[SLUG]
239 return self
._download
_json
(
240 'https://fastball-gateway.mlb.com/graphql',
243 mediaPlayback(ids: "%s") {
265 })['data']['mediaPlayback'][0]