瀏覽代碼

[utils] restart download if server does not support byte ranges

remitamine 10 年之前
父節點
當前提交
d7d2a9a3db
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      youtube_dl/downloader/http.py

+ 14 - 0
youtube_dl/downloader/http.py

@@ -57,6 +57,20 @@ class HttpFD(FileDownloader):
             # Establish connection
             # Establish connection
             try:
             try:
                 data = self.ydl.urlopen(request)
                 data = self.ydl.urlopen(request)
+
+                if resume_len > 0:
+                    content_range = data.headers.get('Content-Range')
+                    if content_range:
+                        content_range_m = re.search(r'bytes (\d+)-', content_range)
+                        if content_range_m:
+                            # Content-Range is correct - go on
+                            if resume_len == int(content_range_m.group(1)):
+                                break
+
+                    # Content-Range is invalid - wipe the file and do entire redownload
+                    resume_len = 0
+                    open_mode = 'wb'
+
                 break
                 break
             except (compat_urllib_error.HTTPError, ) as err:
             except (compat_urllib_error.HTTPError, ) as err:
                 if (err.code < 500 or err.code >= 600) and err.code != 416:
                 if (err.code < 500 or err.code >= 600) and err.code != 416: