3 from .common
import InfoExtractor
6 compat_urllib_parse_urlencode
,
15 class SohuIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
18 # Sohu videos give different MD5 sums on Travis CI and my machine
20 'note': 'This video is available only in Mainland China',
21 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
25 'title': 'MV:Far East Movement《The Illest》',
27 'skip': 'On available in China',
29 'url': 'http://tv.sohu.com/20150305/n409385080.shtml',
33 'title': '《2015湖南卫视羊年元宵晚会》唐嫣《花好月圆》',
36 'url': 'http://my.tv.sohu.com/us/232799889/78693464.shtml',
40 'title': '【爱范品】第31期:MWC见不到的奇葩手机',
43 'note': 'Multipart video',
44 'url': 'http://my.tv.sohu.com/pl/8384802/78910339.shtml',
47 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
51 'id': '78910339_part1',
54 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
58 'id': '78910339_part2',
61 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
65 'id': '78910339_part3',
68 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
72 'note': 'Video with title containing dash',
73 'url': 'http://my.tv.sohu.com/us/249884221/78932792.shtml',
77 'title': 'youtube-dl testing video',
84 def _real_extract(self
, url
):
86 def _fetch_data(vid_id
, mytv
=False):
88 base_data_url
= 'http://my.tv.sohu.com/play/videonew.do?vid='
90 base_data_url
= 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
92 return self
._download
_json
(
93 base_data_url
+ vid_id
, video_id
,
94 'Downloading JSON data for %s' % vid_id
,
95 headers
=self
.geo_verification_headers())
97 mobj
= self
._match
_valid
_url
(url
)
98 video_id
= mobj
.group('id')
99 mytv
= mobj
.group('mytv') is not None
101 webpage
= self
._download
_webpage
(url
, video_id
)
103 title
= re
.sub(r
' - 搜狐视频$', '', self
._og
_search
_title
(webpage
))
105 vid
= self
._html
_search
_regex
(
106 r
'var vid ?= ?["\'](\d
+)["\']',
107 webpage, 'video path')
108 vid_data = _fetch_data(vid, mytv)
109 if vid_data['play'] != 1:
110 if vid_data.get('status') == 12:
111 raise ExtractorError(
112 '%s said: There\'s something wrong in the video.' % self.IE_NAME,
115 self.raise_geo_restricted(
116 '%s said: The video is only licensed to users in Mainland China.' % self.IE_NAME)
119 for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
120 vid_id = vid_data['data'].get('%sVid' % format_id)
123 vid_id = compat_str(vid_id)
124 formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
126 part_count = vid_data['data']['totalBlocks']
129 for i in range(part_count):
131 for format_id, format_data in formats_json.items():
132 allot = format_data['allot']
134 data = format_data['data']
135 clips_url = data['clipsURL']
138 video_url = 'newflv.sohu.ccgslb.net'
142 while 'newflv.sohu.ccgslb.net' in video_url:
145 'file': clips_url[i],
151 if cdnId is not None:
152 params['idc'] = cdnId
154 download_note = 'Downloading %s video URL part %d of %d' % (
155 format_id, i + 1, part_count)
158 download_note += ' (retry #%d)' % retries
159 part_info = self._parse_json(self._download_webpage(
160 'http://%s/?%s' % (allot, compat_urllib_parse_urlencode(params)),
161 video_id, download_note), video_id)
163 video_url = part_info['url']
164 cdnId = part_info.get('nid')
168 raise ExtractorError('Failed to get video URL')
172 'format_id': format_id,
173 'filesize': int_or_none(
174 try_get(data, lambda x: x['clipsBytes'][i])),
175 'width': int_or_none(data.get('width')),
176 'height': int_or_none(data.get('height')),
177 'fps': int_or_none(data.get('fps')),
181 'id': '%s_part%d' % (video_id, i + 1),
183 'duration': vid_data['data']['clipsDuration'][i],
187 if len(playlist) == 1:
189 info['id'] = video_id
192 '_type': 'multi_video',