2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_urlencode
,
17 class SohuIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
21 'note': 'This video is available only in Mainland China',
22 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
23 'md5': '29175c8cadd8b5cc4055001e85d6b372',
27 'title': 'MV:Far East Movement《The Illest》',
29 'skip': 'On available in China',
31 'url': 'http://tv.sohu.com/20150305/n409385080.shtml',
32 'md5': '699060e75cf58858dd47fb9c03c42cfb',
36 'title': '《2015湖南卫视羊年元宵晚会》唐嫣《花好月圆》',
39 'url': 'http://my.tv.sohu.com/us/232799889/78693464.shtml',
40 'md5': '9bf34be48f2f4dadcb226c74127e203c',
44 'title': '【爱范品】第31期:MWC见不到的奇葩手机',
47 'note': 'Multipart video',
48 'url': 'http://my.tv.sohu.com/pl/8384802/78910339.shtml',
51 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
54 'md5': 'bdbfb8f39924725e6589c146bc1883ad',
56 'id': '78910339_part1',
59 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
62 'md5': '3e1f46aaeb95354fd10e7fca9fc1804e',
64 'id': '78910339_part2',
67 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
70 'md5': '8407e634175fdac706766481b9443450',
72 'id': '78910339_part3',
75 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
79 'note': 'Video with title containing dash',
80 'url': 'http://my.tv.sohu.com/us/249884221/78932792.shtml',
84 'title': 'youtube-dl testing video',
91 def _real_extract(self
, url
):
93 def _fetch_data(vid_id
, mytv
=False):
95 base_data_url
= 'http://my.tv.sohu.com/play/videonew.do?vid='
97 base_data_url
= 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
99 req
= sanitized_Request(base_data_url
+ vid_id
)
101 cn_verification_proxy
= self
._downloader
.params
.get('cn_verification_proxy')
102 if cn_verification_proxy
:
103 req
.add_header('Ytdl-request-proxy', cn_verification_proxy
)
105 return self
._download
_json
(
107 'Downloading JSON data for %s' % vid_id
)
109 mobj
= re
.match(self
._VALID
_URL
, url
)
110 video_id
= mobj
.group('id')
111 mytv
= mobj
.group('mytv') is not None
113 webpage
= self
._download
_webpage
(url
, video_id
)
115 title
= re
.sub(r
' - 搜狐视频$', '', self
._og
_search
_title
(webpage
))
117 vid
= self
._html
_search
_regex
(
118 r
'var vid ?= ?["\'](\d
+)["\']',
119 webpage, 'video path')
120 vid_data = _fetch_data(vid, mytv)
121 if vid_data['play'] != 1:
122 if vid_data.get('status') == 12:
123 raise ExtractorError(
124 'Sohu said: There\'s something wrong in the video.',
127 raise ExtractorError(
128 'Sohu said: The video is only licensed to users in Mainland China.',
132 for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
133 vid_id = vid_data['data'].get('%sVid' % format_id)
136 vid_id = compat_str(vid_id)
137 formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
139 part_count = vid_data['data']['totalBlocks']
142 for i in range(part_count):
144 for format_id, format_data in formats_json.items():
145 allot = format_data['allot']
147 data = format_data['data']
148 clips_url = data['clipsURL']
151 video_url = 'newflv.sohu.ccgslb.net'
155 while 'newflv.sohu.ccgslb.net' in video_url:
158 'file': clips_url[i],
164 if cdnId is not None:
165 params['idc'] = cdnId
167 download_note = 'Downloading %s video URL part %d of %d' % (
168 format_id, i + 1, part_count)
171 download_note += ' (retry #%d)' % retries
172 part_info = self._parse_json(self._download_webpage(
173 'http://%s/?%s' % (allot, compat_urllib_parse_urlencode(params)),
174 video_id, download_note), video_id)
176 video_url = part_info['url']
177 cdnId = part_info.get('nid')
181 raise ExtractorError('Failed to get video URL')
185 'format_id': format_id,
186 'filesize': data['clipsBytes'][i],
187 'width': data['width'],
188 'height': data['height'],
191 self._sort_formats(formats)
194 'id': '%s_part%d' % (video_id, i + 1),
196 'duration': vid_data['data']['clipsDuration'][i],
200 if len(playlist) == 1:
202 info['id'] = video_id
205 '_type': 'multi_video',