Retry until error or downloaded

This commit is contained in:
Antonio J. Delgado 2025-08-10 11:52:14 +03:00
parent 50a252d3b7
commit 72f7072d1d

View file

@ -378,6 +378,8 @@ class GetYoutubeVideos:
if self.selected_proxy != '': if self.selected_proxy != '':
ydl_opts['proxy'] = self.selected_proxy ydl_opts['proxy'] = self.selected_proxy
with yt_dlp.YoutubeDL(ydl_opts) as ydl: with yt_dlp.YoutubeDL(ydl_opts) as ydl:
result = 'pending'
while result != 'downloaded' and result != 'error':
try: try:
uri=f"https://www.youtube.com/watch?v={video_id}" uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri) return_code = ydl.download(uri)
@ -391,34 +393,18 @@ class GetYoutubeVideos:
'video_info': video_info, 'video_info': video_info,
} }
) )
result = 'downloaded'
self.summary['downloaded_videos_titles'].append(
video_info.get('title', '?')
)
self.summary['downloaded_videos'] += 1
except yt_dlp.utils.DownloadError as error: except yt_dlp.utils.DownloadError as error:
if 'Requested format is not available' in f"{error}": if 'Requested format is not available' in f"{error}":
self._log.warning( self._log.warning(
"Requested format is not available, trying best format." "Requested format is not available, trying best format."
) )
ydl_opts['format'] = 'bestvideo+bestaudio[ext=m4a]/best' ydl_opts['format'] = 'bestvideo+bestaudio[ext=m4a]/best'
with yt_dlp.YoutubeDL(ydl_opts) as ydl: result = 'retrying (format error)'
try:
uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri)
self._process_download(
{
"return_code": return_code,
'info_dict': {
'id': video_id,
},
'filename': video_info.get('title', '?'),
'video_info': video_info,
}
)
except yt_dlp.utils.DownloadError as sub_error:
self._log.error(
"Error getting video with proxy '%s'. %s",
self.selected_proxy,
sub_error
)
self.summary['videos_with_error'] += 1
break
elif 'Unable to download video subtitles for' in f"{error}": elif 'Unable to download video subtitles for' in f"{error}":
subtitle_match = re.match( subtitle_match = re.match(
r"Unable to download video subtitles for '([a-z]*)' ", r"Unable to download video subtitles for '([a-z]*)' ",
@ -430,28 +416,7 @@ class GetYoutubeVideos:
) )
else: else:
ydl_opts['subtitleslangs'].pop(subtitle_match.group(1)) ydl_opts['subtitleslangs'].pop(subtitle_match.group(1))
with yt_dlp.YoutubeDL(ydl_opts) as ydl: result = 'retrying (subtitles error)'
try:
uri=f"https://www.youtube.com/watch?v={video_id}"
return_code = ydl.download(uri)
self._process_download(
{
"return_code": return_code,
'info_dict': {
'id': video_id,
},
'filename': video_info.get('title', '?'),
'video_info': video_info,
}
)
except yt_dlp.utils.DownloadError as sub_error:
self._log.error(
"Error getting video with proxy '%s'. %s",
self.selected_proxy,
sub_error
)
self.summary['videos_with_error'] += 1
break
else: else:
self._log.error( self._log.error(
"Error getting video with proxy '%s'. %s", "Error getting video with proxy '%s'. %s",
@ -459,11 +424,8 @@ class GetYoutubeVideos:
error error
) )
self.summary['videos_with_error'] += 1 self.summary['videos_with_error'] += 1
break result = error
self.summary['downloaded_videos_titles'].append( continue
video_info.get('title', '?')
)
self.summary['downloaded_videos'] += 1
else: else:
self._log.debug( self._log.debug(
"Video with ID '%s' has been already downloaded", "Video with ID '%s' has been already downloaded",