diff --git a/coub-dl.py b/coub-dl.py index 20cb0b0..1ce16c4 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -7,6 +7,7 @@ from datetime import timedelta from math import floor from argparse import ArgumentParser from functools import wraps +from atexit import register @@ -95,6 +96,15 @@ def mux_streams(): stdout=DEVNULL, stderr=DEVNULL) +def cleanup(): + try: + for key in FILES: + if key not in OUTPUT_KEYS: + remove(FILES[key]) + except FileNotFoundError: + pass + + def yes_no_question(question, default): valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} @@ -119,6 +129,10 @@ def yes_no_question(question, default): +# clean up on exit +register(cleanup) + + # parse arguments parser = ArgumentParser(description='Download player-looped videos with youtube-dl & ffmpeg.') parser.add_argument('-nv', '--nonverbose', action='store_true', help='Turn off non-critical messages to user.') @@ -185,8 +199,3 @@ with open(FILES[File.LIST], 'w') as f: loop_shorter_stream() mux_streams() - -# cleanup -for key in FILES: - if key not in OUTPUT_KEYS: - remove(FILES[key])