Kometa-Team / ImageMaid

Python 3 Script for Cleaning Up Images in Plex
MIT License
289 stars 18 forks source link

[Feature]: Only remove actual bloat images (i.e. EXIF tagged) #82

Open planetrocky opened 2 weeks ago

planetrocky commented 2 weeks ago

Describe the Feature Request

This script is great, but it removes all the alternate artwork and posters that are stored. On a large collection it can take Plex a very long time to repopulate these, and on a CPU bound low-power NAS, it really impacts operation for a few days until it’s restored.

Ideally only the Kometa “bloat” images should be removed or at least an option to control this.

A check on each image before removal should be easy to add:

Taken from modules/library.py of Kometa as an example.

This shows the operation from Kometa:

with Image.open(image_path) as image:
            exif_tags = image.getexif()
        if 0x04bc in exif_tags and exif_tags[0x04bc] == "overlay":
            os.remove(image_path)
            raise Failed("This item's poster already has an Overlay. There is no Kometa setting to change; manual attention required.")
        if remove:
            os.remove(image_path)
        else:
            return image_path
planetrocky commented 2 weeks ago

I've made a quick test run of this locally, and it seems to be good :) It won't remove any posters that have been manually uploaded.

changes.patch

Pull request: https://github.com/Kometa-Team/ImageMaid/pull/84

three line snippet from the log file for operation report, showing one file that is skipped (custom upload file):

[2024-10-09 01:00:59,117] [imagemaid.py:336]          [DEBUG]    | BLOAT FILE: \\fs2\docker\plex\Library\Application Support\Plex Media Server\Metadata\Movies\9\90c7a3c30a60d1150d94205109a5a2b74485cdf.bundle\Uploads\posters\36e4a268b6d4df0bc9f66aa775d3704a1eb44619 |
[2024-10-09 01:00:59,117] [imagemaid.py:336]          [DEBUG]    | IMAGE FILE: \\fs2\docker\plex\Library\Application Support\Plex Media Server\Metadata\Movies\a\ade61580dc88ae8181b9df68aba0b59d40c5a93.bundle\Uploads\posters\d2a12a4a004bcdb4b4269560f8ce868ceae9f6d9 does not have EXIF overlay tag and won't be considered. |
[2024-10-09 01:00:59,117] [imagemaid.py:336]          [DEBUG]    | BLOAT FILE: \\fs2\docker\plex\Library\Application Support\Plex Media Server\Metadata\Movies\a\eb03f784819ccf7eac36ecbe03bded317864837.bundle\Uploads\posters\e12984d3d6cdc86dc085a924b3bdbeb1c862f66c |

three line snippet from the log file for operation remove, showing one file that is skipped (custom upload file):

[2024-10-09 01:32:24,708] [imagemaid.py:338]          [TRACE]    | REMOVE: \\fs2\docker\plex\Library\Application Support\Plex Media Server\Metadata\Movies\9\90c7a3c30a60d1150d94205109a5a2b74485cdf.bundle\Uploads\posters\36e4a268b6d4df0bc9f66aa775d3704a1eb44619 |
[2024-10-09 01:32:24,708] [imagemaid.py:338]          [TRACE]    | IMAGE FILE: \\fs2\docker\plex\Library\Application Support\Plex Media Server\Metadata\Movies\a\ade61580dc88ae8181b9df68aba0b59d40c5a93.bundle\Uploads\posters\d2a12a4a004bcdb4b4269560f8ce868ceae9f6d9 does not have EXIF overlay tag and won't be considered. |
[2024-10-09 01:32:24,708] [imagemaid.py:338]          [TRACE]    | REMOVE: \\fs2\docker\plex\Library\Application Support\Plex Media Server\Metadata\Movies\a\eb03f784819ccf7eac36ecbe03bded317864837.bundle\Uploads\posters\e12984d3d6cdc86dc085a924b3bdbeb1c862f66c |