6 from .common import InfoExtractor
7 from ..utils import ExtractorError
10 class SohuIE(InfoExtractor):
11 _VALID_URL = r'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
14 u'url': u'http://tv.sohu.com/20130724/n382479172.shtml#super',
15 u'file': u'382479172.mp4',
16 u'md5': u'bde8d9a6ffd82c63a1eefaef4eeefec7',
18 u'title': u'MV:Far East Movement《The Illest》',
20 u'skip': u'Only available from China',
23 def _real_extract(self, url):
25 def _fetch_data(vid_id, mytv=False):
27 base_data_url = 'http://my.tv.sohu.com/play/videonew.do?vid='
29 base_data_url = u'http://hot.vrs.sohu.com/vrs_flash.action?vid='
30 data_url = base_data_url + str(vid_id)
31 data_json = self._download_webpage(
33 note=u'Downloading JSON data for ' + str(vid_id))
34 return json.loads(data_json)
36 mobj = re.match(self._VALID_URL, url)
37 video_id = mobj.group('id')
38 mytv = mobj.group('mytv') is not None
40 webpage = self._download_webpage(url, video_id)
41 raw_title = self._html_search_regex(r'(?s)<title>(.+?)</title>',
42 webpage, u'video title')
43 title = raw_title.partition('-')[0].strip()
45 vid = self._html_search_regex(r'var vid ?= ?["\'](\d+)["\']', webpage,
47 data = _fetch_data(vid, mytv)
49 QUALITIES = ('ori', 'super', 'high', 'nor')
50 vid_ids = [data['data'][q + 'Vid']
52 if data['data'][q + 'Vid'] != 0]
54 raise ExtractorError(u'No formats available for this video')
56 # For now, we just pick the highest available quality
59 format_data = data if vid == vid_id else _fetch_data(vid_id, mytv)
60 part_count = format_data['data']['totalBlocks']
61 allot = format_data['allot']
62 prot = format_data['prot']
63 clipsURL = format_data['data']['clipsURL']
64 su = format_data['data']['su']
67 for i in range(part_count):
68 part_url = ('http://%s/?prot=%s&file=%s&new=%s' %
69 (allot, prot, clipsURL[i], su[i]))
70 part_str = self._download_webpage(
72 note=u'Downloading part %d of %d' % (i+1, part_count))
74 part_info = part_str.split('|')
75 video_url = '%s%s?key=%s' % (part_info[0], su[i], part_info[3])
78 'id': '%s_part%02d' % (video_id, i + 1),
83 playlist.append(video_info)
85 if len(playlist) == 1: