]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sohu.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from .common
import compat_str
10 class SohuIE(InfoExtractor
):
11 _VALID_URL
= r
'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
14 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
15 'md5': 'bde8d9a6ffd82c63a1eefaef4eeefec7',
19 'title': 'MV:Far East Movement《The Illest》',
21 'skip': 'Only available from China',
24 def _real_extract(self
, url
):
26 def _fetch_data(vid_id
, mytv
=False):
28 base_data_url
= 'http://my.tv.sohu.com/play/videonew.do?vid='
30 base_data_url
= 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
32 return self
._download
_json
(
33 base_data_url
+ vid_id
, video_id
,
34 'Downloading JSON data for %s' % vid_id
)
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
(
42 r
'(?s)<title>(.+?)</title>',
43 webpage
, 'video title')
44 title
= raw_title
.partition('-')[0].strip()
46 vid
= self
._html
_search
_regex
(
47 r
'var vid ?= ?["\'](\d
+)["\']',
48 webpage, 'video path')
49 vid_data = _fetch_data(vid, mytv)
52 for format_id in ('nor', 'high', 'super', 'ori', 'h2644k', 'h2654k'):
53 vid_id = vid_data['data'].get('%sVid' % format_id)
56 vid_id = compat_str(vid_id)
57 formats_json[format_id] = vid_data if vid == vid_id else _fetch_data(vid_id, mytv)
59 part_count = vid_data['data']['totalBlocks']
62 for i in range(part_count):
64 for format_id, format_data in formats_json.items():
65 allot = format_data['allot']
66 prot = format_data['prot']
68 data = format_data['data']
69 clips_url = data['clipsURL']
72 part_str = self._download_webpage(
73 'http://%s/?prot=%s&file=%s&new=%s' %
74 (allot, prot, clips_url[i], su[i]),
76 'Downloading %s video URL part %d of %d'
77 % (format_id, i + 1, part_count))
79 part_info = part_str.split('|')
80 video_url = '%s%s?key=%s' % (part_info[0], su[i], part_info[3])
84 'format_id': format_id,
85 'filesize': data['clipsBytes'][i],
86 'width': data['width'],
87 'height': data['height'],
90 self._sort_formats(formats)
93 'id': '%s_part%d' % (video_id, i + 1),
95 'duration': vid_data['data']['clipsDuration'][i],
99 if len(playlist) == 1:
101 info['id'] = video_id