Преглед изворни кода

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

Mort Yao пре 12 година
родитељ
комит
e71972d4a1
2 измењених фајлова са 12 додато и 2 уклоњено
  1. 7 0
      common.py
  2. 5 2
      get_youku.py

+ 7 - 0
common.py

@@ -109,6 +109,13 @@ def url_info(url):
     
     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):
     file_size = url_size(url)
     

+ 5 - 2
get_youku.py

@@ -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):
     info = get_info(id2)
     urls, sizes = zip(*find_video(info, stream_type))
+    ext = file_type_of_url(urls[0])
     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:
-        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):
     id2, title = parse_page(url)