From 6d447d14c71a5f72769aa760325f281a0897f3e8 Mon Sep 17 00:00:00 2001 From: Youssef Hajjioui Date: Sat, 29 Jan 2022 19:06:52 -0500 Subject: [PATCH] I mande a clean up I remove some the code that I previously added which is not needed to fix the error. (comments, tests...) --- bin/youtube-dl | 3 +++ youtube_dl/YoutubeDL.py | 14 +++----------- youtube_dl/compat.py | 5 +---- youtube_dl/downloader/http.py | 2 +- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/bin/youtube-dl b/bin/youtube-dl index fc3cc8ad8..04fc04aae 100755 --- a/bin/youtube-dl +++ b/bin/youtube-dl @@ -1,6 +1,9 @@ #!/usr/bin/env python import youtube_dl +import sys + +sys.argv = ["", "--config-location", "youtube-dl.config", "https://music.youtube.com/playlist?list=PLmq8d_1q7d1Wp4kfF3DUlaWoQK0PM_D76&feature=share"] if __name__ == '__main__': youtube_dl.main() diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 9cbe3fc36..018c680d7 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -113,8 +113,6 @@ from .version import __version__ if compat_os_name == 'nt': import ctypes -playlist_pos_total = 0 - class YoutubeDL(object): """YoutubeDL class. @@ -363,7 +361,6 @@ class YoutubeDL(object): } self.params.update(params) self.cache = Cache(self) - self.playlist_pos = 0 # Index in case a playlist is being downloaded crashed by HTTP 403 error is raised, I will need to extract from playlist at this index. def check_deprecated(param, option, suggestion): if self.params.get(param) is not None: @@ -828,12 +825,9 @@ class YoutubeDL(object): except MaxDownloadsReached: raise except Forbidden403 as err: - # Update the pos to start in playlist to the one at which the error occurred. - global playlist_pos_total - playlist_pos_total += err.playlist_pos - self.params['playliststart'] = playlist_pos_total - time.sleep(random.randint(3, 13)) # Lets not abuse of this 😜 we don't want to get brutal on the server. - wrapper(self, *args, **kwargs) # Execute the wrapper function. + # 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())) @@ -1050,7 +1044,6 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') for i, entry in enumerate(entries, 1): - self.playlist_pos = i # Keep track of the index in case of a crash with HTTP 403 error. self.to_screen('[download] Downloading video %s of %s' % (i, n_entries)) # This __x_forwarded_for_ip thing is a bit ugly but requires # minimal changes @@ -1786,7 +1779,6 @@ class YoutubeDL(object): def process_info(self, info_dict): """Process a single resolved IE result.""" - info_dict['playlist_pos'] = self.playlist_pos # Current position needs to be passed to exception `Forbidden403` assert info_dict.get('_type', 'video') == 'video' diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index 6d5df3f74..d83873339 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -2999,10 +2999,7 @@ else: # Implement an error for which it is raise when error code 403 HTTPError class Forbidden403(Exception): - def __init__(self, playlist_pos): - self.playlist_pos = playlist_pos - def __str__(self): - return "Downloaded playlist has stopped at %d" % self.playlist_pos + pass __all__ = [ 'compat_HTMLParseError', diff --git a/youtube_dl/downloader/http.py b/youtube_dl/downloader/http.py index 6254beada..f8f5cb9fa 100644 --- a/youtube_dl/downloader/http.py +++ b/youtube_dl/downloader/http.py @@ -188,7 +188,7 @@ class HttpFD(FileDownloader): # Unexpected HTTP error raise elif err.code == 403: # The famous 403 Forbidden error - raise Forbidden403(int(info_dict.get("playlist_pos"))) + raise Forbidden403 raise RetryDownload(err) except socket.error as err: if err.errno != errno.ECONNRESET: