Process download aside
This commit is contained in:
parent
8bf27630c7
commit
e94f2d9eed
1 changed files with 40 additions and 25 deletions
|
@ -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,32 +237,37 @@ 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 _process_download(self, data):
|
||||||
|
self.total_count += 1
|
||||||
|
self.channel_count += 1
|
||||||
|
if self.total_count == self.config['total_limit']:
|
||||||
|
self._log.info(
|
||||||
|
"Limit (%s) reached for videos from all channels",
|
||||||
|
self.config['total_limit'],
|
||||||
|
)
|
||||||
|
sys.exit(0)
|
||||||
|
if self.channel_count == self.config['channel_limit']:
|
||||||
|
self._log.info(
|
||||||
|
"Limit (%s) reached for videos for this channel '%s'",
|
||||||
|
self.config['channel_limit'],
|
||||||
|
data['info_dict'].get('channel', '?')
|
||||||
|
)
|
||||||
|
# break
|
||||||
|
info_filename = os.path.join(self.config['download_dir'], f"{os.path.basename(data['filename'])}.download_info.json")
|
||||||
|
self._log.debug(
|
||||||
|
"Writting download information in to file '%s'",
|
||||||
|
info_filename
|
||||||
|
)
|
||||||
|
with open(info_filename, 'w', encoding='utf-8') as info_file:
|
||||||
|
json.dump(data, info_file, indent=2)
|
||||||
|
if 'id' in data['info_dict']:
|
||||||
|
self._save_downloaded_items(data['info_dict']['id'])
|
||||||
|
|
||||||
|
|
||||||
def _yt_progress_hook(self, data):
|
def _yt_progress_hook(self, data):
|
||||||
if data['status'] == 'finished':
|
if data['status'] == 'finished':
|
||||||
self.total_count += 1
|
self._process_download(data)
|
||||||
self.channel_count += 1
|
|
||||||
if self.total_count == self.config['total_limit']:
|
|
||||||
self._log.info(
|
|
||||||
"Limit (%s) reached for videos from all channels",
|
|
||||||
self.config['total_limit'],
|
|
||||||
)
|
|
||||||
sys.exit(0)
|
|
||||||
if self.channel_count == self.config['channel_limit']:
|
|
||||||
self._log.info(
|
|
||||||
"Limit (%s) reached for videos for this channel '%s'",
|
|
||||||
self.config['channel_limit'],
|
|
||||||
data['info_dict'].get('channel', '?')
|
|
||||||
)
|
|
||||||
# break
|
|
||||||
info_filename = os.path.join(self.config['download_dir'], f"{os.path.basename(data['filename'])}.download_info.json")
|
|
||||||
self._log.debug(
|
|
||||||
"Writting download information in to file '%s'",
|
|
||||||
info_filename
|
|
||||||
)
|
|
||||||
with open(info_filename, 'w', encoding='utf-8') as info_file:
|
|
||||||
json.dump(data, info_file, indent=2)
|
|
||||||
if 'id' in data['info_dict']:
|
|
||||||
self._save_downloaded_items(data['info_dict']['id'])
|
|
||||||
elif data['status'] == 'downloading':
|
elif data['status'] == 'downloading':
|
||||||
downloading = True
|
downloading = True
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue