Challenge to import cover from file

Hi,

now that I have my Music Folder organized and all my audio files nicely renamed and tagged, it is time to finalize the job and add the album covers. Now this turns out to be quite a challenge and doing it manually album by album is just not an option.

So I looked into using the Action "Import cover from file" but I can only get it to work when my .jpg reside in the same folder (or subfolder there of) as the .mp3 file as in the first example for the files in folder "Eddi - 2015 - Play Yer Guitar (EP)" but not for "Eddi - 2016 - Challenge"

So basically the structure is always something like this

D:\MUSIC
|
|
|
---Eddi

+---Eddi - 2015 - Play Yer Guitar (EP)
|   |   01 - Intro.mp3
|   |   02 - Outro.mp3
|   |   
|   \---Scans
|           NiceCover_1.jpg
|           NiceCover_2.jpg
|           
\---Eddi - 2016 - Challenge
    +---CD1
    |       01 - Intro.mp3
    |       02 - Chorus.mp3
    |       
    +---CD2
    |       01 - Solo.mp3
    |       02 - Outro.mp3
    |       
    \---Scans
            NoCover_1.jpg
            NoCover_2.jpg

So as soon as the audio files are one level deeper than the album covers as in the folder "Eddi - 2016 - Challenge" the Action no longer works and I keep getting the error message saying "Import cover from file "Scans*.jpg" (Front Cover): File D:\Music\Eddi\Eddi - 2016 - Challenge\CD1\Scans*.jpg cannot be accessed.

I understand that the message is legitimate since there is no Scans folder in the CD1 (and CD2) subfolder. But what is the solution to this? I certainly do not want to restructure my MUSIC directory. Placing the .jpg files one level deeper to get it to work would also mean that I would need to put copy all imagr files into BOTH the CD1 and CD2 folder. I am convinced that there is some smarter way to do it, but I just do not see how.

The Help file states that this Action "Imports the cover art specified by the absolute or relative filename into the tag of the file" -- unfortunately it does not say absolute or relative path!

So instead of setting the Action's "Format string for image filename" to "Scans*.jpg" I have tried specifying an absolte path like "D:\Music\Eddi\Eddi - 2016 - Challenge\CD1\Scans*.jpg" or relative path as in "%_parent_directory%\Scans*.jpg" but that all to no avail.

I have also used another column and imported the absolute path of the image file from text into it and then set the Action to read from that column but the error remains the same. There are no special characters anywhere as far as I can see; and I have full admin rights...

I have no problems having to run a different action for all albums containing multiple subfolders, like CD1, CD2, etc but can somebody please provide me with a solution?

Thanks in advance,
Eddi

For albums containing multiple sub-folders, try this format string:

$regexp(%_path%,($repeat(.+\\\\,$sub($folderdepth(%_path%),1)))(.+)(\\\\.+),$1Scans\)*.jpg

Just to be clear, I've assumed your problematic folder structure is this:

  • For cover files: "D:\Music\Eddi\Eddi - 2016 - Challenge\Scans"
  • For audio files: "D:\Music\Eddi\Eddi - 2016 - Challenge\CD1"

I think that this is more or less a one-off treatment of your files.
So I would use filters to cater for the different subfolders
e.g.
%_path% HAS CD1
and then use CD1*.jpg
as import file name.
and then
%_path% HAS scans
with
scans*.jpg
and so on.
Finally, I would use a filter to see if all files have got a cover
%_covers% MISSING
should ideally produce an empty list.
But it could just a well be that you find some folders with other names.

[quote name='ryerman' post='88204' ]For albums containing multiple sub-folders, try this format string:

$regexp(%_path%,($repeat(.+\\\\,$sub($folderdepth(%_path%),1)))(.+)(\\\\.+),$1Scans\)*.jpg

@ryerman - your solution works like a charm! There might be some additional challenges with slightly different directory structures, but I think I'll manage from here for now. Many thanks, this is brilliant!

[quote name='ohrenkino' post='88208']
So I would use filters to cater for the different subfolders
e.g.
%_path% HAS CD1
and then use CD1*.jpg
as import file name.

@ohrenkino, thanks for your reply, as well. I can surely give it a try, but I do believe it will not work, because the Scans folder is not in the CD1 directory

It will return something like
Import cover from file "CD1\ *.jpg" (Front Cover): File D:\MUSIC\Eddi\Eddi - 2016 - Challenge\CD1\CD1</b> *.jpg cannot be accessed.

Action #1: "Import cover from file" Import cover as: Front Cover Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)'Scans\*_1.jpg' Action #2: "Import cover from file" Import cover as: Back Cover Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)'Scans\*_2.jpg'

Testfiles ...
20160130.Eddi.zip (53.3 KB)

DD.20160130.1225.CET

20160130.Eddi.zip (53.3 KB)

@DetlevD, THANKS a lot for your solution, as well. In fact, it is even better in the sense that it can be executed on both folders regardless of whether these contain a CD1 or CD2 subfolder.

I have noticed that Mp3tag defaults to the last cover that was assigned, so I will probably change the oprder of the actions and first assign the back cover and then the front cover, so that the front covers are displayed within the application.

[quote name='DetlevD' post='88213']
[size=1][font="Courier New"][b]Action #1: "Import cover from file"

Import cover as: Front Cover Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)'Scans\*_1.jpg'

@DetlevD, or anybody else, do you happen to know of a way to grab the image files from a 'Scans' directory that is not one but two levels higher up than the audio file; from the great grand parent folder so to speak?

For example, in the following scenario where I store .flac files in a separate folder:

D:\MUSIC\

|
---Eddi

\---Eddi - 2016 - Challenge2
    +---FLAC                                          (=%_parent_directory%)
    |   +---CD1                                       (=%_directory%)
    |   |       01 - Intro.flac                       (=%_path%)
    |   |       02 - Chorus.flac
    |   |       
    |   \---CD2
    |           01 - Solo.flac
    |           02 - Outro.flac
    |           
    \---Scans
            NoCover_1.jpg
            NoCover_2.jpg 

Thanks!

You can always use an absolute path.

The syntax to address the parent directory is ..
so ....*.jpg
addresses files 2 directories up.
I do not now how many cases you have ... it might be easier to treat the files individually.

You can use a slightly changed version of my proposal from above ...
by applying a relative path component.

If standard folder ... Action "Import cover from file" Import cover as: Front Cover Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)'Scans\*_1.jpg'

If folder "FLAC" exist ...

Action "Import cover from file" Import cover as: Front Cover Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)'..\Scans\*_1.jpg'

Both cases merged into one action ...

Action "Import cover from file" Import cover as: Front Cover Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)$ifgreater($strstr(%_folderpath%,'\FLAC\'),0,'..\',)'Scans\*_1.jpg'

... or a little bit more safe ...

Formatstring: $regexp(%_folderpath%,%_directory%'\\\\$',)$ifgreater($strstr(%_folderpath%,'\FLAC\'%_directory%),0,'..\',)'Scans\*_1.jpg'

DD.20160131.1125.CET

How to address a folder by it's relative pathname ...

%_folderpath% <== 'C:\D1\D2\D3\' %_folderpath%$repeat('..\',0) ==> 'C:\D1\D2\D3\' %_folderpath%$repeat('..\',1) ==> 'C:\D1\D2\' %_folderpath%$repeat('..\',2) ==> 'C:\D1\' %_folderpath%$repeat('..\',3) ==> 'C:\' %_folderpath%$repeat('..\',$sub($folderdepth(%_folderpath%),0)) ==> 'C:\' %_folderpath%$repeat('..\',$sub($folderdepth(%_folderpath%),1)) ==> 'C:\D1\' %_folderpath%$repeat('..\',$sub($folderdepth(%_folderpath%),2)) ==> 'C:\D1\D2\' %_folderpath%$repeat('..\',$sub($folderdepth(%_folderpath%),3)) ==> 'C:\D1\D2\D3\'

DD.20160131.1605.CET

Here is a generalized format string. Notice the variable X.

$regexp(%_path%,($repeat(.+\\,$sub($folderdepth(%_path%),X))).+$repeat(\\.+,X),$1)

It can be adjusted to return the path to any directory in a files path.
Replace the variable X (used in two positions) with the number corresponding to the directory of interest.
0 - directory
1 - parent directory
2 - grandparent directory
3 - great-grandparent directory
4 - great-great-grandparent directory
and so on...

The string will return the path to the chosen directory, with a trailing back-slash.

If X = $folderdepth(%_path%), the drive letter is returned.
If X = $folderdepth(%_path%) + 1, $1 is not populated and nothing is returned.
If X > $folderdepth(%_path%) + 1, the regex fails and %_path% is returned.

Note: A not matching $regexp() returns the full input string.

DD.20160131.1511.CET

Thanks for the correction.
Is it accurate to say "If X is greater than $folderdepth(%_path%), $1 is not populated and nothing is returned."?
Sorry, ignore that question.
I'll edit my previous post.

Apologies for the late reply; thank you all very much for the great help and thorough explanations! It's working beautifully :slight_smile: