Process download aside

This commit is contained in:
Antonio J. Delgado 2024-12-12 16:11:10 +02:00
parent 8bf27630c7
commit e94f2d9eed

View file

@ -202,7 +202,17 @@ class GetYoutubeVideos:
} }
with yt_dlp.YoutubeDL(ydl_opts) as ydl: with yt_dlp.YoutubeDL(ydl_opts) as ydl:
try: try:
ydl.download(uri) 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 error: except yt_dlp.utils.DownloadError as error:
self._log.error( self._log.error(
"Error getting video. %s", "Error getting video. %s",
@ -227,8 +237,8 @@ class GetYoutubeVideos:
self.summary['processed_channels'] = self.channels_count self.summary['processed_channels'] = self.channels_count
self.summary['total_count'] = self.total_count self.summary['total_count'] = self.total_count
def _yt_progress_hook(self, data):
if data['status'] == 'finished': def _process_download(self, data):
self.total_count += 1 self.total_count += 1
self.channel_count += 1 self.channel_count += 1
if self.total_count == self.config['total_limit']: if self.total_count == self.config['total_limit']:
@ -253,6 +263,11 @@ class GetYoutubeVideos:
json.dump(data, info_file, indent=2) json.dump(data, info_file, indent=2)
if 'id' in data['info_dict']: if 'id' in data['info_dict']:
self._save_downloaded_items(data['info_dict']['id']) self._save_downloaded_items(data['info_dict']['id'])
def _yt_progress_hook(self, data):
if data['status'] == 'finished':
self._process_download(data)
elif data['status'] == 'downloading': elif data['status'] == 'downloading':
downloading = True downloading = True
else: else: