mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
Merge branch 'playlistImageCleaner' of github.com:Parsa-SadeghiAsl/swingmusic into Parsa-SadeghiAsl-playlistImageCleaner
This commit is contained in:
@@ -318,6 +318,7 @@ def update_playlist_info(path: PlaylistIDPath, form: UpdatePlaylistForm):
|
|||||||
p_tuple = (*playlist.values(),)
|
p_tuple = (*playlist.values(),)
|
||||||
|
|
||||||
PlaylistTable.update_one(playlistid, playlist)
|
PlaylistTable.update_one(playlistid, playlist)
|
||||||
|
playlistlib.cleanup_playlist_images()
|
||||||
|
|
||||||
playlist = models.Playlist(*p_tuple)
|
playlist = models.Playlist(*p_tuple)
|
||||||
playlist.last_updated = date_string_to_time_passed(playlist.last_updated)
|
playlist.last_updated = date_string_to_time_passed(playlist.last_updated)
|
||||||
@@ -377,6 +378,7 @@ def remove_playlist(path: PlaylistIDPath):
|
|||||||
Delete playlist
|
Delete playlist
|
||||||
"""
|
"""
|
||||||
PlaylistTable.remove_one(path.playlistid)
|
PlaylistTable.remove_one(path.playlistid)
|
||||||
|
playlistlib.cleanup_playlist_images()
|
||||||
return {"msg": "Done"}, 200
|
return {"msg": "Done"}, 200
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -135,3 +135,36 @@ def get_first_4_images(
|
|||||||
return images
|
return images
|
||||||
|
|
||||||
return duplicate_images(images)
|
return duplicate_images(images)
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_playlist_images():
|
||||||
|
"""
|
||||||
|
Cleans up unlinked playlist images by comparing files in the playlist image directory
|
||||||
|
against the .image property of all playlists.
|
||||||
|
"""
|
||||||
|
# Import here to avoid circular import
|
||||||
|
from swingmusic.db.userdata import PlaylistTable
|
||||||
|
|
||||||
|
playlists = PlaylistTable.get_all()
|
||||||
|
linked_images = {p.image for p in playlists if p.image and p.image != "None"}
|
||||||
|
|
||||||
|
playlist_dir = settings.Paths.get_playlist_img_path()
|
||||||
|
all_files = os.listdir(playlist_dir)
|
||||||
|
|
||||||
|
# Find unlinked images (including thumbnails)
|
||||||
|
unlinked_files = []
|
||||||
|
for file in all_files:
|
||||||
|
if file.startswith("thumb_"):
|
||||||
|
base_file = file[6:] # Remove "thumb_" prefix
|
||||||
|
if base_file not in linked_images:
|
||||||
|
unlinked_files.append(file)
|
||||||
|
|
||||||
|
elif file not in linked_images:
|
||||||
|
unlinked_files.append(file)
|
||||||
|
|
||||||
|
for file in unlinked_files:
|
||||||
|
try:
|
||||||
|
os.remove(os.path.join(playlist_dir, file))
|
||||||
|
except OSError:
|
||||||
|
# Skip if file doesn't exist or can't be deleted
|
||||||
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user