From efb1b2a4e8a9d3a21b10bac87a4795d99f30d518 Mon Sep 17 00:00:00 2001 From: zehkira <9485872-zehkira@users.noreply.gitlab.com> Date: Wed, 1 Oct 2025 21:47:55 +0200 Subject: [PATCH] Simplify downloads cleanup process --- source/monophony/downloads.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/source/monophony/downloads.py b/source/monophony/downloads.py index 5b97cdb..5b01b88 100644 --- a/source/monophony/downloads.py +++ b/source/monophony/downloads.py @@ -1,3 +1,4 @@ +import contextlib import glob import json import os @@ -141,21 +142,18 @@ class _Downloader: path = get_directory() os.makedirs(path, exist_ok=True) for file in os.listdir(path): - if file.endswith(('.part', '.' + NAME)): + if file.endswith(NAME): os.remove(path + file) logging.info(__name__, f'Removed abandoned temp file "{file}"') continue - for song in downloads_group.songs: - if path + file == get_file(song): - break - else: + yt_id = 'null' + with contextlib.suppress(IndexError): + yt_id = file.split('.')[-2][-11:] + if Song(yt_id=yt_id) not in downloads_group.songs: os.remove(path + file) logging.warning(__name__, f'Removed unexpected file "{file}"') - self.write( - Group(songs=[song for song in self.read().songs if is_downloaded(song)]) - ) logging.info(__name__, 'Cleaned up downloads') self.lock.unlock() -- GitLab