[BlipTVIE] Extract all available formats and fix direct download

This commit is contained in:
rzhxeo 2013-12-17 21:39:09 +01:00
parent 8b4e274610
commit bf5700e2cf

View File

@ -15,6 +15,7 @@ from ..utils import (
ExtractorError, ExtractorError,
unescapeHTML, unescapeHTML,
determine_ext,
) )
@ -36,6 +37,13 @@ class BlipTVIE(InfoExtractor):
} }
} }
_format_ids = {
'Source': 'src',
'Blip LD': 'ld',
'Blip SD': 'sd',
'Blip HD 720': 'hd'
}
def report_direct_download(self, title): def report_direct_download(self, title):
"""Report information extraction.""" """Report information extraction."""
self.to_screen(u'%s: Direct download detected' % title) self.to_screen(u'%s: Direct download detected' % title)
@ -73,19 +81,19 @@ class BlipTVIE(InfoExtractor):
if urlh.headers.get('Content-Type', '').startswith('video/'): # Direct download if urlh.headers.get('Content-Type', '').startswith('video/'): # Direct download
basename = url.split('/')[-1] basename = url.split('/')[-1]
title,ext = os.path.splitext(basename) title,ext = os.path.splitext(basename)
title = title.decode('UTF-8')
ext = ext.replace('.', '') ext = ext.replace('.', '')
self.report_direct_download(title) self.report_direct_download(title)
info = { return {
'id': title, 'id': title,
'url': url,
'uploader': None,
'upload_date': None,
'title': title, 'title': title,
'user_agent': 'iTunes/10.6.1',
'formats': [{
'format_id': 'unk',
'url': url,
'ext': ext, 'ext': ext,
'urlhandle': urlh }]
} }
if info is None: # Regular URL
try: try:
json_code_bytes = urlh.read() json_code_bytes = urlh.read()
json_code = json_code_bytes.decode('utf-8') json_code = json_code_bytes.decode('utf-8')
@ -100,36 +108,41 @@ class BlipTVIE(InfoExtractor):
data = json_data data = json_data
upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d') upload_date = datetime.datetime.strptime(data['datestamp'], '%m-%d-%y %H:%M%p').strftime('%Y%m%d')
formats = []
if 'additionalMedia' in data: if 'additionalMedia' in data:
formats = sorted(data['additionalMedia'], key=lambda f: int(f['media_height'])) for raw_format in sorted(data['additionalMedia'], key=lambda f: int(f['media_height'])):
best_format = formats[-1] if raw_format['media_width'] == '0': # filter m3u8
video_url = best_format['url'] continue
formats.append({
'url': raw_format['url'],
'ext': determine_ext(raw_format['url']),
'format_note': raw_format['role'],
'format_id': self._format_ids.get(raw_format['role'], raw_format['role']),
'width': raw_format['media_width'],
'height': raw_format['media_height'],
})
else: else:
video_url = data['media']['url'] formats.append({
umobj = re.match(self._URL_EXT, video_url) 'url': data['media']['url'],
if umobj is None: 'ext': determine_ext(data['media']['url']),
raise ValueError('Can not determine filename extension') 'format_id': 'unk',
ext = umobj.group(1) 'width': data['media']['width'],
'height': data['media']['height'],
})
info = { return {
'id': compat_str(data['item_id']), 'id': compat_str(data['item_id']),
'url': video_url,
'uploader': data['display_name'], 'uploader': data['display_name'],
'upload_date': upload_date, 'upload_date': upload_date,
'title': data['title'], 'title': data['title'],
'ext': ext,
'format': data['media']['mimeType'],
'thumbnail': data['thumbnailUrl'], 'thumbnail': data['thumbnailUrl'],
'description': data['description'], 'description': data['description'],
'player_url': data['embedUrl'],
'user_agent': 'iTunes/10.6.1', 'user_agent': 'iTunes/10.6.1',
'formats': formats
} }
except (ValueError,KeyError) as err: except (ValueError,KeyError) as err:
raise ExtractorError(u'Unable to parse video information: %s' % repr(err)) raise ExtractorError(u'Unable to parse video information: %s' % repr(err))
return [info]
class BlipTVUserIE(InfoExtractor): class BlipTVUserIE(InfoExtractor):
"""Information Extractor for blip.tv users.""" """Information Extractor for blip.tv users."""