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 configparser
import logging
import glob
import os
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():
if not os.path.isdir(CONFIG_PATH) or not os.path.isfile(CONFIG_FILE):
os.makedirs(CONFIG_PATH, exist_ok=True)
@ -127,12 +137,16 @@ def main():
else:
qobuz.interactive_limit = arguments.limit
qobuz.interactive()
except KeyboardInterrupt:
logging.info(
f"{RED}Interrupted by user\n{YELLOW}Already downloaded items will "
"be skipped if you try to download the same releases again"
)
finally:
remove_leftovers(qobuz.directory)
if __name__ == "__main__":
sys.exit(main())

View File

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

View File

@ -137,7 +137,7 @@ def download_and_tag(
root_dir = os.path.join(root_dir, "Disc " + str(multiple))
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"])
track_file = "{:02}. {}{}".format(