mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2025-08-23 14:45:49 -07:00
I mande a clean up
I remove some the code that I previously added which is not needed to fix the error. (comments, tests...)
This commit is contained in:
parent
dcb656f8c6
commit
6d447d14c7
4 changed files with 8 additions and 16 deletions
|
@ -1,6 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import youtube_dl
|
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__':
|
if __name__ == '__main__':
|
||||||
youtube_dl.main()
|
youtube_dl.main()
|
||||||
|
|
|
@ -113,8 +113,6 @@ from .version import __version__
|
||||||
if compat_os_name == 'nt':
|
if compat_os_name == 'nt':
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
playlist_pos_total = 0
|
|
||||||
|
|
||||||
class YoutubeDL(object):
|
class YoutubeDL(object):
|
||||||
"""YoutubeDL class.
|
"""YoutubeDL class.
|
||||||
|
|
||||||
|
@ -363,7 +361,6 @@ class YoutubeDL(object):
|
||||||
}
|
}
|
||||||
self.params.update(params)
|
self.params.update(params)
|
||||||
self.cache = Cache(self)
|
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):
|
def check_deprecated(param, option, suggestion):
|
||||||
if self.params.get(param) is not None:
|
if self.params.get(param) is not None:
|
||||||
|
@ -828,12 +825,9 @@ class YoutubeDL(object):
|
||||||
except MaxDownloadsReached:
|
except MaxDownloadsReached:
|
||||||
raise
|
raise
|
||||||
except Forbidden403 as err:
|
except Forbidden403 as err:
|
||||||
# Update the pos to start in playlist to the one at which the error occurred.
|
# Lets not abuse of this 😜 we don't want to get brutal on the server
|
||||||
global playlist_pos_total
|
time.sleep(random.randint(3, 13))
|
||||||
playlist_pos_total += err.playlist_pos
|
wrapper(self, *args, **kwargs)
|
||||||
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.
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.params.get('ignoreerrors', False):
|
if self.params.get('ignoreerrors', False):
|
||||||
self.report_error(error_to_compat_str(e), tb=encode_compat_str(traceback.format_exc()))
|
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')
|
x_forwarded_for = ie_result.get('__x_forwarded_for_ip')
|
||||||
|
|
||||||
for i, entry in enumerate(entries, 1):
|
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))
|
self.to_screen('[download] Downloading video %s of %s' % (i, n_entries))
|
||||||
# This __x_forwarded_for_ip thing is a bit ugly but requires
|
# This __x_forwarded_for_ip thing is a bit ugly but requires
|
||||||
# minimal changes
|
# minimal changes
|
||||||
|
@ -1786,7 +1779,6 @@ class YoutubeDL(object):
|
||||||
|
|
||||||
def process_info(self, info_dict):
|
def process_info(self, info_dict):
|
||||||
"""Process a single resolved IE result."""
|
"""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'
|
assert info_dict.get('_type', 'video') == 'video'
|
||||||
|
|
||||||
|
|
|
@ -2999,10 +2999,7 @@ else:
|
||||||
|
|
||||||
# Implement an error for which it is raise when error code 403 HTTPError
|
# Implement an error for which it is raise when error code 403 HTTPError
|
||||||
class Forbidden403(Exception):
|
class Forbidden403(Exception):
|
||||||
def __init__(self, playlist_pos):
|
pass
|
||||||
self.playlist_pos = playlist_pos
|
|
||||||
def __str__(self):
|
|
||||||
return "Downloaded playlist has stopped at %d" % self.playlist_pos
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'compat_HTMLParseError',
|
'compat_HTMLParseError',
|
||||||
|
|
|
@ -188,7 +188,7 @@ class HttpFD(FileDownloader):
|
||||||
# Unexpected HTTP error
|
# Unexpected HTTP error
|
||||||
raise
|
raise
|
||||||
elif err.code == 403: # The famous 403 Forbidden error
|
elif err.code == 403: # The famous 403 Forbidden error
|
||||||
raise Forbidden403(int(info_dict.get("playlist_pos")))
|
raise Forbidden403
|
||||||
raise RetryDownload(err)
|
raise RetryDownload(err)
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
if err.errno != errno.ECONNRESET:
|
if err.errno != errno.ECONNRESET:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue