Remove leftover files after failed downloads

This commit is contained in:
vitiko98 2020-12-19 15:29:26 -04:00
parent ae7fa70118
commit 0ded90c0f8
3 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import base64 import base64
import configparser import configparser
import logging import logging
import glob
import os import os
import sys import sys
@ -64,6 +65,15 @@ def reset_config(config_file):
) )
def remove_leftovers(directory):
directory = os.path.join(directory, "**", ".*.tmp")
for i in glob.glob(directory, recursive=True):
try:
os.remove(i)
except: # noqa
pass
def main(): def main():
if not os.path.isdir(CONFIG_PATH) or not os.path.isfile(CONFIG_FILE): if not os.path.isdir(CONFIG_PATH) or not os.path.isfile(CONFIG_FILE):
os.makedirs(CONFIG_PATH, exist_ok=True) os.makedirs(CONFIG_PATH, exist_ok=True)
@ -127,12 +137,16 @@ def main():
else: else:
qobuz.interactive_limit = arguments.limit qobuz.interactive_limit = arguments.limit
qobuz.interactive() qobuz.interactive()
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info( logging.info(
f"{RED}Interrupted by user\n{YELLOW}Already downloaded items will " f"{RED}Interrupted by user\n{YELLOW}Already downloaded items will "
"be skipped if you try to download the same releases again" "be skipped if you try to download the same releases again"
) )
finally:
remove_leftovers(qobuz.directory)
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(main()) sys.exit(main())

View File

@ -1,5 +1,6 @@
import logging import logging
import os import os
import glob
import re import re
import string import string
import sys import sys

View File

@ -137,7 +137,7 @@ def download_and_tag(
root_dir = os.path.join(root_dir, "Disc " + str(multiple)) root_dir = os.path.join(root_dir, "Disc " + str(multiple))
os.makedirs(root_dir, exist_ok=True) os.makedirs(root_dir, exist_ok=True)
filename = os.path.join(root_dir, ".{:02}".format(tmp_count) + extension) filename = os.path.join(root_dir, ".{:02}.tmp".format(tmp_count))
new_track_title = sanitize_filename(track_metadata["title"]) new_track_title = sanitize_filename(track_metadata["title"])
track_file = "{:02}. {}{}".format( track_file = "{:02}. {}{}".format(