5 from .common
import InfoExtractor
18 class SohuIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
21 # Sohu videos give different MD5 sums on Travis CI and my machine
23 'note': 'This video is available only in Mainland China',
24 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
28 'title': 'MV:Far East Movement《The Illest》',
30 'skip': 'On available in China',
32 'url': 'http://tv.sohu.com/20150305/n409385080.shtml',
36 'title': '《2015湖南卫视羊年元宵晚会》唐嫣《花好月圆》',
38 'skip': 'no longer available',
40 'url': 'http://my.tv.sohu.com/us/232799889/78693464.shtml',
44 'title': '【爱范品】第31期:MWC见不到的奇葩手机',
47 'timestamp': 1425519600,
48 'upload_date': '20150305',
49 'thumbnail': 'http://e3f49eaa46b57.cdn.sohucs.com//group1/M10/83/FA/MTAuMTAuODguODA=/6_14cbccdde5eg104SysCutcloud_78693464_7_0b.jpg',
50 'tags': ['爱范儿', '爱范品', 'MWC', '手机'],
53 'note': 'Multipart video',
54 'url': 'http://my.tv.sohu.com/pl/8384802/78910339.shtml',
57 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
60 'timestamp': 1426269360,
61 'upload_date': '20150313',
62 'thumbnail': 'http://e3f49eaa46b57.cdn.sohucs.com//group1/M11/89/57/MTAuMTAuODguODA=/6_14cea022a1dg102SysCutcloud_78910339_8_0b.jpg',
63 'tags': ['小苍MM', '英雄联盟', '实战秘籍'],
67 'id': '78910339_part1',
70 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
74 'id': '78910339_part2',
77 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
81 'id': '78910339_part3',
84 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
88 'note': 'Video with title containing dash',
89 'url': 'http://my.tv.sohu.com/us/249884221/78932792.shtml',
93 'title': 'youtube-dl testing video',
95 'timestamp': 1426348620,
96 'upload_date': '20150314',
97 'thumbnail': 'http://e3f49eaa46b57.cdn.sohucs.com//group1/M02/8A/00/MTAuMTAuODguNzk=/6_14cee1be192g102SysCutcloud_78932792_7_7b.jpg',
101 'skip_download': True,
105 def _real_extract(self
, url
):
107 def _fetch_data(vid_id
, mytv
=False):
109 base_data_url
= 'http://my.tv.sohu.com/play/videonew.do?vid='
111 base_data_url
= 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
113 return self
._download
_json
(
114 base_data_url
+ vid_id
, video_id
,
115 f
'Downloading JSON data for {vid_id}',
116 headers
=self
.geo_verification_headers())
118 mobj
= self
._match
_valid
_url
(url
)
119 video_id
= mobj
.group('id')
120 mytv
= mobj
.group('mytv') is not None
122 webpage
= self
._download
_webpage
(url
, video_id
)
124 title
= re
.sub(r
'( - 高清正版在线观看)? - 搜狐视频$', '', self
._og
_search
_title
(webpage
))
126 vid
= self
._html
_search
_regex
(
127 r
'var vid ?= ?["\'](\d
+)["\']',
128 webpage, 'video path')
129 vid_data = _fetch_data(vid, mytv)
130 if vid_data['play'] != 1:
131 if vid_data.get('status') == 12:
132 raise ExtractorError(
133 f'{self.IE_NAME} said: There\'s something wrong in the video.',
136 self.raise_geo_restricted(
137 f'{self.IE_NAME} said: The video is only licensed to users in Mainland China.')
140 for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
141 vid_id = vid_data['data'].get(f'{format_id}Vid')
145 formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
147 part_count = vid_data['data']['totalBlocks']
150 for i in range(part_count):
152 for format_id, format_data in formats_json.items():
153 allot = format_data['allot']
155 data = format_data['data']
156 clip_url = traverse_obj(data, (('clipsURL', 'mp4PlayUrl'), i, {url_or_none}), get_all=False)
158 raise ExtractorError(f'Unable to extract url for clip {i}')
161 video_url = 'newflv.sohu.ccgslb.net'
165 while 'newflv.sohu.ccgslb.net' in video_url:
174 if cdn_id is not None:
175 params['idc'] = cdn_id
177 download_note = f'Downloading {format_id} video URL part {i + 1} of {part_count}'
180 download_note += f' (retry #{retries})'
181 part_info = self._parse_json(self._download_webpage(
182 f'http://{allot}/?{urllib.parse.urlencode(params)}',
183 video_id, download_note), video_id)
185 video_url = part_info['url']
186 cdn_id = part_info.get('nid')
190 raise ExtractorError('Failed to get video URL')
194 'format_id': format_id,
195 'filesize': int_or_none(
196 try_get(data, lambda x: x['clipsBytes'][i])),
197 'width': int_or_none(data.get('width')),
198 'height': int_or_none(data.get('height')),
199 'fps': int_or_none(data.get('fps')),
203 'id': f'{video_id}_part{i + 1}',
205 'duration': vid_data['data']['clipsDuration'][i],
209 if len(playlist) == 1:
211 info['id'] = video_id
214 '_type': 'multi_video',
218 'duration': traverse_obj(vid_data, ('data', 'totalDuration', {float_or_none})),
222 publish_time = unified_timestamp(self._search_regex(
223 r'publishTime:\s*["\'](\d
+-\d
+-\d
+ \d
+:\d
+)["\']', webpage, 'publish time', fatal=False))
225 publish_time = traverse_obj(vid_data, ('tv_application_time', {unified_timestamp}))
228 'timestamp': publish_time - 8 * 3600 if publish_time else None,
229 **traverse_obj(vid_data, {
230 'alt_title': ('data', 'subName', {str}),
231 'uploader': ('wm_data', 'wm_username', {str}),
232 'thumbnail': ('data', 'coverImg', {url_or_none}),
233 'tags': ('data', 'tag', {str.split}),
239 class SohuVIE(InfoExtractor):
240 _VALID_URL = r'https?://tv\.sohu\.com/v/(?P<id>[\w=-]+)\.html(?:$|[#?])'
243 'note': 'Multipart video',
244 'url': 'https://tv.sohu.com/v/MjAyMzA2MTQvbjYwMTMxNTE5Mi5zaHRtbA==.html',
247 'title': '《淬火丹心》第1集',
248 'alt_title': '“点天灯”发生事故',
249 'duration': 2701.692,
250 'timestamp': 1686758040,
251 'upload_date': '20230614',
252 'thumbnail': 'http://photocdn.tv.sohu.com/img/20230614/vrsa_hor_1686738763256_454010551.jpg',
254 'playlist_mincount': 9,
255 'skip': 'Only available in China',
257 'url': 'https://tv.sohu.com/v/dXMvMjMyNzk5ODg5Lzc4NjkzNDY0LnNodG1s.html',
261 'title': '【爱范品】第31期:MWC见不到的奇葩手机',
264 'timestamp': 1425519600,
265 'upload_date': '20150305',
266 'thumbnail': 'http://e3f49eaa46b57.cdn.sohucs.com//group1/M10/83/FA/MTAuMTAuODguODA=/6_14cbccdde5eg104SysCutcloud_78693464_7_0b.jpg',
267 'tags': ['爱范儿', '爱范品', 'MWC', '手机'],
270 'note': 'Multipart video',
271 'url': 'https://tv.sohu.com/v/dXMvMjQyNTYyMTYzLzc4OTEwMzM5LnNodG1s.html?src=pl',
274 'title': '【神探苍实战秘籍】第13期 战争之影 赫卡里姆',
275 'uploader': '小苍cany',
277 'timestamp': 1426269360,
278 'upload_date': '20150313',
279 'thumbnail': 'http://e3f49eaa46b57.cdn.sohucs.com//group1/M11/89/57/MTAuMTAuODguODA=/6_14cea022a1dg102SysCutcloud_78910339_8_0b.jpg',
280 'tags': ['小苍MM', '英雄联盟', '实战秘籍'],
282 'playlist_mincount': 3,
285 def _real_extract(self, url):
286 encoded_id = self._match_id(url)
287 path = base64.urlsafe_b64decode(encoded_id).decode()
288 subdomain = 'tv' if re.match(r'\d+/n\d+\.shtml', path) else 'my.tv'
289 return self.url_result(urljoin(f'http://{subdomain}.sohu.com/', path), SohuIE)