better logging
This commit is contained in:
parent
14f3914574
commit
50924c5552
|
@ -375,26 +375,40 @@ while True:
|
||||||
if result['downloaded_video_id']:
|
if result['downloaded_video_id']:
|
||||||
download_archive_logger.info(result['downloaded_video_id'])
|
download_archive_logger.info(result['downloaded_video_id'])
|
||||||
|
|
||||||
# Print stuff
|
# Print short error messages.
|
||||||
for line in result['video_error_logger_msg']:
|
# An error should never be added to both video_critical_err_msg_short and video_critical_err_msg.
|
||||||
file_msg = f"{result['video_id']} - {ansi_escape_regex.sub('', line)}"
|
for line in result['video_critical_err_msg_short']:
|
||||||
term_msg = f"{result['video_id']} - {line}"
|
# file_msg = f"{result['video_id']} - {ansi_escape_regex.sub('', line)}"
|
||||||
video_error_logger.error(file_msg)
|
# term_msg = f"{result['video_id']} - {line}"
|
||||||
file_logger.error(file_msg)
|
msg = f"{result['video_id']} - {line}"
|
||||||
|
video_error_logger.error(msg)
|
||||||
|
file_logger.error(msg)
|
||||||
|
encountered_errors += 1
|
||||||
|
if args.daemon:
|
||||||
|
logger.error(msg)
|
||||||
|
else:
|
||||||
|
status_bar.write(msg)
|
||||||
|
|
||||||
|
# Print longer error messages.
|
||||||
|
# Won't print anything to console if the silence_errors arg is set.
|
||||||
|
for line in result['video_critical_err_msg']:
|
||||||
|
# file_msg = f"{result['video_id']} - {ansi_escape_regex.sub('', line)}"
|
||||||
|
# term_msg = f"{result['video_id']} - {line}"
|
||||||
|
msg = f"{result['video_id']} - {line}"
|
||||||
|
video_error_logger.error(msg)
|
||||||
|
file_logger.error(msg)
|
||||||
encountered_errors += 1
|
encountered_errors += 1
|
||||||
if not args.silence_errors:
|
if not args.silence_errors:
|
||||||
if args.daemon:
|
if args.daemon:
|
||||||
logger.error(term_msg)
|
logger.error(msg)
|
||||||
else:
|
else:
|
||||||
status_bar.write(term_msg)
|
status_bar.write(msg)
|
||||||
|
|
||||||
if len(result['video_error_logger_msg']):
|
# if len(result['video_critical_err_msg']):
|
||||||
errored_videos += 1
|
# errored_videos += 1
|
||||||
if args.silence_errors and args.daemon:
|
# if args.silence_errors and args.daemon:
|
||||||
logger.error(f"{result['video_id']} - Failed due to error.")
|
# logger.error(f"{result['video_id']} - Failed due to error.")
|
||||||
|
|
||||||
# for line in result['status_msg']:
|
|
||||||
# playlist_bar.write(line)
|
|
||||||
for line in result['logger_msg']:
|
for line in result['logger_msg']:
|
||||||
log_info_twice(line)
|
log_info_twice(line)
|
||||||
playlist_bar.update()
|
playlist_bar.update()
|
||||||
|
|
|
@ -70,14 +70,14 @@ def download_video(args) -> dict:
|
||||||
|
|
||||||
video = args[0]
|
video = args[0]
|
||||||
kwargs = args[1]
|
kwargs = args[1]
|
||||||
output_dict = {'downloaded_video_id': None, 'video_id': video['id'], 'video_error_logger_msg': [], 'status_msg': [], 'logger_msg': []} # empty object
|
output_dict = {'downloaded_video_id': None, 'video_id': video['id'], 'video_critical_err_msg': [], 'video_critical_err_msg_short': [], 'status_msg': [], 'logger_msg': []} # empty object
|
||||||
|
|
||||||
if not kwargs['ignore_downloaded'] and not video['channel_id'] or not video['channel'] or not video['channel_url']:
|
if not kwargs['ignore_downloaded'] and not video['channel_id'] or not video['channel'] or not video['channel_url']:
|
||||||
if video['duration'] or isinstance(video['view_count'], int):
|
if video['duration'] or isinstance(video['view_count'], int):
|
||||||
# Sometimes videos don't have channel_id, channel, or channel_url but are actually valid. Like shorts.
|
# Sometimes videos don't have channel_id, channel, or channel_url but are actually valid. Like shorts.
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
output_dict['video_error_logger_msg'].append(f"{video['id']} unavailable.")
|
output_dict['video_critical_err_msg_short'].append('unavailable.')
|
||||||
return output_dict
|
return output_dict
|
||||||
|
|
||||||
# Get a bar
|
# Get a bar
|
||||||
|
@ -101,7 +101,7 @@ def download_video(args) -> dict:
|
||||||
yt_dlp = ydl.YDL(kwargs['ydl_opts'])
|
yt_dlp = ydl.YDL(kwargs['ydl_opts'])
|
||||||
video_n = yt_dlp.get_info(video['url'])
|
video_n = yt_dlp.get_info(video['url'])
|
||||||
if not video_n:
|
if not video_n:
|
||||||
output_dict['video_error_logger_msg'].append(f"{video['id']} failed to get info.")
|
output_dict['video_critical_err_msg_short'].append('failed to get info.')
|
||||||
return output_dict
|
return output_dict
|
||||||
video_n['url'] = video['url']
|
video_n['url'] = video['url']
|
||||||
video = video_n
|
video = video_n
|
||||||
|
@ -121,9 +121,9 @@ def download_video(args) -> dict:
|
||||||
output_dict['logger_msg'].append(f"{video['id']} '{video['title']}' downloaded in {elapsed} min.")
|
output_dict['logger_msg'].append(f"{video['id']} '{video['title']}' downloaded in {elapsed} min.")
|
||||||
output_dict['downloaded_video_id'] = video['id']
|
output_dict['downloaded_video_id'] = video['id']
|
||||||
else:
|
else:
|
||||||
output_dict['video_error_logger_msg'] = output_dict['video_error_logger_msg'] + ylogger.errors
|
output_dict['video_critical_err_msg'] = output_dict['video_critical_err_msg'] + ylogger.errors
|
||||||
except Exception:
|
except Exception:
|
||||||
output_dict['video_error_logger_msg'].append(f"EXCEPTION -> {traceback.format_exc()}")
|
output_dict['video_critical_err_msg'].append(f"EXCEPTION -> {traceback.format_exc()}")
|
||||||
if locked:
|
if locked:
|
||||||
bar.update(100 - bar.n)
|
bar.update(100 - bar.n)
|
||||||
if locked:
|
if locked:
|
||||||
|
|
Reference in New Issue