Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: File renaming with Foobar2000 (Read 6188 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

File renaming with Foobar2000

Good evening.

I was wondering if it was possible to create temporary variables while using a file renaming script in foobar2000, eg, to store a temporary file name -- that way I could use the $replace() function to replace illegal characters in my filename with others...

(eg, if I have a question mark in the track title, I could tell foobar to $replace() it with an empty string?)

If it's possible, could anyone help me on how to implement this?

Thanks in advance,
Shade.

File renaming with Foobar2000

Reply #1
It should be enough to replace %title% with $replace(%title%,?,) in the masstagger script (at least it was in 0.8.3).  I think I remember reading that there are issues with trying to replace '/' and '\', but I honestly can't remember the details.  Which version are you using, and maybe someone can offer step-by-step instructions.

File renaming with Foobar2000

Reply #2
Quote
It should be enough to replace %title% with $replace(%title%,?,) in the masstagger script (at least it was in 0.8.3).  I think I remember reading that there are issues with trying to replace '/' and '\', but I honestly can't remember the details.  Which version are you using, and maybe someone can offer step-by-step instructions.
[a href="index.php?act=findpost&pid=359353"][{POST_SNAPBACK}][/a]

I'm using .9b13, but wouldn't using that command change my title in the mp3 file?

I also have .8.3 aside, in case .9b13 doesn't work, but it shouldn't be necessary, I think..

File renaming with Foobar2000

Reply #3
$replace(%title%,?,) does not affect the parameter %title%, but just returns the result of the process.

It's more like "copy the string that is stored in %title%, replace any question marks with an empty string, and return that new string".  The copy is amended, not the original.
I'm on a horse.

File renaming with Foobar2000

Reply #4
When you create new field-names in the tag editing dialog, notice how everything you type gets converted into uppercase, without '%' signs. TITLE, ALBUM, etc., etc. It's the same in various mass-tagger dialogs as well.

When you read values from fields, then the field-names are surrounded with '%'s.

So you don't have to worry when you just deal with %values%.

edit: spelling

File renaming with Foobar2000

Reply #5
I had this same question. When using the renaming feature and Foobar encounters an illegal character it currently replaces it with a " _ " (underscore). Instead I would just like a space (blank) when foobar encounters any illegal character.

File renaming with Foobar2000

Reply #6
This is my masstagger renaming script, operating on variables before renaming:
Code: [Select]
$num(%tracknumber%,2)- $trim($replace($replace(
$if($stricmp($left(%artist%,4),The ),$substr(%artist%,5,60),
$if($stricmp($left(%artist%,2),A ),$substr(%artist%,3,60),%artist%)),
$char(92), ,$char(47), ,'|',,<,,>,,'"',,*,,?,,:,, - , , -, ,- , ,'(',,')',,ß,ss,œ,
oe,æ,ae,',',,!,,$char(39),,.,,_, ,&,And,+,Plus,å,a,Å,A,ä,a,Ä,A,ö,o,Ö,O,
ø,o,ô,o,ò,o,ó,o,à,a,À,A,Â,A,Á,A,á,a,ë,e,é,e,É,E,ê,e,Ê,E,è,e,È,E,î,i,Î,I,
Ç,C,ç,c,ì,i,í,i,ñ,n,Ü,U,ü,u,ú,u,ù,u),    , ,   , ,  , )) - $trim(
$replace($replace($if($stricmp($left(%title%,4),The ),
$substr(%title%,5,60),$if($stricmp($left(%title%,2),A ),
$substr(%title%,3,60),%title%)),$char(92), ,$char(47), ,'|',,<,,>,,'"',,
*,,?,,:,, - , , -, ,- , ,'(',,')',,ß,ss,œ,oe,æ,ae,',',,!,,$char(39),,.,,_, ,&,And,
+,Plus,å,a,Å,A,ä,a,Ä,A,ö,o,Ö,O,ø,o,ô,o,ò,o,ó,o,à,a,À,A,Â,A,Á,A,á,a,ë,e,
é,e,É,E,ê,e,Ê,E,è,e,È,E,î,i,Î,I,Ç,C,ç,c,ì,i,í,i,ñ,n,Ü,U,ü,u,ú,u,ù,u),    , ,   , ,  , ))

It is an adaption of these perl-regexps, which operated directly on the filenames:
Code: [Select]
s/\&/ And /g;
y/åÅäÄöÖøôòóàÀÂÁáëéÉêÊèÈîÎÇçìíñÜüúù/aAaAoOooooaAAAaeeEeEeEiICciinUuuu/;
s/\((.+?)\)/\L$1\E/g; # ()
s/ß/ss/g;s/œ/oe/g;s/æ/ae/g;s/,|!|\'//g;s/\. |\_/ /g;
s/\.(?=.*\..+)//g; # Remove dots
s/- The |- A /- /g; s/^The //;
s/(?<![\d ])- / /g;
s/ +/ /g; # Reduce multiple spaces
s/ (?=\..+$)//g; # Remove last space


This metadata:

Artist: The Baguettes
Title: A Trip To Heaven (Ça Sonne Bien) (Acoustic)
Tracknumber: 3

will result in this filename:

03- Baguettes - Trip To Heaven ca sonne bien acoustic.mp3

The fb2k code is not optimised, and sometimes even redundant, but I hope this will inspire someone. If there is a good way to lowercase the content of parentheses, please contribute.

[span style='font-size:8pt;line-height:100%']Edit: The renaming script contained bugs. They are fixed and the code above is updated.[/span]

File renaming with Foobar2000

Reply #7
Quote
If there is a good way to lowercase the content of parentheses, please contribute.
[{POST_SNAPBACK}][/a]

[a href="http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Titleformat_Reference#.24lower.28a.29]$lower()[/url]?

File renaming with Foobar2000

Reply #8
Quote
This is my masstagger renaming script, operating on variables before renaming:

Is this in 0.8.3 or 0.9b13? If b13, how did you get it to operate on variables before renaming? For me, in b13, I can't get this to work no matter what I do.

File renaming with Foobar2000

Reply #9
Quote
If there is a good way to lowercase the content of parentheses, please contribute.


If you for instance just wanted to lowercase only the contents of the parentheses in the title tag you could use this code:

Code: [Select]
$lower($substr(%title%,$strchr(%title%,'('),$strrchr(%title%,')')))


Otherwise, you could just use $lower().

File renaming with Foobar2000

Reply #10
Quote
Is this in 0.8.3 or 0.9b13? If b13, how did you get it to operate on variables before renaming? For me, in b13, I can't get this to work no matter what I do.[a href="index.php?act=findpost&pid=361148"][{POST_SNAPBACK}][/a]
This is 0.8.3, but I could not save data in temp variables in this version either. I just tried it. [span style='font-size:8pt;line-height:100%'](Edit)[/span]

Quote
Quote
If there is a good way to lowercase the content of parentheses, please contribute.
If you for instance just wanted to lowercase only the contents of the parentheses in the title tag you could use this code:
Code: [Select]
$lower($substr(%title%,$strchr(%title%,'('),$strrchr(%title%,')')))


Otherwise, you could just use $lower().[a href="index.php?act=findpost&pid=361152"][{POST_SNAPBACK}][/a]

Thank you. The code would be something like:
1. Using your code, output the lowercased content of parentheses.
2. Output everything from parenthesis until next paranthesis.
3. Using your code, output the lowercased content of parentheses.

This metadata:
Artist: The Baguettes
Title: (A Trip) To Heaven (Ça Sonne Bien) (Acoustic)
Tracknumber: 3

would result in this filename:
03- Baguettes - trip To Heaven ca sonne bien acoustic.mp3
which adheres to the abovementioned perl regexps.

Now I only have to write the code. Um yes, and what happens when there are more interlieved text and parentheses? Like: (A Trip) To Heaven (Ça Sonne Bien) Acoustic (Live)? Maybe I try too hard. Is there a regex plugin or is some $regex() function planned for the new 0.9 version?

 

File renaming with Foobar2000

Reply #11
Quote
Thank you. The code would be something like:
1. Using your code, output the lowercased content of parentheses.
2. Output everything from parenthesis until next paranthesis.
3. Using your code, output the lowercased content of parentheses.

This metadata:
Artist: The Baguettes
Title: (A Trip) To Heaven (Ça Sonne Bien) (Acoustic)
Tracknumber: 3

would result in this filename:
03- Baguettes - trip To Heaven ca sonne bien acoustic.mp3
which adheres to the abovementioned perl regexps.

Now I only have to write the code. Um yes, and what happens when there are more interlieved text and parentheses? Like: (A Trip) To Heaven (Ça Sonne Bien) Acoustic (Live)? Maybe I try too hard. Is there a regex plugin or is some $regex() function planned for the new 0.9 version?
[a href="index.php?act=findpost&pid=361273"][{POST_SNAPBACK}][/a]


While this would be possible, I fear the code would become far too cumbersome to do what you ask. If there were something similar to a "while" statement or a "foreach" statement in TAGZ then it would be a lot easier.

I do agree though, having regexp support in foobar TAGZ would be excellent. I may be a windows user, but I've had plenty of experience with a bash shell and used Sed. Regexp are very powerful for modifying string data and would be of excellent use in foobar.