diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 8e8546596..57c49fe2b 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -41,6 +41,7 @@ from .compat import ( compat_urllib_error, compat_urllib_request, compat_urllib_request_DataHandler, + Forbidden403 ) from .utils import ( age_restricted, @@ -825,6 +826,10 @@ class YoutubeDL(object): self.report_error(compat_str(e), e.format_traceback()) except MaxDownloadsReached: raise + except Forbidden403: + # Lets not abuse of this 😜 we don't want to get brutal on the server + time.sleep(random.randint(3, 13)) + wrapper(self, *args, **kwargs) except Exception as e: if self.params.get('ignoreerrors', False): self.report_error(error_to_compat_str(e), tb=encode_compat_str(traceback.format_exc())) diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index 28942a8c1..c9b50a2f6 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -3094,6 +3094,11 @@ else: return ctypes.WINFUNCTYPE(*args, **kwargs) +# Implement an error for which it is raise when error code 403 HTTPError +class Forbidden403(Exception): + pass + + __all__ = [ 'compat_HTMLParseError', 'compat_HTMLParser', diff --git a/youtube_dl/downloader/http.py b/youtube_dl/downloader/http.py index d8ac41dcc..86d6f3441 100644 --- a/youtube_dl/downloader/http.py +++ b/youtube_dl/downloader/http.py @@ -11,6 +11,7 @@ from .common import FileDownloader from ..compat import ( compat_str, compat_urllib_error, + Forbidden403 ) from ..utils import ( ContentTooShortError, @@ -183,9 +184,11 @@ class HttpFD(FileDownloader): ctx.resume_len = 0 ctx.open_mode = 'wb' return - elif err.code < 500 or err.code >= 600: + elif err.code != 403 and (err.code < 500 or err.code >= 600): # Unexpected HTTP error raise + elif err.code == 403: # The famous 403 Forbidden error + raise Forbidden403 raise RetryDownload(err) except socket.error as err: if err.errno != errno.ECONNRESET: