From bc5b704e0eb3a4c2bdb0014837ab9392135be5e3 Mon Sep 17 00:00:00 2001 From: Mort Yao Date: Thu, 3 Jan 2013 16:04:33 +0100 Subject: [PATCH] Sohu: fix #53 --- CHANGELOG.txt | 9 +++++++ LICENSE.txt | 2 +- you_get/downloader/sohu.py | 52 +++++++++++++++++++++++++------------- you_get/version.py | 4 +-- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7445179b..ab16e2ec 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,15 @@ Changelog ========= +0.3dev-20130104 +--------------- + +*Date: 2013-01-04* + +* Sohu: + - fix `#53 `_. + - merge pull request `#54 `_; downloading the highest available quality now. + 0.3dev-20121228 --------------- diff --git a/LICENSE.txt b/LICENSE.txt index 711df074..4bfaa35f 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,7 @@ ============================================== This is a copy of the MIT license. ============================================== -Copyright (C) 2012 Mort Yao +Copyright (C) 2012, 2013 Mort Yao Copyright (C) 2012 Boyu Guo Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/you_get/downloader/sohu.py b/you_get/downloader/sohu.py index 260c6f93..fc0a8a62 100644 --- a/you_get/downloader/sohu.py +++ b/you_get/downloader/sohu.py @@ -4,6 +4,8 @@ __all__ = ['sohu_download'] from ..common import * +import json + def real_url(host, prot, file, new): url = 'http://%s/?prot=%s&file=%s&new=%s' % (host, prot, file, new) start, _, host, key, _, _ = get_html(url).split('|') @@ -11,24 +13,38 @@ def real_url(host, prot, file, new): def sohu_download(url, output_dir = '.', merge = True, info_only = False): vid = r1('vid="(\d+)"', get_html(url)) - assert vid - import json - 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') + + 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') + + else: + vid = r1('vid=\'(\d+)\'', get_html(url)) + data = json.loads(get_decoded_html('http://my.tv.sohu.com/videinfo.jhtml?m=viewnew&vid=%s' % vid)) + 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') print_info(site_info, title, 'mp4', size) if not info_only: diff --git a/you_get/version.py b/you_get/version.py index 8ee46a7e..db7e76ff 100644 --- a/you_get/version.py +++ b/you_get/version.py @@ -1,4 +1,4 @@ #!/usr/bin/env python -__version__ = '0.3dev-20121228' -__date__ = '2012-12-28' +__version__ = '0.3dev-20130104' +__date__ = '2013-01-04'