# Is there a way to purge old album art?

**URL:** <https://discourse.beets.io/t/is-there-a-way-to-purge-old-album-art/1790>\
**Category:** Help\
**Created:** [June 9, 2021, 3:03pm UTC](https://discourse.beets.io/t/is-there-a-way-to-purge-old-album-art/1790 "2021-06-09T15:03:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apastuszak](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@apastuszak](https://discourse.beets.io/u/apastuszak)\
**Post date:** [June 9, 2021, 3:03pm UTC](https://discourse.beets.io/t/is-there-a-way-to-purge-old-album-art/1790/1 "2021-06-09T15:03:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ctrueden](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/ctrueden/32/475_2.png) [@ctrueden](https://discourse.beets.io/u/ctrueden)\
**Post date:** [June 13, 2021, 3:32am UTC](https://discourse.beets.io/t/is-there-a-way-to-purge-old-album-art/1790/2 "2021-06-13T03:32:19Z")

</div>

> [@apastuszak](#):
>
> Is there some way to get beets to purge all image files except for the one currenly in use by the database?

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?

> [@apastuszak](#):
>
> if I do a manaul fetchart, will it embed the artwork or do I need to do that in another step?

I think that will depend on whether you have enabled the [embedart plugin](https://beets.readthedocs.io/en/stable/plugins/embedart.html).

---

<div class="post-metadata">

**Author:** ![adrian](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/adrian/32/4_2.png) [@adrian](https://discourse.beets.io/u/adrian)\
**Post date:** [June 13, 2021, 2:15pm UTC](https://discourse.beets.io/t/is-there-a-way-to-purge-old-album-art/1790/3 "2021-06-13T14:15:26Z")

</div>

> [@ctrueden](#):
>
> 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.

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:

> <https://github.com/beetbox/beets/blob/0d624191329f5ef5f9acf40ebd7c46b578383222/beets/library.py#L1028>

---

<div class="post-metadata">

**Author:** ![ctrueden](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.beets.io/ctrueden/32/475_2.png) [@ctrueden](https://discourse.beets.io/u/ctrueden)\
**Post date:** [August 17, 2021, 6:46pm UTC](https://discourse.beets.io/t/is-there-a-way-to-purge-old-album-art/1790/4 "2021-08-17T18:46:06Z")

</div>

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:

```auto
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.
