2 from __future__ import unicode_literals
6 from .common import InfoExtractor
11 from ..utils import sanitize_url_path_consecutive_slashes
14 class SohuIE(InfoExtractor):
15 _VALID_URL = r'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
18 'note': 'This video is available only in Mainland China',
19 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
20 'md5': '29175c8cadd8b5cc4055001e85d6b372',
24 'title': 'MV:Far East Movement《The Illest》',
27 'cn_verification_proxy': 'proxy.uku.im:8888'
30 'url': 'http://tv.sohu.com/20150305/n409385080.shtml',
31 'md5': '699060e75cf58858dd47fb9c03c42cfb',
35 'title': '《2015湖南卫视羊年元宵晚会》唐嫣《花好月圆》',
38 'url': 'http://my.tv.sohu.com/us/232799889/78693464.shtml',
39 'md5': '9bf34be48f2f4dadcb226c74127e203c',
43 'title': '【爱范品】第31期:MWC见不到的奇葩手机',
46 'note': 'Multipart video',
47 'url': 'http://my.tv.sohu.com/pl/8384802/78910339.shtml',
52 'md5': 'bdbfb8f39924725e6589c146bc1883ad',
54 'id': '78910339_part1',
57 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
60 'md5': '3e1f46aaeb95354fd10e7fca9fc1804e',
62 'id': '78910339_part2',
65 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
68 'md5': '8407e634175fdac706766481b9443450',
70 'id': '78910339_part3',
73 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
77 'note': 'Video with title containing dash',
78 'url': 'http://my.tv.sohu.com/us/249884221/78932792.shtml',
82 'title': 'youtube-dl testing video',
89 def _real_extract(self, url):
91 def _fetch_data(vid_id, mytv=False):
93 base_data_url = 'http://my.tv.sohu.com/play/videonew.do?vid='
95 base_data_url = 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
97 req = compat_urllib_request.Request(base_data_url + vid_id)
99 cn_verification_proxy = self._downloader.params.get('cn_verification_proxy')
100 if cn_verification_proxy:
101 req.add_header('Ytdl-request-proxy', cn_verification_proxy)
103 return self._download_json(
105 'Downloading JSON data for %s' % vid_id)
107 mobj = re.match(self._VALID_URL, url)
108 video_id = mobj.group('id')
109 mytv = mobj.group('mytv') is not None
111 webpage = self._download_webpage(url, video_id)
113 title = self._og_search_title(webpage)
115 vid = self._html_search_regex(
116 r'var vid ?= ?["\'](\d+)["\']',
117 webpage, 'video path')
118 vid_data = _fetch_data(vid, mytv)
121 for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
122 vid_id = vid_data['data'].get('%sVid' % format_id)
125 vid_id = compat_str(vid_id)
126 formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
128 part_count = vid_data['data']['totalBlocks']
131 for i in range(part_count):
133 for format_id, format_data in formats_json.items():
134 allot = format_data['allot']
135 prot = format_data['prot']
137 data = format_data['data']
138 clips_url = data['clipsURL']
141 part_str = self._download_webpage(
142 'http://%s/?prot=%s&file=%s&new=%s' %
143 (allot, prot, clips_url[i], su[i]),
145 'Downloading %s video URL part %d of %d'
146 % (format_id, i + 1, part_count))
148 part_info = part_str.split('|')
150 video_url = sanitize_url_path_consecutive_slashes(
151 '%s%s?key=%s' % (part_info[0], su[i], part_info[3]))
155 'format_id': format_id,
156 'filesize': data['clipsBytes'][i],
157 'width': data['width'],
158 'height': data['height'],
161 self._sort_formats(formats)
164 'id': '%s_part%d' % (video_id, i + 1),
166 'duration': vid_data['data']['clipsDuration'][i],
170 if len(playlist) == 1:
172 info['id'] = video_id