Help write a script to conditionally export cover.jpg

I have been playing with Quick action > Export cover to file, but it seems that is too limited for my needs, so I think I might be able to use scripting functions - but I have never done this before sorry and can't figure out "how" especially since most of the script functions and examples seem to involve writing tags, not cover art files!

Music is in a fairly typical directory structure:
root\%genre%\%albumartist%\%albumname%\
Tracks are all individual (no tricky iso or cue files here) but are a mixture of mp3 and flac files. Compilations use %albumartist% = "Various Artists", yes.
For the MOST part, my tags are correct and most albums HAVE embedded cover art (type = front cover).
If any albums are missing covers - that's because the album is rare enough that I couldn't find art online anywhere, manually, and didn't have a scanner available to scan the jacket...

Desired output:
cover.jpg file to be saved into each album folder.
However, I want to use the following logic / decisions about what to save and what to overwrite!

Test1. IF cover.jpg does not exist, then write output file cover.jpg from saved front cover embedded in the files (assume they're all the same ie just open track#1).
That scenario is actually met by the existing Quick action yes, but not the rest!
1a However, resize output cover.jpg file as max 700x700 if the embedded front cover was say 2000x2000 and/or convert format if embedded art was png/bmp.

Test2. IF cover.jpg DOES exist, then check the widthxheight size of the existing file.
CASE1 IF existing cover.jpg is bigger than 700x700, then look at embedded album art of type = front cover, AND IF such album art exists, then fetch size AND IF it is larger than 700x700 then output cover.jpg, resized to max 700x700 and/or change format from png/bmp > jpg.
OR If embedded art is less than or equal to 700x700, no need to downsize, only format from png/bmp > jpg.
This output file SHOULD OVERWRITE the existing cover.jpg file.

CASE 2
If existing cover.jpg is less than or equal to 700x700 - no action required, continue parsing folders (ie don't bother with test3).

Test3. IF cover.jpg does not exist AND tracks do NOT have embedded album art type = front cover, then CHECK if file = folder.jpg exists.
CASE 1 If folder.jpg does exist then do similar size & format logic checking (as above) and output downsized cover.jpg to max 700x700 and type=jpg from png/bmp.
CASE 2 If folder.jpg does NOT exist, then skip this folder and parse the next.

Why do I want to do this?
After a huge amount of trial and error, I have found that my car stereo headunit which plays both mp3 and flac files from USB, for album cover art uses ONLY file = cover.jpg and ONLY if less than or equal to 700x700 size. It doesn't actually look at embedded album art, nor folder.jpg. So while things like WMP, kodi & Plex all happily read the embedded art and display it fine, the car headunit only shows a few!

If what I'm trying to do can only be done manually, then - yeah I can't see me bothering with that just for the car stereo, but if it can be scripted that would be awesome!
Cheers, tU

To cut this short: any condition that has to compare the properties of another file (here: the external picture file) will not work as MP3tag does not do that.

Also, actions to export data cannot be executed conditionally - you would have to apply a filter first and then call the action.

So I think that it will boil down to

I can't quite understand why you make the project so complicated and burden it with so many "ifs".
I would simply filter for
%_cover_type% IS Front Cover
and then export the embedded covers
.
Why is it so important which resolution the cover.jpg already in the folder has? Do you suspect that you are overwriting better-quality covers in the folder - that you might want to embed later - with embedded covers of lower quality with this export action?

After this action I would automatically convert the generated cover.* files to JPG in one operation using external software and set the resolution to 700. A program that can do this in batch mode is e.g. Irfanview.

:joy: I think that you are right, but thank you for your reply!

You are correct yes - for some albums the better quality covers are embedded, and for others the better quality covers are external files - hence all the conditions.
The "why" is complicated, but I have been ripping my own CDs since the mid 1990s, back in the days when you had to patch CDROM firmwares to get proper DAE, and am a long term EAC user, initially with LAME > mp3 but in more recent years exclusively FLAC.
There are multiple generations of media management and tagging methods employed (until I discovered mp3tag of course! I've used nothing else for a very long time now!)
One of which was a semi-automated cover-art program which, while it was designed specifically for WMP/MCE, had its other uses too (now obsolete, and not supported for many many years).
I THINK that I used that to downgrade embedded art in mp3s to small quality. I can't recall why I did that (maybe to meet the album art display requirements of an ipod?), at the time it didn't seem like a "loss" as such, but now I regret doing that.
Whatever the reason, for that generation of files created, the better album art (and there is a big collection) will be the external cover.jpg - NOT the embedded front covers.

Interesting suggestion thanks, maybe I will check out irfanview.

Actually, both of your replies made me realise I've been an idiot, and as noted made this way more complicated than it needs to be. :upside_down_face:
The solution required is only for the car USB flash drive, and method employed doesn't have to break anything in the main collection.
Therefore, I'll use mp3tag to bulk export front covers > cover.jpg for the entire flash drive.
Then I can just find all cover(1).jpg files and bulk delete from the drive.
Job done, case closed "next patient please"! :joy:
Thanks guys :blush:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.