]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sohu.py
07f514a46246657206ae3fd31e19b1d2932e6f15
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..utils
import ExtractorError
11 class SohuIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?P<mytv>my\.)?tv\.sohu\.com/.+?/(?(mytv)|n)(?P<id>\d+)\.shtml.*?'
15 'url': 'http://tv.sohu.com/20130724/n382479172.shtml#super',
16 'md5': 'bde8d9a6ffd82c63a1eefaef4eeefec7',
20 'title': 'MV:Far East Movement《The Illest》',
22 'skip': 'Only available from China',
25 def _real_extract(self
, url
):
27 def _fetch_data(vid_id
, mytv
=False):
29 base_data_url
= 'http://my.tv.sohu.com/play/videonew.do?vid='
31 base_data_url
= 'http://hot.vrs.sohu.com/vrs_flash.action?vid='
32 data_url
= base_data_url
+ str(vid_id
)
33 data_json
= self
._download
_webpage
(
35 note
='Downloading JSON data for ' + str(vid_id
))
36 return json
.loads(data_json
)
38 mobj
= re
.match(self
._VALID
_URL
, url
)
39 video_id
= mobj
.group('id')
40 mytv
= mobj
.group('mytv') is not None
42 webpage
= self
._download
_webpage
(url
, video_id
)
43 raw_title
= self
._html
_search
_regex
(r
'(?s)<title>(.+?)</title>',
44 webpage
, 'video title')
45 title
= raw_title
.partition('-')[0].strip()
47 vid
= self
._html
_search
_regex
(r
'var vid ?= ?["\'](\d
+)["\']', webpage,
49 data = _fetch_data(vid, mytv)
51 QUALITIES = ('ori', 'super', 'high', 'nor')
52 vid_ids = [data['data'][q + 'Vid']
54 if data['data'][q + 'Vid'] != 0]
56 raise ExtractorError('No formats available for this video')
58 # For now, we just pick the highest available quality
61 format_data = data if vid == vid_id else _fetch_data(vid_id, mytv)
62 part_count = format_data['data']['totalBlocks']
63 allot = format_data['allot']
64 prot = format_data['prot']
65 clipsURL = format_data['data']['clipsURL']
66 su = format_data['data']['su']
69 for i in range(part_count):
70 part_url = ('http://%s/?prot=%s&file=%s&new=%s' %
71 (allot, prot, clipsURL[i], su[i]))
72 part_str = self._download_webpage(
74 note='Downloading part %d of %d' % (i + 1, part_count))
76 part_info = part_str.split('|')
77 video_url = '%s%s?key=%s' % (part_info[0], su[i], part_info[3])
80 'id': '%s_part%02d' % (video_id, i + 1),
85 playlist.append(video_info)
87 if len(playlist) == 1: