2012-09-01 14:14:12 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
__all__ = ['sohu_download']
|
|
|
|
|
|
|
|
from ..common import *
|
|
|
|
|
2013-01-03 19:04:33 +04:00
|
|
|
import json
|
|
|
|
|
2012-09-01 14:14:12 +04:00
|
|
|
def real_url(host, prot, file, new):
|
|
|
|
url = 'http://%s/?prot=%s&file=%s&new=%s' % (host, prot, file, new)
|
2013-06-27 05:13:46 +04:00
|
|
|
start, _, host, key = get_html(url).split('|')[:4]
|
2012-09-01 14:14:12 +04:00
|
|
|
return '%s%s?key=%s' % (start[:-1], new, key)
|
|
|
|
|
|
|
|
def sohu_download(url, output_dir = '.', merge = True, info_only = False):
|
2013-09-17 17:42:46 +04:00
|
|
|
html = get_html(url)
|
|
|
|
vid = r1('vid\s*=\s*"(\d+)"', html)
|
|
|
|
if not vid:
|
|
|
|
vid = r1('vid\s*:\s*"(\d+)"', html)
|
|
|
|
|
2013-10-30 10:32:06 +04:00
|
|
|
# Open Sogou proxy if required
|
|
|
|
if get_sogou_proxy() is not None:
|
|
|
|
server = sogou_proxy_server(get_sogou_proxy(), ostream=open(os.devnull, 'w'))
|
|
|
|
server_thread = threading.Thread(target=server.serve_forever)
|
|
|
|
server_thread.daemon = True
|
|
|
|
server_thread.start()
|
|
|
|
set_proxy(server.server_address)
|
|
|
|
|
2013-01-03 19:04:33 +04:00
|
|
|
if vid:
|
|
|
|
data = json.loads(get_decoded_html('http://hot.vrs.sohu.com/vrs_flash.action?vid=%s' % vid))
|
|
|
|
for qtyp in ["oriVid","superVid","highVid" ,"norVid","relativeId"]:
|
|
|
|
hqvid = data['data'][qtyp]
|
|
|
|
if hqvid != 0 and hqvid != vid :
|
|
|
|
data = json.loads(get_decoded_html('http://hot.vrs.sohu.com/vrs_flash.action?vid=%s' % hqvid))
|
|
|
|
break
|
|
|
|
host = data['allot']
|
|
|
|
prot = data['prot']
|
|
|
|
urls = []
|
|
|
|
data = data['data']
|
|
|
|
title = data['tvName']
|
|
|
|
size = sum(data['clipsBytes'])
|
|
|
|
assert len(data['clipsURL']) == len(data['clipsBytes']) == len(data['su'])
|
|
|
|
for file, new in zip(data['clipsURL'], data['su']):
|
|
|
|
urls.append(real_url(host, prot, file, new))
|
|
|
|
assert data['clipsURL'][0].endswith('.mp4')
|
2013-09-17 17:42:46 +04:00
|
|
|
|
2013-01-03 19:04:33 +04:00
|
|
|
else:
|
2013-10-08 18:00:00 +04:00
|
|
|
if re.match(r'http://share.vrs.sohu.com', url):
|
|
|
|
vid = r1('id=(\d+)', url)
|
|
|
|
else:
|
|
|
|
vid = r1('vid\s*=\s*\'(\d+)\'', get_html(url))
|
|
|
|
data = json.loads(get_decoded_html('http://my.tv.sohu.com/play/videonew.do?vid=%s&referer=http://my.tv.sohu.com' % vid))
|
2013-01-03 19:04:33 +04:00
|
|
|
host = data['allot']
|
|
|
|
prot = data['prot']
|
|
|
|
urls = []
|
|
|
|
data = data['data']
|
|
|
|
title = data['tvName']
|
|
|
|
size = sum([int(clipsBytes) for clipsBytes in data['clipsBytes']])
|
|
|
|
assert len(data['clipsURL']) == len(data['clipsBytes']) == len(data['su'])
|
|
|
|
for file, new in zip(data['clipsURL'], data['su']):
|
|
|
|
urls.append(real_url(host, prot, file, new))
|
|
|
|
assert data['clipsURL'][0].endswith('.mp4')
|
2013-09-17 17:42:46 +04:00
|
|
|
|
2013-10-30 10:32:06 +04:00
|
|
|
# Close Sogou proxy if required
|
|
|
|
if get_sogou_proxy() is not None:
|
|
|
|
server.shutdown()
|
|
|
|
unset_proxy()
|
|
|
|
|
2012-09-01 14:14:12 +04:00
|
|
|
print_info(site_info, title, 'mp4', size)
|
|
|
|
if not info_only:
|
|
|
|
download_urls(urls, title, 'mp4', size, output_dir, refer = url, merge = merge)
|
|
|
|
|
|
|
|
site_info = "Sohu.com"
|
|
|
|
download = sohu_download
|
|
|
|
download_playlist = playlist_not_supported('sohu')
|