[sohu] fix multipart formats extraction

This commit is contained in:
remitamine 2016-01-15 01:25:33 +01:00
parent 3f97d9fd59
commit c56621f173

View File

@ -11,6 +11,7 @@ from ..compat import (
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
sanitized_Request, sanitized_Request,
int_or_none,
) )
@ -127,6 +128,7 @@ class SohuIE(InfoExtractor):
raise ExtractorError( raise ExtractorError(
'Sohu said: The video is only licensed to users in Mainland China.', 'Sohu said: The video is only licensed to users in Mainland China.',
expected=True) expected=True)
vid = compat_str(vid_data['id'])
formats_json = {} formats_json = {}
for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'): for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
@ -136,18 +138,12 @@ class SohuIE(InfoExtractor):
vid_id = compat_str(vid_id) vid_id = compat_str(vid_id)
formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv) formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
part_count = vid_data['data']['totalBlocks'] formats = []
for format_id, format_data in formats_json.items():
playlist = [] data = format_data['data']
for i in range(part_count): part_count = data['totalBlocks']
formats = [] parts = []
for format_id, format_data in formats_json.items(): for i in range(part_count):
allot = format_data['allot']
data = format_data['data']
clips_url = data['clipsURL']
su = data['su']
video_url = 'newflv.sohu.ccgslb.net' video_url = 'newflv.sohu.ccgslb.net'
cdnId = None cdnId = None
retries = 0 retries = 0
@ -155,8 +151,8 @@ class SohuIE(InfoExtractor):
while 'newflv.sohu.ccgslb.net' in video_url: while 'newflv.sohu.ccgslb.net' in video_url:
params = { params = {
'prot': 9, 'prot': 9,
'file': clips_url[i], 'file': data['clipsURL'][i],
'new': su[i], 'new': data['su'][i],
'prod': 'flash', 'prod': 'flash',
'rb': 1, 'rb': 1,
} }
@ -170,7 +166,7 @@ class SohuIE(InfoExtractor):
if retries > 0: if retries > 0:
download_note += ' (retry #%d)' % retries download_note += ' (retry #%d)' % retries
part_info = self._parse_json(self._download_webpage( part_info = self._parse_json(self._download_webpage(
'http://%s/?%s' % (allot, compat_urllib_parse.urlencode(params)), 'http://%s/?%s' % (format_data['allot'], compat_urllib_parse.urlencode(params)),
video_id, download_note), video_id) video_id, download_note), video_id)
video_url = part_info['url'] video_url = part_info['url']
@ -180,32 +176,22 @@ class SohuIE(InfoExtractor):
if retries > 5: if retries > 5:
raise ExtractorError('Failed to get video URL') raise ExtractorError('Failed to get video URL')
formats.append({ parts.append({
'url': video_url, 'url': video_url,
'format_id': format_id, 'duration': int_or_none(vid_data['data']['clipsDuration'][i]),
'filesize': data['clipsBytes'][i], 'filesize': int_or_none(data['clipsBytes'][i]),
'width': data['width'],
'height': data['height'],
'fps': data['fps'],
}) })
self._sort_formats(formats) formats.append({
'format_id': format_id,
playlist.append({ 'parts': parts,
'id': '%s_part%d' % (video_id, i + 1), 'width': int_or_none(data['width']),
'title': title, 'height': int_or_none(data['height']),
'duration': vid_data['data']['clipsDuration'][i], 'fps': int_or_none(data['fps']),
'formats': formats,
}) })
self._sort_formats(formats)
if len(playlist) == 1: return {
info = playlist[0] 'id': video_id,
info['id'] = video_id 'title': title,
else: 'formats': formats,
info = { }
'_type': 'multi_video',
'entries': playlist,
'id': video_id,
'title': title,
}
return info