From 15076a26fd6bdd87f793d4331000e92e671a48bc Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Tue, 19 May 2026 18:51:39 +0200 Subject: work --- dl-artist.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dl-artist.py b/dl-artist.py index d034b61..eec11f0 100644 --- a/dl-artist.py +++ b/dl-artist.py @@ -34,7 +34,7 @@ class DownloadFailedException(Exception): self.message = message super().__init__(self.message) -def remove_external_albums(name, complete_albums): +def cleanup_album(name, complete_albums): directory_path = output_dir+'/'+name if not os.path.exists(directory_path): return False @@ -43,9 +43,17 @@ def remove_external_albums(name, complete_albums): album_titles = album_titles.copy() album_titles.append('Singles') - filenames = [f for f in os.listdir(directory_path) if os.path.isdir(os.path.join(directory_path, f))] + existing_album_folders = [f for f in os.listdir(directory_path) if os.path.isdir(os.path.join(directory_path, f))] # Find .webp files from failed downloads. + for existing_album in existing_album_folders: + directory_path = output_dir+'/'+name+'/'+existing_album + if os.path.exists(directory_path): + webp_files = [os.path.join(directory_path, f) for f in os.listdir(directory_path) if f.endswith('.webp')] + for webp_file in webp_files: + if not args.test: + os.remove(webp_file) + print(f'Cleanup: removed file {webp_file}') # Find albums that are on disk, but are not is discography list. #unknown_albums = [elem for elem in filenames if elem not in album_titles] @@ -77,6 +85,7 @@ except ImportError: parser = argparse.ArgumentParser(description='Music downloader.') parser.add_argument('--test', action='store_true', help='Test script without downloading anything.') +parser.add_argument('--cleanup', action='store_true', help='Remove download artifacts.') parser.add_argument('--update', action='store_true', help='Retrieve artists from output directory and download missing albums and singles. Overwrites queue file.') parser.add_argument('--out', type=str, default='download', help='Output directory. (default: folder /download/ will be created in active directory.)') @@ -107,7 +116,7 @@ while (NeedRestart): print('Updating existing library: getting artist list...') if not os.path.exists(output_dir): - raise InvalidPathException + raise InvalidPathException('D') filenames = [f for f in os.listdir(output_dir) if os.path.isdir(os.path.join(output_dir, f))] filenames.sort() @@ -126,7 +135,7 @@ while (NeedRestart): lines = [line.strip() for line in lines if line.strip()] if len(lines) == 0: - raise QueueEmptyException + raise QueueEmptyException('D') if ArtistToDownload == None: ArtistToDownload = lines.pop(0) @@ -165,7 +174,10 @@ while (NeedRestart): if artist_result['singles']['browseId'] != None: singles = ytmusic.get_artist_albums(artist_result["singles"]["browseId"], artist_result["singles"]["params"], 9999) - remove_external_albums(artist_name, albums) + if args.cleanup: + cleanup_album(artist_name, albums) + ArtistToDownload = None + continue directory_path = output_dir+'/'+artist_name if album_is_complete(directory_path, albums, singles): @@ -217,7 +229,7 @@ while (NeedRestart): failCount += 1 print('Download failed') if failCount >= 5: - raise DownloadFailedException + raise DownloadFailedException('D') # 2. Download singles print('Artist "' + artist_name + '" has ' + str(len(singles)) + ' singles...') -- cgit v1.2.3-70-g09d2