summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@mailbox.org>2026-05-19 18:51:39 +0200
committerAldrik Ramaekers <aldrik@mailbox.org>2026-05-19 18:51:39 +0200
commit15076a26fd6bdd87f793d4331000e92e671a48bc (patch)
tree9d2b46cf5a19ca3e7d4201adc2ed76916bc23d02
parent838abfd809b3f9ade77508ebfb534a37dacbb9a8 (diff)
work
-rw-r--r--dl-artist.py24
1 files 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...')