Regular Expression to Set discnumber based on path

Hope someone can help me create this action please.

In english -
If discnumber is populated do nothing.
If the directory path looks like it identifies a discnumber set the discnumber, else do nothing

use cases i can see (case insensitive)
discX*
cdX*

where X is a number following disc|cd
where X might be up to two digits (and if it starts with 0 eg 01,use 1 for discnumber)
and disc|cd appear at the bottom of the path (possibly overkill as a match elsewhere is unlikely)

could someone advise on the regexp to use. even just the core part if the fancy bells are not easy.

thanks

How often, do you think, will this happen? I would say: just this once. As in the future you will fill the discnumber straightaway and then create the folder structure from the tags, right?

So what I would do:
Set a filter to
%discnumber% MISSING and %_directory% MATCHES ".*\d"
Then use the converter Filename - Tag and the mask
%dummy% cd%discnumber\%dummy%
and then
%dummy% disc%discnumber\%dummy%

Twiddle a little with the blank after disc or cd

thanks for the 'quick and dirty' approach. It worked after a fashion but there a bit too many cases of fiddling and no certainty without a check at the end, ie not a repeatable process. (i would not feel safe running it accross the entire collection or confident of a known outcome)

i used %discnumber% IS "" rather than MISSING

i might be able to cut down on the fiddling with some if/regexp statements in the filename to tag.
I am probably being greedy but please say if there is a more succint repeatable method.

If you are not certain that you can limit down the pattern to just one then a regular expression will not help you very much further or produce just the same amount of uncertainty.
GIGO is always an option.

but i thought the power of regular expression could limit it down, but i dont know how to write it.
areas of improvement might be, the tag to filenme seemed case sensitive and i think regexp can match on closeness between the cd|disc and the 1 or two digits disc number, where the discnumber might not be at the end eg.. "Cd_02)"

First try to say the instructions in your own words and then try to put it into an expression.
So, a phrase would "Take the last characters before the backslash and treat them as discnumber". The problem there is: what are the last characters? What separates them from the "first" characters?
By now you have mentioned: a blank, a bracket, an underscore ...
Or are these always the last 2 characters? Apparently not.
So I would say that you have to cater for all these variations.
BTW: you can test the results of a regular expression by using this expression as part of a filter with MATCHES.
If the filter does not show all or more files than you wanted, it does not match.

thanks for advice on using the filter to quickly test different expressions whilst learning
gotchaFilter expressions are insensitve but $regexp is sensitive by default.
so far through following advice i have

Format Value
Field - discnumber
$regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1)

$1=anything (even nothing)
$2=disc or cd (,1 at end=case insensitive match)
$3=anything but a digit - not more than 3 long (ie close to)
$4=1or2 digits
$5=anything (even nothing)

This seems to work but...
if it cant match it returns the whole %_directory%
which i could probably fix this with a filter 1st

but is there a tweak i could use to the action, without a filter, so that no change is made if there is no match. I am trying to avoid filters in the hope of make a list of actions suitable for the whole library.

doh! so i could use
$if($neql($regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1),%_directory%),$regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1),)

but is there a more succint way to say to an action "dont do it unless there is a match"

Slighty more sophisticated.

Set the disk number if a disknumber is apparent in the path...
$if($neql($regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1),%_directory%),$regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1),)

Set the disk number only if there is no discnumber already...
$if2(%discnumber%,$if($neql($regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1),%_directory%),$regexp(%_directory%,(.)(disc|cd)(\D{0,3})(\d{1,2})(.),$4,1),))

is it possible to add the total number of discs (paths?)

example-sampler:
cd1 --> 1/3
cd2 --> 2/3
cd3 --> 3/3

No.
Except for the track numbering wizard mp3tag does not know anything about coming or already processed files and their contents. So it cannot look ahead an see that there will come 3 cds.

Hi,
I am using this action (Format value _FILENAME):
D:\Format_wav$if($eql(%compilation%,1),Compilation,%artist%)[%year% - ]%album%[<b>CD %discnumber%]$num(%track%,2) - %artist% - %title%
To be able to change and arrange all the files. But such a mistake is creating vinyl and vinyl track numbers!
Are Mp3Tag column:
"Track" may write for example A1, A2, ... B1, B2, ...
"Discnumber" may write like LP 1, LP 2, ... Vinyls and CD 1, CD 2 ... CDs.
Do the following entries are correct? Will it be done?
In this case the action ... becomes correct and the file names are created correctly.
D:\Format_wav$if($eql(%compilation%,1),Compilation,%artist%)[%year% - ]%album%[\%discnumber%]\%track%. %artist% - %title%)
Thus, the vinyl will be
D:...\Laima Vaikule\1996 - Viss Nak Un Aiziet<b>LP 1<b>A1. Laima Vaikule - Balta Saule (Цветные сны).flac
and CDs will be
D:...\Алена Свиридова\2001 - Застольные песни уходящего века<b>CD 6<b>0023. Алена Свиридова - Песенка о медведях.flac


I do not quite understand what your message is, but I try to comment something about it.

If a tag-field is basically defined to hold a number, like the track number or the disc number ...
TRACK ... [#TRCK Track number/Position in set]
DISCNUMBER ... [#TPOS Part of a set]
... then someone should not fill such tag-fields with alpha text characters, ...
if the application would allow that at all.

You should use one dedicated tag-field for the media type.

The ID3 standard offers the tag field TMED.
"The 'Media type' frame describes from which media the sound originated."
Locate "TMED" on the web page ...
http://id3.org/id3v2.3.0
... and read the reference about the predefined media types.

DD.20140105.1946.CET

All ideas start is here:
/t/14613/1

But very shortly -

May (can) I write LP 1, LP 2, ... in the column "Discnumber" if it is marked vinyl number?
May (can) I write CD 1, CD 2, ... in the column "Discnumber" if it is marked CD's (compact disc) number?
May (can) I write A1, A2, ... , B1, B2, ... in the column "Track", if it is marked vinyl track number?
Or in the columns "Discnumber" and "Track" may (can) write only numbers? But no letters.
See attachment above.

I do not think that Mp3tag checks if you have stored standard-compliant data in a field. It only checks if there is data at all.
So I would assume that yes, your expression should lead to the correct results.

If you are not really sure, you may check the effect like this:

  • copy the format string from your action
  • close the action without executing it.
  • select a "normal" file and open Convert >Tag-Filename and paste the format string.
  • check what the preview shows. If it is the construction you want, the format string will work.

Do the same check for a compilation file.
I can hardly check this as I do not have your numbering scheme.

I think, you should apply the tag-field MEDIATYPE in each file to describe that this one track is related to a special kind of media type.
For example ...
MEDIATYPE=LP
DISCNUMBER=1
TRACK=1
... or ...
MEDIATYPE=CD
DISCNUMBER=1
TRACK=1

Then a part of the format string has to be changed to ...

$if($eql(%MEDIATYPE%,'LP'),$replace(%DISCNUMBER%,1,'A',2,'B'),%DISCNUMBER%)

DD.20140106.0945.CET

D:...$if($eql(%compilation%,1),Compilation,%artist%)[%year% - ]%album%[\%discnumber%]\%track%. %artist% - %title%

Thank you. This testing method works very well ! With that I will be able to check all of my expectations.

Mp3tag program allows the following entry "LP 1 , LP 2, ... , CD 1 , CD 2, ..." in a column "discnumber" and allows entry "A1 , A2, ... B1 , B2, ... 1 , 2, ..." in a column "track".

But completely universal script probably will not be able to create. Work will be carried out in several stages. So that :
a) the script " %track% " empty record to remain empty
" D: \ ... \ 00th Div ' flying boats made by sea - . Flac " ->
" D: \ ... \ . - Div ' forage cap flying through Juru.flac "
b ) while the script $num(%track%,2) overwrites "A1" to "00" !
" D: \ ... \ A1 . Ricky Valence - Sealed With A Kiss.flac " ->
" D: \ ... \ 00. Ricky Valence - Sealed With A Kiss.flac "
etc. Refer to the attachment .

Thank you very much for the explanation ! However, some programs do not recognize the tag - field " mediatype ". So for now I can not use it. But the media library for the classification of your method is very good, then processing work with my music file will be completed.

Both thank you very much .


The reference to some other programs is irrelevant, because you only need this tag field MEDIATYPE to create your favorite directory structure and filenames.

If you want to have the tag-data within your collection be compatible with other programs, then you should check the contents of the relevant tag-fields in your tagged files from within the other applications.

It would be helpful for the Mp3tag users to know, whether a DISCNUMBER set to 'A1' by Mp3tag is compatible with which other tagging-applications.

DD.20140106.1657.CET

DetlevD, Yes of course. I understood you.
For example, this program Xrecode http://xrecode.com/ does not allow script "mediatype". So when I transcode (recode) my music files, it can not create a file structure with reference to the tag "mediatype". But the discnumber LP 1, LP2 .. and track A1, B1, .. Xrecode understood well.
Look at attachment.
I have enough information to consideration paid to how to proceed with your music files.
Thank you.