1 from __future__ import unicode_literals
5 from .common import InfoExtractor
8 class MlbIE(InfoExtractor):
9 _VALID_URL = r'http?://m\.mlb\.com/video/topic/[0-9]+/v(?P<id>n?\d+)/.*$'
11 'url': 'http://m.mlb.com/video/topic/81536970/v34496663/mianym-stanton-practices-for-the-home-run-derby',
12 'md5': u'd9c022c10d21f849f49c05ae12a8a7e9',
17 'description': "7/11/14: Giancarlo Stanton practices for the Home Run Derby prior to the game against the Mets",
18 'title': "Stanton prepares for Derby",
22 def _real_extract(self, url):
23 mobj = re.match(self._VALID_URL, url)
24 video_id = mobj.group('id')
26 webpage = self._download_webpage(url, video_id)
28 title = self._og_search_title(webpage, default=video_id)
29 description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)"/>', webpage, 'description', fatal=False)
30 thumbnail = self._html_search_regex(r'<meta itemprop="image" (?:content|value)="(.*?)" />', webpage, 'image', fatal=False)
32 # use the thumbnail URL to find the folder that contains the videos
33 _image_url = r'http://mediadownloads.mlb.com/mlbam/(?P<_date>n?.+)/images/.*$'
34 bobj = re.match(_image_url, thumbnail)
35 datestr = bobj.group('_date')
36 base_url = 'http://mediadownloads.mlb.com/mlbam/' + datestr
37 filespage = self._download_webpage(base_url, video_id)
39 # Try 1800K, 1500K, 1200K, 600K, then 300K videos
40 video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_1800K.mp4"', filespage, '1800K', fatal=False)
42 video_url = base_url+'/'+video+'_'+video_id+'_1800K.mp4'
44 video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_1500K.mp4"', filespage, '1500K', fatal=False)
46 video_url = base_url+'/'+video+'_'+video_id+'_1500K.mp4'
48 video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_600K.mp4"', filespage, '600K', fatal=False)
50 video_url = base_url+'/'+video+'_'+video_id+'_600K.mp4'
52 video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_300K.mp4"', filespage, 'MLB', fatal=False)
54 video_url = base_url+'/'+video+'_'+video_id+'_300K.mp4'
56 # nothing valuable to return
65 'description': description,
66 'thumbnail': thumbnail,