support my.tv.sohu.com

try tv.sohu.com first
then my.tv.sohu.com

Signed-off-by: Zhang Ning <zhangn1985@gmail.com>
This commit is contained in:
Zhang Ning 2015-09-04 18:45:35 +08:00
parent c9590bd8d5
commit 8663ef14bd

View File

@ -23,47 +23,58 @@ class Sohu(VideoExtractor):
{'id': 'superVid', 'container': 'mp4', 'video_profile': '超清'}, {'id': 'superVid', 'container': 'mp4', 'video_profile': '超清'},
{'id': 'highVid', 'container': 'mp4', 'video_profile': '高清'}, {'id': 'highVid', 'container': 'mp4', 'video_profile': '高清'},
{'id': 'norVid', 'container': 'mp4', 'video_profile': '标清'}, {'id': 'norVid', 'container': 'mp4', 'video_profile': '标清'},
{'id': 'relativeId', 'container': 'mp4', 'video_profile': '当前'},
] ]
realurls = { 'oriVid': [], 'superVid': [], 'highVid': [], 'norVid': [], 'relativeId': []} realurls = { 'oriVid': [], 'superVid': [], 'highVid': [], 'norVid': [], 'relativeId': []}
vids = {} vids = { 'oriVid': 0, 'superVid': 0, 'highVid': 0, 'norVid': 0, 'relativeId': 0}
def real_url(host, vid, tvid, new, clipURL, ck): def real_url(host, vid, tvid, new, clipURL, ck):
return 'http://'+host+'/?prot=9&prod=flash&pt=1&file='+clipURL+'&new='+new +'&key='+ ck+'&vid='+str(vid)+'&uid='+str(int(time.time()*1000))+'&t='+str(random()) return 'http://'+host+'/?prot=9&prod=flash&pt=1&file='+clipURL+'&new='+new +'&key='+ ck+'&vid='+str(vid)+'&uid='+str(int(time.time()*1000))+'&t='+str(random())
def get_vid_from_url(url):
return match1(url, 'id=(\d+)')
def get_vid_from_content(content): def get_vid_from_content(content):
return match1(content, '\/([0-9]+)\/v\.swf') return match1(content, '\/([0-9]+)\/v\.swf') or \
match1(content, '\&id=(\d+)')
def parser_info(self, info, stream, lvid):
host = info['allot']
prot = info['prot']
tvid = info['tvid']
data = info['data']
size = sum(map(int,data['clipsBytes']))
assert len(data['clipsURL']) == len(data['clipsBytes']) == len(data['su'])
for new, clip, ck, in zip(data['su'], data['clipsURL'], data['ck']):
clipURL = urlparse(clip).path
self.realurls[stream['id']].append(self.__class__.real_url(host, lvid, tvid, new, clipURL, ck))
self.streams[stream['id']] = {'container': 'mp4', 'video_profile': stream['video_profile'], 'size' : size}
self.vids[stream['id']] = lvid
def prepare(self, **kwargs): def prepare(self, **kwargs):
assert self.url or self.vid assert self.url or self.vid
if self.url and not self.vid: if self.url and not self.vid:
self.vid = self.__class__.get_vid_from_url(self.url) or \ self.vid = self.__class__.get_vid_from_content(str(get_decoded_html(self.url)))
self.__class__.get_vid_from_content(str(get_decoded_html(self.url)))
info = json.loads(get_decoded_html('http://hot.vrs.sohu.com/vrs_flash.action?vid=%s' % self.vid)) info = json.loads(get_decoded_html('http://hot.vrs.sohu.com/vrs_flash.action?vid=%s' % self.vid))
data = info['data'] if info['status'] == 1:
self.title = data['tvName'] data = info['data']
for stream in self.stream_types: self.title = data['tvName']
lvid = data[stream['id']] for stream in self.stream_types:
if lvid != 0 and lvid != self.vid : lvid = data[stream['id']]
info = json.loads(get_decoded_html('http://hot.vrs.sohu.com/vrs_flash.action?vid=%s' % lvid)) if lvid != 0 and lvid != self.vid :
data = info['data'] info = json.loads(get_decoded_html('http://hot.vrs.sohu.com/vrs_flash.action?vid=%s' % lvid))
host = info['allot'] self.parser_info(info, stream, lvid)
prot = info['prot'] return
tvid = info['tvid'] info = json.loads(get_decoded_html('http://my.tv.sohu.com/play/videonew.do?vid=%s&referer=http://my.tv.sohu.com' % self.vid))
size = sum(data['clipsBytes']) if info['status'] == 1:
assert len(data['clipsURL']) == len(data['clipsBytes']) == len(data['su']) data = info['data']
for new, clip, ck, in zip(data['su'], data['clipsURL'], data['ck']): self.title = data['tvName']
clipURL = urlparse(clip).path for stream in self.stream_types:
self.realurls[stream['id']].append(self.__class__.real_url(host, lvid, tvid, new, clipURL, ck)) lvid = data[stream['id']]
self.streams[stream['id']] = {'container': 'mp4', 'video_profile': stream['video_profile'], 'size' : size} info = json.loads(get_decoded_html('http://my.tv.sohu.com/play/videonew.do?vid=%s&referer=http://my.tv.sohu.com' % lvid))
self.vids[stream['id']] = lvid self.parser_info(info, stream, lvid)
return
def extract(self, **kwargs): def extract(self, **kwargs):
if 'stream_id' in kwargs and kwargs['stream_id']: if 'stream_id' in kwargs and kwargs['stream_id']: