Manage proxies
This commit is contained in:
parent
ab1bc5af92
commit
70e8f9c048
1 changed files with 29 additions and 11 deletions
|
@ -76,6 +76,20 @@ class GetYoutubeVideos:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _change_proxy(self, video_id):
|
||||||
|
if len(self.config['proxy']) > 0:
|
||||||
|
if self.proxy_index<len(self.config['proxy']):
|
||||||
|
self._log.warning(
|
||||||
|
"Got an error fetching video information. Setting proxy to '%s'...",
|
||||||
|
self.selected_proxy
|
||||||
|
)
|
||||||
|
self.selected_proxy = self.config['proxy'][self.proxy_index]
|
||||||
|
self.proxy_index += 1
|
||||||
|
return self._get_video_info(video_id)
|
||||||
|
self.proxy_index = 0
|
||||||
|
self.selected_proxy = ''
|
||||||
|
return None
|
||||||
|
|
||||||
def _get_video_info(self, video_id):
|
def _get_video_info(self, video_id):
|
||||||
uri=f"https://www.youtube.com/watch?v={video_id}"
|
uri=f"https://www.youtube.com/watch?v={video_id}"
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
|
@ -88,31 +102,35 @@ class GetYoutubeVideos:
|
||||||
try:
|
try:
|
||||||
raw_video_info = ydl.extract_info(uri, download=False)
|
raw_video_info = ydl.extract_info(uri, download=False)
|
||||||
except yt_dlp.utils.DownloadError as error:
|
except yt_dlp.utils.DownloadError as error:
|
||||||
self._log.debug(
|
|
||||||
"Skipping video. Error: %s",
|
|
||||||
error
|
|
||||||
)
|
|
||||||
if 'The uploader has not made this video available in your country' in f"{error}":
|
if 'The uploader has not made this video available in your country' in f"{error}":
|
||||||
self.summary['videos_with_error'] += 1
|
self.summary['videos_with_error'] += 1
|
||||||
|
result = self._change_proxy(video_id)
|
||||||
|
if not result:
|
||||||
|
return None
|
||||||
|
return result
|
||||||
elif 'HTTP Error 403: Forbidden' in f"{error}":
|
elif 'HTTP Error 403: Forbidden' in f"{error}":
|
||||||
self.summary['videos_with_error'] += 1
|
self.summary['videos_with_error'] += 1
|
||||||
self.summary['possible_proxy_errors'] += 1
|
self.summary['possible_proxy_errors'] += 1
|
||||||
if len(self.config['proxy']) > 0:
|
result = self._change_proxy(video_id)
|
||||||
if self.proxy_index<len(self.config['proxy']):
|
if not result:
|
||||||
self.selected_proxy = self.config['proxy'][self.proxy_index]
|
|
||||||
self.proxy_index += 1
|
|
||||||
return self._get_video_info(video_id)
|
|
||||||
self.proxy_index = 0
|
|
||||||
self.selected_proxy = ''
|
|
||||||
return None
|
return None
|
||||||
|
return result
|
||||||
elif 'not a bot' in f"{error}":
|
elif 'not a bot' in f"{error}":
|
||||||
self.summary['videos_with_error'] += 1
|
self.summary['videos_with_error'] += 1
|
||||||
self.summary['possible_ban_errors'] += 1
|
self.summary['possible_ban_errors'] += 1
|
||||||
# elif age_limit_errors?
|
# elif age_limit_errors?
|
||||||
|
result = self._change_proxy(video_id)
|
||||||
|
if not result:
|
||||||
|
return None
|
||||||
|
return result
|
||||||
elif 'This live event will begin in a few moments' in f"{error}":
|
elif 'This live event will begin in a few moments' in f"{error}":
|
||||||
self.summary['skipped_videos'] += 1
|
self.summary['skipped_videos'] += 1
|
||||||
else:
|
else:
|
||||||
self.summary['skipped_videos'] += 1
|
self.summary['skipped_videos'] += 1
|
||||||
|
self._log.debug(
|
||||||
|
"Skipping video. Error: %s",
|
||||||
|
error
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
video_info = ydl.sanitize_info(raw_video_info)
|
video_info = ydl.sanitize_info(raw_video_info)
|
||||||
return video_info
|
return video_info
|
||||||
|
|
Loading…
Reference in a new issue