Is there a way to purge old album art?

I have updated the album art on quiet a number of my albums using the fetchart plugin. This leaves old album art in the direcory.

Is there some way to get beets to purge all image files except for the one currenly in use by the database?

Also, if I do a manaul fetchart, will it embed the artwork or do I need to do that in another step?

I could be wrong, but to my knowledge, the database retains no reference to any album art, either “files on the side” e.g. cover.jpg, nor art embedded in the music files themselves. At least, I couldn’t find any such references when digging through my whole music collection of tens of thousands of songs, which has plenty of album art embedded in files, and a few files on the side too. So, I think you can just delete the ones you don’t want to keep.

If you want to programmatically delete older album art files, leaving only the newest ones, you could write a shell script for that… do you need guidance on how to do that?

I think that will depend on whether you have enabled the embedart plugin.

FWIW, the database does track associated “file on the side” image files. In case anyone’s interested in where this shows up in the code, it’s the artpath field:

1 Like

Thanks @adrian for the info, and sorry for not checking the DB schema before replying.

So then @apastuszak: assuming you are still interested in a script to help with this, you could do something like:

artpaths=$(sqlite3 ~/.config/beets/library.db 'select artpath from albums where artpath not null;')
find /path/to/my/music -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.gif' | while read f
do
echo "$artpaths" | grep -qF "$f" || echo "$f"
done > untracked-images.txt

Which will log all PNG, JPEG, and GIF files that are not tracked in the DB’s artpath field into the file untracked-images.txt. You can then review the list, and if all looks good, run rm $(cat untracked-images.txt) to delete them all.

Caveat emptor: my beets database does not have any artwork tracked by that artpath column, so I couldn’t test this script completely. In particular, I do not know if artpath will be an absolute path, or a path relative to the music root. So the script might need slight adjustments for that. Respond here if you still need help.