about summary refs log tree commit diff
path: root/youtube_dl/downloader/http.py
diff options
context:
space:
mode:
authorremitamine <remitamine@gmail.com>2015-08-02 03:28:04 +0100
committerSergey M․ <dstftw@gmail.com>2015-08-03 02:23:31 +0600
commitd7d2a9a3dbf1cef78c5085a4aab5d2f336c64cff (patch)
tree7465b5f59b8616d6c22100b74cf923228328e231 /youtube_dl/downloader/http.py
parent25a4c5a9ed59eca0241922363e83e61172527658 (diff)
downloadyoutube-dl-d7d2a9a3dbf1cef78c5085a4aab5d2f336c64cff.tar.gz
youtube-dl-d7d2a9a3dbf1cef78c5085a4aab5d2f336c64cff.tar.xz
youtube-dl-d7d2a9a3dbf1cef78c5085a4aab5d2f336c64cff.zip
[utils] restart download if server does not support byte ranges
Diffstat (limited to 'youtube_dl/downloader/http.py')
-rw-r--r--youtube_dl/downloader/http.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/youtube_dl/downloader/http.py b/youtube_dl/downloader/http.py
index b7f144af9..b2e82cfde 100644
--- a/youtube_dl/downloader/http.py
+++ b/youtube_dl/downloader/http.py
@@ -57,6 +57,20 @@ class HttpFD(FileDownloader):
             # Establish connection
             try:
                 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
             except (compat_urllib_error.HTTPError, ) as err:
                 if (err.code < 500 or err.code >= 600) and err.code != 416: