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 video_id to find the Media detail XML
33 id_len = len(video_id)
34 _mediadetail_url = 'http://m.mlb.com/gen/multimedia/detail/'+video_id[id_len-3]+'/'+video_id[id_len-2]+'/'+video_id[id_len-1]+'/'+video_id+'.xml'
36 mediadetails = self._download_xml(_mediadetail_url, video_id, "Downloading media detail...")
40 # loop through the list of url's and only get the highest quality MP4 content
41 for element in mediadetails.findall('url'):
42 scenario = element.attrib['playback_scenario']
43 if scenario.startswith(u'FLASH'):
44 if scenario.startswith(u'FLASH_1800K'):
45 video_url = element.text
46 # 1800K is the current highest quality video on MLB.com
49 if scenario.startswith(u'FLASH_1500K'):
50 video_url = element.text
53 if (scenario.startswith(u'FLASH_1200K') and not has1500K):
54 video_url = element.text
57 if (scenario.startswith(u'FLASH_600K') and not has1200K):
58 video_url = element.text
61 if (scenario.startswith(u'FLASH_300K') and not has600K):
62 video_url = element.text
72 'description': description,
73 'thumbnail': thumbnail,