]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mlb.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 class MLBBaseIE(InfoExtractor
):
16 def _real_extract(self
, url
):
17 display_id
= self
._match
_id
(url
)
18 video
= self
._download
_video
_data
(display_id
)
19 video_id
= video
['id']
20 title
= video
['title']
21 feed
= self
._get
_feed
(video
)
24 for playback
in (feed
.get('playbacks') or []):
25 playback_url
= playback
.get('url')
28 name
= playback
.get('name')
29 ext
= determine_ext(playback_url
)
31 formats
.extend(self
._extract
_m
3u8_formats
(
32 playback_url
, video_id
, 'mp4',
33 'm3u8_native', m3u8_id
=name
, fatal
=False))
39 mobj
= re
.search(r
'_(\d+)K_(\d+)X(\d+)', name
)
42 'height': int(mobj
.group(3)),
43 'tbr': int(mobj
.group(1)),
44 'width': int(mobj
.group(2)),
46 mobj
= re
.search(r
'_(\d+)x(\d+)_(\d+)_(\d+)K\.mp4', playback_url
)
49 'fps': int(mobj
.group(3)),
50 'height': int(mobj
.group(2)),
51 'tbr': int(mobj
.group(4)),
52 'width': int(mobj
.group(1)),
55 self
._sort
_formats
(formats
)
58 for cut
in (try_get(feed
, lambda x
: x
['image']['cuts'], list) or []):
63 'height': int_or_none(cut
.get('height')),
65 'width': int_or_none(cut
.get('width')),
68 language
= (video
.get('language') or 'EN').lower()
74 'description': video
.get('description'),
75 'duration': parse_duration(feed
.get('duration')),
76 'thumbnails': thumbnails
,
77 'timestamp': parse_iso8601(video
.get(self
._TIMESTAMP
_KEY
)),
78 'subtitles': self
._extract
_mlb
_subtitles
(feed
, language
),
82 class MLBIE(MLBBaseIE
):
85 (?:[\da-z_-]+\.)*mlb\.com/
88 (?:[^/]+/)*video/[^/]+/c-|
90 shared/video/embed/(?:embed|m-internal-embed)\.html|
91 (?:[^/]+/)+(?:play|index)\.jsp|
99 'url': 'https://www.mlb.com/mariners/video/ackleys-spectacular-catch/c-34698933',
100 'md5': '632358dacfceec06bad823b83d21df2d',
104 'title': "Ackley's spectacular catch",
105 'description': 'md5:7f5a981eb4f3cbc8daf2aeffa2215bf0',
107 'timestamp': 1405995000,
108 'upload_date': '20140722',
109 'thumbnail': r
're:^https?://.*\.jpg$',
113 'url': 'https://www.mlb.com/video/stanton-prepares-for-derby/c-34496663',
114 'md5': 'bf2619bf9cacc0a564fc35e6aeb9219f',
118 'title': 'Stanton prepares for Derby',
119 'description': 'md5:d00ce1e5fd9c9069e9c13ab4faedfa57',
121 'timestamp': 1405120200,
122 'upload_date': '20140711',
123 'thumbnail': r
're:^https?://.*\.jpg$',
127 'url': 'https://www.mlb.com/video/cespedes-repeats-as-derby-champ/c-34578115',
128 'md5': '99bb9176531adc600b90880fb8be9328',
132 'title': 'Cespedes repeats as Derby champ',
133 'description': 'md5:08df253ce265d4cf6fb09f581fafad07',
135 'timestamp': 1405414336,
136 'upload_date': '20140715',
137 'thumbnail': r
're:^https?://.*\.jpg$',
141 'url': 'https://www.mlb.com/video/bautista-on-home-run-derby/c-34577915',
142 'md5': 'da8b57a12b060e7663ee1eebd6f330ec',
146 'title': 'Bautista on Home Run Derby',
147 'description': 'md5:b80b34031143d0986dddc64a8839f0fb',
149 'timestamp': 1405405122,
150 'upload_date': '20140715',
151 'thumbnail': r
're:^https?://.*\.jpg$',
155 'url': 'https://www.mlb.com/video/hargrove-homers-off-caldwell/c-1352023483?tid=67793694',
156 'only_matching': True,
159 'url': 'http://m.mlb.com/shared/video/embed/embed.html?content_id=35692085&topic_id=6479266&width=400&height=224&property=mlb',
160 'only_matching': True,
163 'url': 'http://mlb.mlb.com/shared/video/embed/embed.html?content_id=36599553',
164 'only_matching': True,
167 'url': 'http://mlb.mlb.com/es/video/play.jsp?content_id=36599553',
168 'only_matching': True,
171 'url': 'https://www.mlb.com/cardinals/video/piscottys-great-sliding-catch/c-51175783',
172 'only_matching': True,
175 # From http://m.mlb.com/news/article/118550098/blue-jays-kevin-pillar-goes-spidey-up-the-wall-to-rob-tim-beckham-of-a-homer
176 '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',
177 'only_matching': True,
180 _TIMESTAMP_KEY
= 'date'
183 def _get_feed(video
):
187 def _extract_mlb_subtitles(feed
, language
):
189 for keyword
in (feed
.get('keywordsAll') or []):
190 keyword_type
= keyword
.get('type')
191 if keyword_type
and keyword_type
.startswith('closed_captions_location_'):
192 cc_location
= keyword
.get('value')
194 subtitles
.setdefault(language
, []).append({
199 def _download_video_data(self
, display_id
):
200 return self
._download
_json
(
201 'http://content.mlb.com/mlb/item/id/v1/%s/details/web-v1.json' % display_id
,
205 class MLBVideoIE(MLBBaseIE
):
206 _VALID_URL
= r
'https?://(?:www\.)?mlb\.com/(?:[^/]+/)*video/(?P<id>[^/?&#]+)'
208 'url': 'https://www.mlb.com/mariners/video/ackley-s-spectacular-catch-c34698933',
209 'md5': '632358dacfceec06bad823b83d21df2d',
211 'id': 'c04a8863-f569-42e6-9f87-992393657614',
213 'title': "Ackley's spectacular catch",
214 'description': 'md5:7f5a981eb4f3cbc8daf2aeffa2215bf0',
216 'timestamp': 1405995000,
217 'upload_date': '20140722',
218 'thumbnail': r
're:^https?://.+',
221 _TIMESTAMP_KEY
= 'timestamp'
224 def suitable(cls
, url
):
225 return False if MLBIE
.suitable(url
) else super(MLBVideoIE
, cls
).suitable(url
)
228 def _get_feed(video
):
229 return video
['feeds'][0]
232 def _extract_mlb_subtitles(feed
, language
):
234 for cc_location
in (feed
.get('closedCaptions') or []):
235 subtitles
.setdefault(language
, []).append({
239 def _download_video_data(self
, display_id
):
240 # https://www.mlb.com/data-service/en/videos/[SLUG]
241 return self
._download
_json
(
242 'https://fastball-gateway.mlb.com/graphql',
245 mediaPlayback(ids: "%s") {
267 })['data']['mediaPlayback'][0]