Grab the discnumber from filename to tag, Only IF there is a discnumber?

Hi there!

I started using Mp3Tag a while ago, and let me tell you it was love at first sight. It's such a nifty piece of software, and it has saved me literally thousands of hours of work, trying to perfect my digital audio collection. Thank you for that!

Now there however seems to be trouble in paradise, and I have run into some problems, which I hope that you can help me to sort of. It takes some explaining however, so please bare with me.

This is what my folder structure looks like

Genre\Artist(Year) Album\Track - Title

Here it is put to practical use, further exemplified by the (in my opinion) masterful works of Periphery:

Djent\Periphery(2015) Juggernaut_ Alpha\01 - A Black Minute

For this i simply convert FILENAME to TAG using the following format string:

%genre%\%albumartist%(%year%) %album%\%track% - %title%

This works great, UNLESS the album in question is a double CD, box set or any other media type which consists of two or more discs. Since then an extra level of folders is added to the mix, inbetween the album name and the actual tracks - generating the following structure:

Genre\Artist(Year) Album<i>Discnumber\Track - Title

Now my format string no longer works, and I have to manually edit it for it to function properly. Which I for certain am able to do, but I don't have to, do I? This leading us to the core and the main question of this thread - I'm simply wondering if there's a way to grab the disc number from a file name and convert it to a tag, Only if there are disc number folders (maybe using an IF statement)? And if so: How do I do it?

I've been tinkering with it myself, but to no avail. It would seem I simply lack the coding skills necessary - any help is much appreciated. Thanks in advance!

// Johan Wendesten

I think you have to perform two steps to cater for the different depths in paths.
So you could apply a filter that checks how many folders there are, e.g.:
$add($len($regexp(%_path%,'[^\\]',)),1) is 5
checks for 5 folders.

Try to get the folders with multiple CDs first and then filter for
$add($len($regexp(%_path%,'[^\\]',)),1) is 4 AND %discnumber% MISSING
to fill the other files.

Set Filter like ...
"$folderdepth(%_folderpath%)" IS 3
... or ...
"$folderdepth(%_folderpath%)" IS 4
... to handle both cases separately.

DD.20150223.1749.CET

Let me start by apologizing for my late response, but I've been away for a few days not getting the opportunity to respond until now. Second of all: thanks for the help! I tried out DetlevD's method and it worked like a charm - it turns out using filters to handle both cases separately is the way to go.

Although this two step solution is satisfactory, it's not quite as elegant as one step variant would be, so if anyone comes up with an even more streamlined method, and feels the urge to share it, don't hesitate to do so. In the meantime: thank you once again for your help, it's much appreciated!

// Johan Wendesten

If you look at it cloesly, there is no one-step-variant.
You still have to supply the full expression to extract the data for the case with cd number and the case without the cd number plus the evaluation of the folderdepth.
All in all would this lead to a very long statement that certainly has its drawbacks in respect to maintainabilty.
The curent solution has the advantage that it was ready-made for youl.

If you need more flexibility for handling different cases at once, and the interactive Mp3tag Converters cannot help anymore, then you have to work with Mp3tag actions, where you can apply the Mp3tag Scripting Language, which supports if-condition and so forth.
Try out the following group of actions.

All Action "Format value" Field Formatstring ---------------------------- DISCNUMBER <== $if($eql(4,$folderdepth(%_folderpath%)),
                <!--coloro:#800080--><span style="color:#800080"><!--/coloro-->$regexp<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->(<!--colorc--></span><!--/colorc--><!--coloro:#0000be--><span style="color:#0000be"><!--/coloro-->%_folderpath%<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->^(?:(.+?)\\\\){5}.*$<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->$1<!--colorc--></span><!--/colorc--><!--coloro:#008080--><span style="color:#008080"><!--/coloro-->'<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->,<!--colorc--></span><!--/colorc--><!--coloro:#0000a0--><span style="color:#0000a0"><!--/coloro-->%DISCNUMBER%<!--colorc--></span><!--/colorc--><!--coloro:#000000--><span style="color:#000000"><!--/coloro-->)<!--colorc--></span><!--/colorc-->
GENRE <== $regexp(%_folderpath%,'^(?:(.+?)\\\\){2}.*$','$1') ALBUMARTIST <== $regexp(%_folderpath%,'^(?:(.+?)\\\\){3}.*$','$1') YEAR_ALBUM <== $regexp(%_folderpath%,'^(?:(.+?)\\\\){4}.*$','$1') TRACK_TITLE <== %_filename% YEAR <== $regexp(%YEAR_ALBUM%,'^\((.+?)\) (.+?)$','$1') ALBUM <== $regexp(%YEAR_ALBUM%,'^\((.+?)\) (.+?)$','$2') YEAR_ALBUM <== $char(0) TRACK <== $regexp(%TRACK_TITLE%,'^(.+?) - (.+?)$','$1') TITLE <== $regexp(%TRACK_TITLE%,'^(.+?) - (.+?)$','$2') TRACK_TITLE <== $char(0)

DD.20150228.1358.CET

Okey guys! It seems I underestimated the complexity of the task at hand - so thanks for clarifying. And thank you for your help once again, the method provided in this topic is, as I stated above, satisfactory as it suits my needs quite perfectly, even more so now when I now that there is no simple better way of doing things, at least no within the realm om my coding skills. I'll simply let that magical inconceivable one step solution be a holy grail for now. Cheers!

// Johan Wendesten

My proposal from above is a "one-step solution".
It is just only one group of actions, which can be invoked by one or two mouse clicks or keyboard shortcut.

Mp3tag MTA actiongroup and foldertree with testfiles ...
20150228.VarFolderDepth.Test.zip (1.87 KB)

DD.20150228.1835.CET

20150228.VarFolderDepth.Test.zip (1.87 KB)