IPB

Welcome Guest ( Log In | Register )

> Notice!

Please take a minute to check our Frequently Asked Questions. Use Search to reveal possible related topics.

Also make sure you've read the Forum Guidelines before posting in this forum.

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Scripting Function that Derives DISCNUMBER from FOLDER
ragtag
post Sep 10 2017, 13:09
Post #1


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



For multiple disc albums, such as box sets, I usually name the individual discs, as an album sub-folder, this way -- but only when each disc does not have its own specific subtitle:

CD1
CD2
CD3
..etc.

Sometimes, when the name/title of the disc, as sub-folder, is known, I will add it so that the sub-folder title looks like this:

CD1. Title
CD2. Title
CD3. Title
...etc.

Mostly, the first example applies.

I wish to derive the Field: DISCNUMBER, from the folder/directory by means of a suitable script. No leading zeroes are required. However, it will be nice to see an optional script, which provides for leading zeroes in the disc number as well. smile.gif

From what I have learned so far, I was able to construct a suitable Action Group, which were successful, but I am certain there is a much better, more efficient way to trim the two first two characters, "CD", so only the numerical character is displayed. Furthermore, I do not know how to construct a script to apply whenever I have to derive the disc number from the second set of examples given above.

Could you please advise me?

For your information, the Action Group I came up with so far:

Format Value: DISCNUMBER
Format String: %_directory%

Then, Replace with Regular Expression in:

Field: DISCNUMBER
Regular Expression: right(%discnumber%,2)
Replace matches with: Blank

The aforementioned failed, so I tried this Action Group, which was successful:

Format Value: DISCNUMBER
Format String: %_directory%

Replace Field: DISCNUMBER
Original: CD
x with case sensitive comparison enabled


This post has been edited by ragtag: Sep 11 2017, 16:26
Go to the top of the page
 
+Quote Post
ohrenkino
post Sep 10 2017, 13:34
Post #2


Member


Group: Full Members
Posts: 9225
Joined: 9-December 09
From: Norddeutschland / Northern Germany
Member No.: 11458
Mp3tag Version: 2.85



ZITAT(ragtag @ Sep 10 2017, 14:09) *
...
Then, Replace with Regular Expression in:

Field: DISCNUMBER
Regular Expression: right(%discnumber%,2)
Replace matches with: Blank

The aforementioned failed, so I tried this Action Group, which was successful:

Of course, because it is no regular expression.

What about an action of the type "Guess value" for _DIRECTORY
Guessing pattern: CD%discnumber%

With a little extension the same type of action also works for the second set of CDs:
an action of the type "Guess value" for _DIRECTORY
Guessing pattern: CD%discnumber%. %dummy%

This post has been edited by ohrenkino: Sep 10 2017, 13:35


--------------------
42 - wie war die Frage / what was the question / quelle était la question
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 10 2017, 13:37
Post #3


Member


Group: Full Members
Posts: 6718
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.85



QUOTE (ragtag @ Sep 10 2017, 14:09) *
... I wish to derive the Field: DISCNUMBER, from the folder/directory ...

Action "Format value" ...
DISCNUMBER <== 
$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$','$2',1),'1')
$char(0)'If no match, then return 1, else return number from directory name'


DD.20170910.1442.CEST


... or just a 'quick and dirty' proposal ...
Apply Action "Format value" ...
DISCNUMBER <== $regexp(%_directory%,'\D',)


DD.20170910.1510.CEST

This post has been edited by DetlevD: Sep 10 2017, 14:10


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
stevehero
post Sep 10 2017, 13:42
Post #4


Member


Group: Full Members
Posts: 835
Joined: 3-December 10
From: Ireland
Member No.: 13334
Mp3tag Version: 2.84



Your 2nd action is missing the $ before right. But needs to be a format action.


But use this all in one action.

Use format action.

Format: DISCNUMBER
with: $regexp(%_directory%,.*CD(\d+).*,$1)

Edit: Noticed error with capture 1 in regexp

This post has been edited by stevehero: Sep 12 2017, 04:50


--------------------
Go to the top of the page
 
+Quote Post
ragtag
post Sep 10 2017, 18:42
Post #5


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



Thank you very much to all three of you, for your welcome advice. As you will have undoubtedly noticed already, I have zero in-depth knowledge and understanding of the subject at hand. The little bit I do have, I usually apply by trial and error. Mostly, I get along, but sometimes I am just so stuck, and then I am thankful that I can rely on experts like your good selves to assist me. I am always grateful for that.

Now I am off to go and try out your various proposals. smile.gif

This post has been edited by ragtag: Sep 11 2017, 13:50
Go to the top of the page
 
+Quote Post
ragtag
post Sep 18 2017, 17:25
Post #6


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



QUOTE
Format value" ...
DISCNUMBER <==
$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$','$2',1),'1')
$char(0)'If no match, then return 1, else return number from directory name'

Presently, the above script by DetlevD, seems to best fit the circumstance. There is, however, one drawback in my own application of it: When the script is applied, it will also number the single albums with disc number 1. I prefer to leave the disc number field of one-disc albums, blank/clean. Is it possible to revise the script to take care of this situation, while still allocating the appropriate individual disc number to multi-disc albums?

(Furthermore, is there another, perhaps simpler way, to derive each individual disc number from multi-disc albums- AND keep a single-disc album number blank? For instance, derive the disc number by counting the number of folders, and sequentially number them? In such a case, how would the correct number sequence be determined- if not from the folder description?). Please ignore the portion between brackets if it does not make sense. smile.gif

Thank you for your contribution.
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 18 2017, 19:48
Post #7


Member


Group: Full Members
Posts: 6718
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.85



QUOTE (ragtag @ Sep 18 2017, 18:25) *
... I prefer to leave the disc number field of one-disc albums, blank/clean. Is it possible to revise the script to take care of this situation, while still allocating the appropriate individual disc number to multi-disc albums? ...

Action "Format value" ...
DISCNUMBER <==
$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$','$2',1),)
$char(0)'If no match, then return nothing, else return number from directory n
ame
'


DD.20170918.2048.CEST

... or ...

$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)[\s_0]*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)[\s_0]*(\d+).*$','$2',1),)

DD.20170919.1430.CEST

This post has been edited by DetlevD: Sep 19 2017, 13:30


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
ragtag
post Sep 18 2017, 20:47
Post #8


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



Thank you, DetlevD! biggrin.gif

Edit: I do not see see if, and how, this is related, but I am posting my findings after applying the new script:

When applying Tag-to-Filename, I use, among others, the following Action:

Format Value ===>_FILENAME ===>$replace([%discnumber%-]%track%. %title%,/,·,",'',:,··,(,{,),},)

Instead of naming the file

"01. Filename.ext"

the resulting filename now is

"-01. Filename.ext"

How do I correct this Action to achieve the desired filename format for both single and multi-disc albums? For example:

"01. Filename.ext"

"02. Filename.ext"

"1-01. Filename.ext"

"2-01. Filename.ext"

Thank you.

This post has been edited by ragtag: Sep 19 2017, 08:28
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 19 2017, 09:24
Post #9


Member


Group: Full Members
Posts: 6718
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.85



QUOTE (ragtag @ Sep 18 2017, 21:47) *
... When applying Tag-to-Filename, I use, among others, the following Action:
Format Value ===>_FILENAME ===>$replace([%discnumber%-]%track%. %title%,/,·,",'',:,··,(,{,),},)
Instead of naming the file
"01. Filename.ext"
the resulting filename now is
"-01. Filename.ext" ...

There is a writing error in the $replace function, so maybe this works ...

$replace([%DISCNUMBER%'-']%TRACK%''%TITLE%,'/','·','"','''',':','··','(','{',')','}')

DD.20170919.1026.CEST

This post has been edited by DetlevD: Sep 19 2017, 09:26


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
ragtag
post Sep 19 2017, 11:29
Post #10


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



Thank you for spotting the error, DetlevD. I have never used the hyphens, and yet it still seemed to work in other Actions, which I have used up to now. Are these hyphens an imperative, and how does one tell when to use them, or not? Is it perhaps discussed somewhere so I can read more about its application?

Edit: I have now tried the revised Action, but the result is identical. I think I may have lost the plot completely, and I have to check all the Actions in this Group again. It definitely adds a blank space in the beginning of the file name:

_-01. Filename.txt (The "_" representing the blank space)

Edit 2: If I do not apply this Action:

QUOTE
Action "Format value" ...
DISCNUMBER <==
$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$','$2',1),)
$char(0)'If no match, then return nothing, else return number from directory n
ame'


The file names are named in the desired manner i.e. without the preceding blank space and the dash- as it did before the Action above was changed.

This post has been edited by ragtag: Sep 19 2017, 12:50
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 19 2017, 12:55
Post #11


Member


Group: Full Members
Posts: 6718
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.85



QUOTE (ragtag @ Sep 19 2017, 12:29) *
... Edit: I have now tried the revised Action, but the result is identical. ... It definitely adds a blank space in the beginning of the file name: _-01. Filename.txt (The "_" representing the blank space)

You have to check, whether there is a tagfield involved, which is named DISCNUMBER, which carries one or more space character?

DD.20170919.1355.CEST


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
ragtag
post Sep 19 2017, 14:21
Post #12


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



QUOTE (DetlevD @ Sep 19 2017, 13:55) *
You have to check, whether there is a tagfield involved, which is named DISCNUMBER, which carries one or more space character?

DD.20170919.1355.CEST


Thank you. Not yet sure why, but while looking for that elusive space character, the problem disappeared. I could have edited something inadvertently.

The need for the single hyphens in my replace function still baffles me, because the replace function seems to be working just fine without it.
Go to the top of the page
 
+Quote Post
DetlevD
post Sep 19 2017, 15:09
Post #13


Member


Group: Full Members
Posts: 6718
Joined: 26-May 06
From: Wuppertal, Germany, Planet Earth
Member No.: 3194
Mp3tag Version: 2.85



QUOTE (ragtag @ Sep 19 2017, 15:21) *
... The need for the single hyphens in my replace function still baffles me, because the replace function seems to be working just fine without it.

I want to mention:

The hyphen character U+002D (-) is a punctuation mark used to join words and to separate syllables of a single word.
See also ... https://en.wikipedia.org/wiki/Hyphen

The typewriter apostrophe character U+0027 (') is a punctuation mark used for several purposes.
See also ... https://en.wikipedia.org/wiki/Apostrophe

The Mp3tag function $replace is defined as ...
$replace(string,from,to)
... or ...
$replace(string,from1,to1,from2,to2[,... and so forth ...])

DD.20170919.1609.CEST


--------------------
* Beyond that, don't ask, when you don't know what to do with the answer. *
♥ home is where the heart is ♥
Go to the top of the page
 
+Quote Post
ragtag
post Sep 19 2017, 15:34
Post #14


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



QUOTE (DetlevD @ Sep 19 2017, 16:09) *
I want to mention:

The hyphen character U+002D (-) is a punctuation mark used to join words and to separate syllables of a single word.
See also ... https://en.wikipedia.org/wiki/Hyphen

The typewriter apostrophe character U+0027 (') is a punctuation mark used for several purposes.
See also ... https://en.wikipedia.org/wiki/Apostrophe

The Mp3tag function $replace is defined as ...
$replace(string,from,to)
... or ...
$replace(string,from1,to1,from2,to2[,... and so forth ...])

DD.20170919.1609.CEST


Sorry, I truly messed up my vocabulary in my post. When speaking about the hyphen, I was in fact referring to the use of the apostrophe. blush.gif

Thank you for correcting me, DetlevD. smile.gif
Go to the top of the page
 
+Quote Post
ragtag
post Sep 19 2017, 17:23
Post #15


Member


Group: Full Members
Posts: 76
Joined: 16-February 13
Member No.: 17578
Mp3tag Version: 2.84a



QUOTE (DetlevD @ Sep 18 2017, 20:48) *
Action "Format value" ...
DISCNUMBER <==
$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)\s*0*(\d+).*$','$2',1),)
$char(0)'If no match, then return nothing, else return number from directory n
ame
'


DD.20170918.2048.CEST

... or ...

$if($eql($regexp(%_directory%,'^(CD|DISC|DISK)[\s_0]*(\d+).*$',,1),),$regexp(%_directory%,'^(CD|DISC|DISK)[\s_0]*(\d+).*$','$2',1),)

DD.20170919.1430.CEST


DetlevD: The error was not eliminated, as I had previously thought. The first of the above two scripts somehow inserts a space into the DISCNUMBER tag. It applies a space for single-album discs, and space after the disc number too, for multi-disc albums. I do not know how to edit the regular expression to care of this problem. That said, I eventually tested the second one of the above two scripts, and so far it has performed splendidly. However, I will still appreciate it very much if you could show me where the first of the two expressions happened to insert the space into the DISCNUMBER field.

Thank you.
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 19th November 2017 - 15:00