better logging

This commit is contained in:
Cyberes 2023-02-07 19:50:45 -07:00
parent 9912683db4
commit 914e6ce92e
2 changed files with 4 additions and 3 deletions

View File

@ -409,7 +409,7 @@ while True:
# logger.error(f"{result['video_id']} - Failed due to error.")
for line in result['logger_msg']:
log_info_twice(line)
log_info_twice(f"{result['video_id']} - {line}")
playlist_bar.update()
else:
status_bar.write(f"All videos already downloaded for '{playlist['title']}'.")

View File

@ -110,17 +110,18 @@ def download_video(args) -> dict:
try:
base_path = os.path.splitext(unidecode(yt_dlp.prepare_filename(video)))[0]
video['outtmpl'] = f"{kwargs['output_path']}/{ydl.get_output_templ(title=unidecode(video['title']), uploader=unidecode(video['uploader']))}" # clean the filename
video['outtmpl'] = f"{kwargs['output_dir']}/{ydl.get_output_templ(title=unidecode(video['title']), uploader=unidecode(video['uploader']))}" # clean the filename
except AttributeError:
# Sometimes we won't be able to pull the video info so just use the video's ID.
base_path = kwargs['output_dir'] / video['id']
video['outtmpl'] = f"{kwargs['output_dir']}/{ydl.get_output_templ()}"
ylogger = ytdl_logger(setup_file_logger(video['id'], str(base_path) + '.log'))
kwargs['ydl_opts']['logger'] = ylogger
yt_dlp = ydl.YDL(kwargs['ydl_opts']) # recreate the object with the correct logging path
error_code = yt_dlp(video['url']) # Do the download
if not error_code:
elapsed = round(math.ceil(time.time() - start_time) / 60, 2)
output_dict['logger_msg'].append(f"{video['id']} '{video['title']}' downloaded in {elapsed} min.")
output_dict['logger_msg'].append(f"'{video['title']}' - Downloaded in {elapsed} min.")
output_dict['downloaded_video_id'] = video['id']
else:
output_dict['video_critical_err_msg'] = output_dict['video_critical_err_msg'] + ylogger.errors