Switched to use media detail XML to extract video URL

This commit is contained in:
Charles Chen 2014-07-15 13:55:23 -07:00
parent b1b01841af
commit 172240c0a4
1 changed files with 32 additions and 25 deletions

View File

@ -29,36 +29,43 @@ class MlbIE(InfoExtractor):
description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)"/>', webpage, 'description', fatal=False) description = self._html_search_regex(r'<meta name="description" (?:content|value)="(.*?)"/>', webpage, 'description', fatal=False)
thumbnail = self._html_search_regex(r'<meta itemprop="image" (?:content|value)="(.*?)" />', webpage, 'image', fatal=False) thumbnail = self._html_search_regex(r'<meta itemprop="image" (?:content|value)="(.*?)" />', webpage, 'image', fatal=False)
# use the thumbnail URL to find the folder that contains the videos # use the video_id to find the Media detail XML
_image_url = r'http://mediadownloads.mlb.com/mlbam/(?P<_date>n?.+)/images/.*$' id_len = len(video_id)
bobj = re.match(_image_url, thumbnail) _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'
datestr = bobj.group('_date')
base_url = 'http://mediadownloads.mlb.com/mlbam/' + datestr
filespage = self._download_webpage(base_url, video_id)
# Try 1800K, 1500K, 1200K, 600K, then 300K videos mediadetails = self._download_xml(_mediadetail_url, video_id, "Downloading media detail...")
video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_1800K.mp4"', filespage, '1800K', fatal=False) has1500K = 0
if video is not None: has1200K = 0
video_url = base_url+'/'+video+'_'+video_id+'_1800K.mp4' has600K = 0
else: # loop through the list of url's and only get the highest quality MP4 content
video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_1500K.mp4"', filespage, '1500K', fatal=False) for element in mediadetails.findall('url'):
if video is not None: scenario = element.attrib['playback_scenario']
video_url = base_url+'/'+video+'_'+video_id+'_1500K.mp4' if scenario.startswith(u'FLASH'):
else: if scenario.startswith(u'FLASH_1800K'):
video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_600K.mp4"', filespage, '600K', fatal=False) video_url = element.text
if video is not None: # 1800K is the current highest quality video on MLB.com
video_url = base_url+'/'+video+'_'+video_id+'_600K.mp4' break
else: else:
video = self._html_search_regex(r'<li><a href="(.*?)_'+video_id+'_300K.mp4"', filespage, 'MLB', fatal=False) if scenario.startswith(u'FLASH_1500K'):
if video is not None: video_url = element.text
video_url = base_url+'/'+video+'_'+video_id+'_300K.mp4' has1500K = 1
else: else:
# nothing valuable to return if (scenario.startswith(u'FLASH_1200K') and not has1500K):
return None video_url = element.text
has1200K = 1
else:
if (scenario.startswith(u'FLASH_600K') and not has1200K):
video_url = element.text
has600K = 1
else:
if (scenario.startswith(u'FLASH_300K') and not has600K):
video_url = element.text
return { return {
'id': video_id, 'id': video_id,
'url': video_url, 'url': video_url,
'extractor': 'mlb',
'webpage_url': url,
'title': title, 'title': title,
'ext': 'mp4', 'ext': 'mp4',
'format': 'mp4', 'format': 'mp4',