fix #1: use redirected URLs for resuming of Youku downloads

This commit is contained in:
Mort Yao 2012-08-31 02:55:47 +02:00
parent a4bf334acf
commit e71972d4a1
2 changed files with 12 additions and 2 deletions

View File

@ -109,6 +109,13 @@ def url_info(url):
return type, ext, size return type, ext, size
def url_locations(urls):
locations = []
for url in urls:
response = request.urlopen(request.Request(url))
locations.append(response.url)
return locations
def url_save(url, filepath, bar, refer = None, is_part = False): def url_save(url, filepath, bar, refer = None, is_part = False):
file_size = url_size(url) file_size = url_size(url)

View File

@ -123,11 +123,14 @@ def file_type_of_url(url):
def youku_download_by_id(id2, title, output_dir = '.', stream_type = None, merge = True, info_only = False): def youku_download_by_id(id2, title, output_dir = '.', stream_type = None, merge = True, info_only = False):
info = get_info(id2) info = get_info(id2)
urls, sizes = zip(*find_video(info, stream_type)) urls, sizes = zip(*find_video(info, stream_type))
ext = file_type_of_url(urls[0])
total_size = sum(sizes) total_size = sum(sizes)
print_info(site_info, title, file_type_of_url(urls[0]), total_size) urls = url_locations(urls) # Use real (redirected) URLs for resuming of downloads
print_info(site_info, title, ext, total_size)
if not info_only: if not info_only:
download_urls(urls, title, file_type_of_url(urls[0]), total_size, output_dir, merge = merge) download_urls(urls, title, ext, total_size, output_dir, merge = merge)
def youku_download(url, output_dir = '.', stream_type = None, merge = True, info_only = False): def youku_download(url, output_dir = '.', stream_type = None, merge = True, info_only = False):
id2, title = parse_page(url) id2, title = parse_page(url)