@@ -63,7 +63,7 @@ def delete_uploaded_albums(add_to_library):
63
63
progress_bar = manager .counter (total = len (uploaded_albums ), desc = "Albums Processed" , unit = "albums" )
64
64
for album in uploaded_albums :
65
65
try :
66
- artist = album ["artists" ][0 ]["name" ] if hasattr ( album , "artists" ) else const .UNKNOWN_ARTIST
66
+ artist = album ["artists" ][0 ]["name" ] if "artists" in album else const .UNKNOWN_ARTIST
67
67
title = album ["title" ]
68
68
logging .info (f"Processing album: { artist } - { title } " )
69
69
if add_to_library :
@@ -102,7 +102,7 @@ def delete_uploaded_singles():
102
102
103
103
for single in uploaded_singles :
104
104
try :
105
- artist = single ["artist" ][0 ]["name" ] if hasattr ( single , "artist" ) else const .UNKNOWN_ARTIST
105
+ artist = single ["artist" ][0 ]["name" ] if "artist" in single else const .UNKNOWN_ARTIST
106
106
title = single ["title" ]
107
107
response = youtube_auth .delete_upload_entity (single ["entityId" ])
108
108
if response == "STATUS_SUCCEEDED" :
@@ -125,7 +125,7 @@ def add_album_to_library(artist, title):
125
125
if result ["resultType" ] == "album" and match_found (result , artist , title ):
126
126
catalog_album = youtube_auth .get_album (result ["browseId" ])
127
127
logging .info (
128
- f"\t Found matching album \" { catalog_album ['artist' ][0 ]['name' ] if hasattr ( catalog_album , 'artist' ) else '' } - { catalog_album ['title' ]} \" in YouTube Music. Adding to library..."
128
+ f"\t Found matching album \" { catalog_album ['artist' ][0 ]['name' ] if 'artist' in catalog_album else '' } - { catalog_album ['title' ]} \" in YouTube Music. Adding to library..."
129
129
)
130
130
success = youtube_auth .rate_playlist (catalog_album ["playlistId" ], const .LIKE )
131
131
if success :
@@ -140,7 +140,7 @@ def match_found(result, artist, title):
140
140
try :
141
141
resultArtist = str (result ["artist" ]).lower ()
142
142
except KeyError :
143
- resultArtist = str (result ["artists" ][0 ] if hasattr ( result , "artists" ) else "" ).lower ()
143
+ resultArtist = str (result ["artists" ][0 ] if "artists" in result else "" ).lower ()
144
144
try :
145
145
resultTitle = str (result ["title" ]).lower ()
146
146
except KeyError :
@@ -181,12 +181,14 @@ def remove_library():
181
181
library_songs = []
182
182
# Filter out songs where album is None (possible rare occurrence seen here: https://github.com/apastel/ytmusic-deleter/issues/12)
183
183
filtered_songs = list (filter (lambda song : song ["album" ], library_songs ))
184
+ if len (library_songs ) - len (filtered_songs ) > 0 :
185
+ logging .info (f"{ len (library_songs ) - len (filtered_songs )} songs are not part of an album and won't be deleted." )
184
186
# Filter for unique album IDs so that for each song, we can just remove the album it's a part of
185
- filtered_songs = list ({v ["album" ]["id" ]: v for v in filtered_songs }.values ())
186
- progress_bar = manager .counter (total = len (filtered_songs ), desc = "Singles Processed" , unit = "singles" )
187
- albums_removed += remove_library_albums_by_song (filtered_songs , progress_bar )
187
+ album_unique_songs = list ({v ["album" ]["id" ]: v for v in filtered_songs }.values ())
188
+ progress_bar = manager .counter (total = len (album_unique_songs ), desc = "Singles Processed" , unit = "singles" )
189
+ albums_removed += remove_library_albums_by_song (album_unique_songs , progress_bar )
188
190
logging .info (
189
- f"Removed { albums_removed } out of { len (library_albums ) + len (filtered_songs )} albums from your library." )
191
+ f"Removed { albums_removed } out of { len (library_albums ) + len (album_unique_songs )} albums from your library." )
190
192
191
193
192
194
def remove_library_albums (albums , progress_bar ):
@@ -214,7 +216,7 @@ def remove_album(browseId):
214
216
logging .exception (
215
217
f"\t Failed to remove album with ID { browseId } from your library, as it could not be retrieved." )
216
218
return False
217
- artist = album ["artist" ][0 ]["name" ] if hasattr ( album , "artist" ) else const .UNKNOWN_ARTIST
219
+ artist = album ["artist" ][0 ]["name" ] if "artist" in album else const .UNKNOWN_ARTIST
218
220
title = album ["title" ]
219
221
logging .info (f"Processing album: { artist } - { title } " )
220
222
response = youtube_auth .rate_playlist (album ["playlistId" ], const .INDIFFERENT )
@@ -240,7 +242,7 @@ def unlike_all():
240
242
logging .info ("Begin unliking songs..." )
241
243
progress_bar = manager .counter (total = len (your_likes ['tracks' ]), desc = "Songs Unliked" , unit = "songs" )
242
244
for track in your_likes ["tracks" ]:
243
- artist = track ["artists" ][0 ]["name" ] if hasattr ( track , "artists" ) else const .UNKNOWN_ARTIST
245
+ artist = track ["artists" ][0 ]["name" ] if "artists" in track else const .UNKNOWN_ARTIST
244
246
title = track ["title" ]
245
247
logging .info (f"Processing track: { artist } - { title } " )
246
248
if track ["album" ] is None :
0 commit comments