IPB

Welcome Guest ( Log In | Register )

> foobar2000 Tech Support Forum Rules

Please read foobar2000 Tech Support Forum Rules before posting and comply with all the points.
Failure to provide all the information pointed out in the above document in your post is considered wasting other people's time and in extreme cases will lead to your topic getting locked without a reply.


See also: Hydrogenaudio Terms of Service.

2 Pages V   1 2 >  
Reply to this topicStart new topic
Changing the default "illegal character" replacement charact, want to change from the underscore to the hyphen
golphcart
post Sep 13 2006, 22:08
Post #1





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



Okay, this may be anal, but I hate the _ (underscore). It's evil and I never want to see it in my filenames. It's ugly. My opinion, of course. Right now, I am using a conjuction of $and() and $replace() to change illegal characters like ? ! > < (there are others I'm sure, but those are the ones I usually see in my tags) to a hyphen. I know this has got to be some kind of default, probably one that is easy to change, but I cannot find it (when you simply rename from file tags with these characters in it, it automagically changes them to the underscore). What I would like is to automagically change these to a - (hyphen). Is this possible?

Please and thanks.

golphcart.

EDIT: Okay, so the $replace() doesn't seem to work..., I thought it used to, but I guess I haven't done it in a while. It shows that it works in the preview line, when you edit a file naming scheme, but when you select the file naming scheme in the output file name format drop-down menu, the preview shows an underscore. Also illegal characters I actually see, after a more careful look are:
: / < ?

This post has been edited by golphcart: Sep 13 2006, 22:46
Go to the top of the page
+Quote Post
golphcart
post Sep 16 2006, 06:36
Post #2





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



Can someone read what I wrote in the 'EDIT' and comment on it, please. Even just saying I'm an anal f*ckstain would be grand.

Seriously, though, the $replace() method USED to work; what am I missing?

- teh golphcart.

This post has been edited by golphcart: Sep 16 2006, 06:38
Go to the top of the page
+Quote Post
david_dl
post Sep 16 2006, 06:58
Post #3





Group: Members
Posts: 604
Joined: 17-December 05
From: New Zealand
Member No.: 26461



The illegal characters for a windows filename are:
CODE
\ / : * ? " < > |
Go to the top of the page
+Quote Post
Cosmo
post Sep 16 2006, 08:41
Post #4





Group: Members
Posts: 913
Joined: 10-January 05
Member No.: 18979



I'm not sure I completely understand what you're doing. Have you tried using the $replace() function to replace underscores instead of the illegal characters?

exa: $replace(%artist% - %title%,_,-)

It works for me... but again, I aint sure I understandz you.

[ edit ~ it doesn't work in the preview, but the filename comes out right ]

This post has been edited by Cosmo: Sep 16 2006, 08:44
Go to the top of the page
+Quote Post
golphcart
post Sep 17 2006, 03:42
Post #5





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



QUOTE (Cosmo @ Sep 16 2006, 02:41) *
I'm not sure I completely understand what you're doing. Have you tried using the $replace() function to replace underscores instead of the illegal characters?

exa: $replace(%artist% - %title%,_,-)

It works for me... but again, I aint sure I understandz you.

[ edit ~ it doesn't work in the preview, but the filename comes out right ]


Nope. You don't. But that's fine. I have files which I tagged using illegal characters (i.e. cannot be used in a windows filename) in various tag fields. Thus when I try to rename from tag fields, foobar automatically changes these illegal characters (see david_dl's post) with an underscore. I would like them to be replaced with a hyphen. That's the dealio.

Hope the following pic will explain what I cannot in words:



Thanks.

- teh golphcart.

To clarify what is in the picture:

I did NOT edit the file naming script, just opened it for your viewing pleasure.

I DID test the file naming script by using on the files selected, and in fact the underscore was NOT removed. (As in the OUTPUT FILE NAME preview, NOT the FILE NAMING SCRIPT preview)

I DID try moving the files to another harddrive and back again using this script. (dunno what this would affect, but I did it)

I DID check to make sure these files are not read-only.

I DID try changing the filenaming script, using it, then change back to the filenaming script in the picture, and using it; same result occured. (again, dunno what this would affect, but I did it)
Go to the top of the page
+Quote Post
Cosmo
post Sep 17 2006, 04:45
Post #6





Group: Members
Posts: 913
Joined: 10-January 05
Member No.: 18979



I guess I should have tried more illegal characters. I only used ''\'' as a test, and it worked. dry.gif

try this one:
CODE
$replace($replace($replace($replace($replace($replace($replace($replace(%artist% - %album% - %tracknumber% - %title%,:,-),*,-),?,-),",-),<,-),>,-),|,-),_,-)

the following will replace underscores in existing filenames:
CODE
$replace(%filename%,_,-)


EDIT: after gob added further clarity to the issue (thanks!), I now see that the first script can be shortened a little more:
CODE
$replace($replace($replace($replace($replace($replace(%artist% - %album% - %tracknumber% - %title%,*,-),?,-),",-),<,-),>,-),_,-)

...or maybe there's an altogether better way...?

EDIT.2: lol, shame on me for not RTFM. After gfngfgf's insightful tip :
CODE
$replace(%artist% - %album% - %tracknumber% - %title%,*,-,?,-,",-,<,-,>,-,_,-)

...though you'll probably want to remove things like ''?'' instead of replace. Anyhow, you get the idea!

This post has been edited by Cosmo: Sep 17 2006, 07:41
Go to the top of the page
+Quote Post
gob
post Sep 17 2006, 05:13
Post #7





Group: Members
Posts: 412
Joined: 13-July 03
From: bc.ca
Member No.: 7732



i understand what you’re talking about. when using scripts to move and rename files, the $replace() function properly works with ?, <, >, *, and " for both the previews and the actual renaming of the files. but not with /, \, |, or :. when using the latter illegal chars, the preview boxes in the file naming scheme windows will show that $replace(%tag%,'/',-) works, however, the preview box in the move, rename, or copy files window will show that the / is still being replaced with _ and it will be renamed this way also.

you can however use $replace(%tag%,_,-) to replace the /, \, |, and : chars with a string of your choice, just change the - in that script with the string you want.

also, when using $replace(%tag%,_,-), the preview boxes in the file naming scheme windows will show that the / has not been replaced with a -. but the move, rename, or copy files window will, and the file will be renamed this way.

i agree the $replace() function should work with whatever chars you throw at it, and have them properly handled before they are modified for correct filenames.


here is the script that i use to move and rename my albums
CODE
$if(%artist%,$trim($replace($replace($replace($replace($replace($replace(%artist%,?,),<,{),>,}),'"',''),*,+),_,-)),unknown artist)/[%date%'.' ]$if(%album%,$trim($replace($replace($replace($replace($replace($replace(%album%,?,),<,{),>,}),'"',''),*,+),_,-)),unknown album)/$if(%discname%,$trim($replace($replace($replace($replace($replace($replace(%discname%,?,),<,{),>,}),'"',''),*,+),_,-))'/',[%disc%.])[$left(%tracknumber%,2). ]$trim($replace($replace($replace($replace($replace($replace(%title%,?,),<,{),>,}),'"',''),*,+),_,-))


This post has been edited by gob: Sep 17 2006, 06:07
Go to the top of the page
+Quote Post
gfngfgf
post Sep 17 2006, 07:19
Post #8





Group: Members
Posts: 899
Joined: 2-November 04
Member No.: 17951



slightly OT, but the $replace() function can take more than three arguments, so this:

CODE
$replace($replace(%title%,?,-),*,-)

is equivalent to:

CODE
$replace(%title%,?,-,*,-)

It just looks nicer, really.
Go to the top of the page
+Quote Post
gob
post Sep 17 2006, 15:38
Post #9





Group: Members
Posts: 412
Joined: 13-July 03
From: bc.ca
Member No.: 7732



QUOTE (gfngfgf @ Sep 17 2006, 02:19) *
slightly OT, but the $replace() function can take more than three arguments, so this:

CODE
$replace($replace(%title%,?,-),*,-)

is equivalent to:

CODE
$replace(%title%,?,-,*,-)

It just looks nicer, really.


nice. thanks for that info.
Go to the top of the page
+Quote Post
golphcart
post Sep 17 2006, 20:22
Post #10





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



Thanks for all the input, guys. Really helpful. But I am still wondering what I can do about the ':' & the '/' There is quite a few of them in album and title tags, and I really would like to replace them with a hyphen instead of an underscore.

Also, going back to my original post:

Is there any way to just make the default illegal character replacement a hyphen instead of an underscore? This would void all the messy replace issues, entirely.

This post has been edited by golphcart: Sep 17 2006, 21:37
Go to the top of the page
+Quote Post
Yotsuya
post Sep 17 2006, 20:55
Post #11





Group: Members
Posts: 1535
Joined: 8-May 06
Member No.: 30546



Try using $char(58) instead of :, and $char(47) instead of /

$replace(%title%,$char(58),-,$char(47),-)


--------------------
http://www.ubuntu.com
Go to the top of the page
+Quote Post
golphcart
post Sep 17 2006, 21:43
Post #12





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



same deal, yotsuya. it works in the file naming script preview, but not the output file name preview nor the actual output file name.

thanks though.
Go to the top of the page
+Quote Post
Cosmo
post Sep 17 2006, 21:57
Post #13





Group: Members
Posts: 913
Joined: 10-January 05
Member No.: 18979



QUOTE (golphcart @ Sep 17 2006, 15:22) *
I am still wondering what I can do about the ':' & the '/'

In my testing, I put all of the above mentioned illegal characters ( \ / : * ? " < > | ) into tags, and they were all converted to hyphens in the file name. What version of foobar2000 do you use?

I also wonder if windows version / settings could have effect?

This post has been edited by Cosmo: Sep 17 2006, 21:59
Go to the top of the page
+Quote Post
golphcart
post Sep 18 2006, 05:21
Post #14





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



QUOTE (Cosmo @ Sep 17 2006, 15:57) *
What version of foobar2000 do you use?


v0.9.3.1

QUOTE (Cosmo @ Sep 17 2006, 15:57) *
I also wonder if windows version / settings could have effect?


windows xp pro sp1

settings? not sure what you mean.

also, I don't think it is a windows issue (as I've stated in previous posts, I used to use $replace() with no problems), but then again, I can't remember specifically which characters I was replacing. It might not have been one of the four that seems to cause problems (from gob's post : / \ | ).

for now I have used your solution:

$replace(%filename%,_,-)

Thanks for all the help. I appreciate it.

This post has been edited by golphcart: Sep 18 2006, 05:22
Go to the top of the page
+Quote Post
Cosmo
post Sep 18 2006, 06:28
Post #15





Group: Members
Posts: 913
Joined: 10-January 05
Member No.: 18979



It also works in 0.9.3.1 for me. (same OS)

By ''settings'', I meant something like code page (character encoding). Wild guess.

Good luck!
Go to the top of the page
+Quote Post
golphcart
post Sep 18 2006, 07:47
Post #16





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



This is kind of repetitive but I'm going to post it anyways:

relevant tag info:
ALBUM=A Girl Like Me \ / : * ? " < > |

file naming scheme:
$replace(%album%,\,1,/,2,:,3,*,4,?,5,",6,<,7,>,8,|,9)

file naming scheme preview:
A Girl Like Me 1 2 3 4 5 6 7 8 9

output file names preview:
A Girl Like Me _ _ _ 4 5 6 7 8 _

say I actually ran this script to rename this to %album%.mp3
now I run a new file naming script:
$replace(%filename%,_,-)

my output is now:
A Girl Like Me - - - 4 5 6 7 8 -.mp3

so basically the $replace() function is useless for illegal characters' numbered 1 (\), 2 (/), 3 (:) and 9 (|)

Cosmo:

not sure really what you are asking (basically I am not exactly sure what a code page - character encoding is) but I did run charmap.exe to find out the corresponding hexadecimal codes for the troublesome characters, and I searched google for 'how to find windows code page' and after some links found one that had the same hexadecimal codes for the troublesome characters.

I use two fonts in foobar:
MS Sans Serif 8pt for playlist switcher
Verdana 10pt for playlist tabs

both had equal hex.dec. values for illegal chars in charmap
charmap hex.dec. values for illegal chars matched website
(http://www.microsoft.com/globaldev/reference/sbcs/1250.mspx)
I must say I have absolutely no idea if this is the code page that my comp uses but I assume it is. I live in the US and have no idea how to change my code page, and I dare say that this is the default.

codes:
\ 0x5c or $char(92)
/ 0x2f or $char(47)
: 0x3a or $char(58)
| 0x7c or $char(124)

also I checked the hyphen in both fonts for charmap and the website.
code:
- 0x2d or $char(45)

I guess that's a summary, of sorts.

- teh golphcart.

EDIT: goddamn smilies. :)

This post has been edited by golphcart: Sep 18 2006, 07:50
Go to the top of the page
+Quote Post
Cosmo
post Sep 18 2006, 08:39
Post #17





Group: Members
Posts: 913
Joined: 10-January 05
Member No.: 18979



I'm sorry about the confusion, I didn't mean to make it sound like I was asking you for your OS info, I was just wondering aloud. I don't know much about character encoding stuff either (and thus I could be way off base), but it seems that since the $replace() function is acting differently on our systems (in foobar of the same version), then perhaps the problem is outside of foobar. (I'm not aware of any settings within foobar that would cause this discrepancy.) Or maybe it's not the system, but something within the files?
Go to the top of the page
+Quote Post
kjoonlee
post Sep 18 2006, 09:01
Post #18





Group: Members
Posts: 2526
Joined: 25-July 02
From: South Korea
Member No.: 2782



The characters in \ / : * ? " < > | are all part of 7bit ASCII, so there shouldn't be any codepage problems with 8bit extensions to ASCII.

Maybe Cosmo uses NTFS and golphcart uses FAT32?


--------------------
http://blacksun.ivyro.net/vorbis/vorbisfaq.htm
Go to the top of the page
+Quote Post
golphcart
post Sep 18 2006, 09:08
Post #19





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



NTFS here.

more specifically...

one volume is NTFS basic and the other is NTFS dynamic

This post has been edited by golphcart: Sep 18 2006, 09:20
Go to the top of the page
+Quote Post
gob
post Sep 18 2006, 20:50
Post #20





Group: Members
Posts: 412
Joined: 13-July 03
From: bc.ca
Member No.: 7732



QUOTE (gfngfgf @ Sep 17 2006, 02:19) *
slightly OT, but the $replace() function can take more than three arguments, so this:

CODE
$replace($replace(%title%,?,-),*,-)

is equivalent to:

CODE
$replace(%title%,?,-,*,-)

It just looks nicer, really.



after modifing all my scripts that used multiple replace functions, i found out using $replace(%title%,' To ',' to ',' A ',' a ',' On ',' on ') will not always give the same result as $replace($replace($replace(%title%,' To ',' to '),' A ',' a '),' On ',' on ')

heres an example: if the title is "Your Pussy's Glued To A Building On Fire"
$replace(%title%,' To ',' to ',' A ',' a ',' On ',' on ') will produce
"Your Pussy's Glued to A Building on Fire"
$replace($replace($replace(%title%,' To ',' to '),' A ',' a '),' On ',' on ') will produce
"Your Pussy's Glued to a Building on Fire"

this is very odd and confusing behaviour..
Go to the top of the page
+Quote Post
pepoluan
post Sep 18 2006, 21:07
Post #21





Group: Members
Posts: 1455
Joined: 22-November 05
From: Jakarta
Member No.: 25929



QUOTE (gob @ Sep 19 2006, 02:50) *
heres an example: if the title is "Your Pussy's Glued To A Building On Fire"
$replace(%title%,' To ',' to ',' A ',' a ',' On ',' on ') will produce
"Your Pussy's Glued to A Building on Fire"
$replace($replace($replace(%title%,' To ',' to '),' A ',' a '),' On ',' on ') will produce
"Your Pussy's Glued to a Building on Fire"

this is very odd and confusing behaviour..

My guess is the multi-parameter $replace works like this:
CODE
Your Pussy's Glued To A Building On Fire
0123456789012345678901234567890123456789
0         1         2         3

* It searches for anything resembling the searched-for pattern, i.e. ' To ', ' A ', and ' On ' (note the spaces on left and right.
* It finds ' To ' at position 18.
* It replaces ' To ' with ' to ', and shifts the pointer to after the end of the found pattern, i.e. the pointer is now pointing at position 22, which means that the current pattern is 'A ' not ' A ' ( ' A ' is found at position 21).
* It keeps scanning until it finds ' On ' at position 32.
* It replaces ' On ' with ' on ', and resumes at position 36.
*Finish.

CMIIW

I'm sleepy, going offline, bye!


--------------------
Nobody is Perfect.
I am Nobody.

http://pandu.poluan.info
Go to the top of the page
+Quote Post
golphcart
post Sep 19 2006, 00:40
Post #22





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



gob:

I think an easy way to fix that is to ditch the space to the left of the words (all of them).

$replace(%title%,'To ','to ','A ','a ','On ','on ')

Now you don't have the potential for 'overlapping' spaces. This would still do what you want I think unless you have some word with a capital letter mid-word. I can't think of a good example so I'll give a bad (but still failing) example:

Dr McTo Eats Butterflies for Breakfast

would be replaced to

Dr Mcto Eats Butterflies for Breakfast
Go to the top of the page
+Quote Post
gob
post Sep 19 2006, 02:43
Post #23





Group: Members
Posts: 412
Joined: 13-July 03
From: bc.ca
Member No.: 7732



QUOTE (golphcart @ Sep 18 2006, 19:40) *
gob:

I think an easy way to fix that is to ditch the space to the left of the words (all of them).

$replace(%title%,'To ','to ','A ','a ','On ','on ')

Now you don't have the potential for 'overlapping' spaces. This would still do what you want I think unless you have some word with a capital letter mid-word. I can't think of a good example so I'll give a bad (but still failing) example:

Dr McTo Eats Butterflies for Breakfast

would be replaced to

Dr Mcto Eats Butterflies for Breakfast


yea, but i dont want any of these words to be replaced unless there is a space in front of them. so multiple replace functions are needed. either way, if it works using 15 replace functions, thats what i will do.
Go to the top of the page
+Quote Post
golphcart
post Oct 4 2006, 23:47
Post #24





Group: Members
Posts: 99
Joined: 18-May 06
Member No.: 30918



Old solution:

$replace(%tag%,\,-,/,-,:,-,*,-,?,,",-,<,-,>,-,|,-)
$replace(%filename%,_,-)

But this did not work when trying to change path based on tags, and was two steps.

New solution:

$replace($replace(%tag%,\,-,/,-,:,-,*,-,?,,",-,<,-,>,-,|,-),_,-)

Now this replaces all the baddies that cannot be replaced normally.

Still brings up the question: Why do these 4 characters not want to be replaced?
Go to the top of the page
+Quote Post
Ydope
post Oct 29 2007, 22:09
Post #25





Group: Members
Posts: 18
Joined: 7-February 07
Member No.: 40393



QUOTE (golphcart @ Sep 18 2006, 07:47) *
This is kind of repetitive but I'm going to post it anyways:

relevant tag info:
ALBUM=A Girl Like Me \ / : * ? " < > |

file naming scheme:
$replace(%album%,\,1,/,2,:,3,*,4,?,5,",6,<,7,>,8,|,9)

file naming scheme preview:
A Girl Like Me 1 2 3 4 5 6 7 8 9

output file names preview:
A Girl Like Me _ _ _ 4 5 6 7 8 _

say I actually ran this script to rename this to %album%.mp3
now I run a new file naming script:
$replace(%filename%,_,-)

my output is now:
A Girl Like Me - - - 4 5 6 7 8 -.mp3

so basically the $replace() function is useless for illegal characters' numbered 1 (\), 2 (/), 3 (:) and 9 (|)


Hi,

sorry to bring this old thread back, but this is exactly my problem.

I have some cases where %ALBUM ARTIST% = e.g. "Jim / John" and I want the directory name to look like "Jim & John". When I $replace " / " with " & " it doesn't work but I get "Jim _ John". Just as described above.

So how can I find a solution that does what I want but leaves Album Artists that may already include underscores for whatever reason in order. I don't want to replace every " _ " with " & ".

Any idea? This is really bugging me.

Great thanks in advance,
Y

This post has been edited by Ydope: Oct 29 2007, 22:10
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: 17th September 2014 - 07:19