Retry until error or downloaded
This commit is contained in:
parent
50a252d3b7
commit
72f7072d1d
1 changed files with 44 additions and 82 deletions
|
@ -378,92 +378,54 @@ 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:
|
||||||
try:
|
result = 'pending'
|
||||||
uri=f"https://www.youtube.com/watch?v={video_id}"
|
while result != 'downloaded' and result != 'error':
|
||||||
return_code = ydl.download(uri)
|
try:
|
||||||
self._process_download(
|
uri=f"https://www.youtube.com/watch?v={video_id}"
|
||||||
{
|
return_code = ydl.download(uri)
|
||||||
"return_code": return_code,
|
self._process_download(
|
||||||
'info_dict': {
|
{
|
||||||
'id': video_id,
|
"return_code": return_code,
|
||||||
},
|
'info_dict': {
|
||||||
'filename': video_info.get('title', '?'),
|
'id': video_id,
|
||||||
'video_info': video_info,
|
},
|
||||||
}
|
'filename': video_info.get('title', '?'),
|
||||||
)
|
'video_info': video_info,
|
||||||
except yt_dlp.utils.DownloadError as error:
|
}
|
||||||
if 'Requested format is not available' in f"{error}":
|
|
||||||
self._log.warning(
|
|
||||||
"Requested format is not available, trying best format."
|
|
||||||
)
|
)
|
||||||
ydl_opts['format'] = 'bestvideo+bestaudio[ext=m4a]/best'
|
result = 'downloaded'
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
self.summary['downloaded_videos_titles'].append(
|
||||||
try:
|
video_info.get('title', '?')
|
||||||
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}":
|
|
||||||
subtitle_match = re.match(
|
|
||||||
r"Unable to download video subtitles for '([a-z]*)' ",
|
|
||||||
f"{error}"
|
|
||||||
)
|
)
|
||||||
if not subtitle_match:
|
self.summary['downloaded_videos'] += 1
|
||||||
self._log.error(
|
except yt_dlp.utils.DownloadError as error:
|
||||||
f"Error finding subtitle that failed in error string"
|
if 'Requested format is not available' in f"{error}":
|
||||||
|
self._log.warning(
|
||||||
|
"Requested format is not available, trying best format."
|
||||||
)
|
)
|
||||||
|
ydl_opts['format'] = 'bestvideo+bestaudio[ext=m4a]/best'
|
||||||
|
result = 'retrying (format error)'
|
||||||
|
elif 'Unable to download video subtitles for' in f"{error}":
|
||||||
|
subtitle_match = re.match(
|
||||||
|
r"Unable to download video subtitles for '([a-z]*)' ",
|
||||||
|
f"{error}"
|
||||||
|
)
|
||||||
|
if not subtitle_match:
|
||||||
|
self._log.error(
|
||||||
|
f"Error finding subtitle that failed in error string"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
ydl_opts['subtitleslangs'].pop(subtitle_match.group(1))
|
||||||
|
result = 'retrying (subtitles error)'
|
||||||
else:
|
else:
|
||||||
ydl_opts['subtitleslangs'].pop(subtitle_match.group(1))
|
self._log.error(
|
||||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
"Error getting video with proxy '%s'. %s",
|
||||||
try:
|
self.selected_proxy,
|
||||||
uri=f"https://www.youtube.com/watch?v={video_id}"
|
error
|
||||||
return_code = ydl.download(uri)
|
)
|
||||||
self._process_download(
|
self.summary['videos_with_error'] += 1
|
||||||
{
|
result = error
|
||||||
"return_code": return_code,
|
continue
|
||||||
'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:
|
|
||||||
self._log.error(
|
|
||||||
"Error getting video with proxy '%s'. %s",
|
|
||||||
self.selected_proxy,
|
|
||||||
error
|
|
||||||
)
|
|
||||||
self.summary['videos_with_error'] += 1
|
|
||||||
break
|
|
||||||
self.summary['downloaded_videos_titles'].append(
|
|
||||||
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",
|
||||||
|
|
Loading…
Reference in a new issue