I'm trying to eliminate unnecessary or incompatible characters and replace spaces with underscores etc. in a huge folder of files once and for all

Greetings folks,

I apologise for starting a fresh thread on this subject as it's seems to be covered in the FAQ at Scripting Functions – Mp3tag Documentation but the only problem with this great information is that I'm a moron with no formal training in using or creating scripts and strings and all these funky things, so I'm finding it difficult to get my old brain around, to be frank with you all! :joy: :skull:

Would anybody be so kind as to help me work out what I need to input into the Convert > Tag - Filename > Format String field in order to turn a few thousand excessively long file names into something slightly shorter and more "internet-friendly" for the future, whilst maintaining the important details (so they are still easily searchable in cloud folders or raw hyperlink directories with no internal metadata search capacity) and also replacing spaces and all known "illegal" or unsafe characters (such as { , } , | , \ , ^ , ~ , [ , ] , ` etc. plus any more you know of?) so that when these files become an extension to a webpage URL, they don't become converted to a bunch of %'s and all that jazz which makes links even more hideously long! (Example, an ugly hyperlink like - https://archive.org/download/mediatimeline/1997-11-01-Helter%20Skelter-Time-Sanctuary%20Warehouse%20(Ratpack)-Denbigh%20Leisure%20Complex-Milton%20Keynes-UK-Lipmaster%20Mark%20feat.%20Evenson%20Allen-Part%201-192-71081665.mp3).

Ideally, it would be nice if a visitor can comfortably read what the file contains simply from the raw hyperlink pasted (wherever it isn't truncated, so maybe not Facebook, LOL) during the posting by other users of our archive...

For instance "https://archive.org/download/mediatimeline/1997-11-01-Helter_Skelter-Time-Sanctuary_Warehouse__Ratpack_-Denbigh_Leisure_Complex-Milton_Keynes-UK-Lipmaster_Mark_feat._Evenson_Allen-Part_1-192-71081665.mp3" is easier to read at a glance.

The web usually replaces spaces with %20, open brackets with %28 and close brackets with %29, so I'd want underscores replacing them so that doesn't happen...

Currently, all the files in the archive we're building are using custom ID3 tags to temporarily store more variables so that people who download these files have the option of easily re-tagging the entire collection locally using a format scheme they prefer. Not everybody needs all information embedded in the Album or Title field, but I'm still writing these details to the master files for myself and others who do (plus for future import to MusicBrainz, as and when I or somebody else has worked out a script or plug-in for this task, but that's another story covered here, if anybody's interested in giving feedback, I'll make sure to give you credit on the finished site - RaveBrainz: a MusicBrainz-compliant version of the RaveLibraryOnline - MusicBrainz - MetaBrainz Community Discourse)

TL;DR -

I need filenames to be generated from my own ID3 tags within many thousands of MP3, MP4, WMA, FLAC, M4A, WAV and any other media types which MP3Tag can handle.
Here are the extended tags we have embedded (obviously only readable/displayable in certain applications) -

Please tell me how to modify the current formula(?) below so that all spaces and regular () brackets, and unsafe characters ({ , } , | , \ , ^ , ~ , [ , ] , ` etc.) are replaced with _

My attempt! -
[%year%][-%promoter%][-%event%][-%set%][-%venue%][-%town_city%][-%state%][-%country%][-%artist%][~%notes%][-Part %track%][-%_video_width%x%_video_height%][-%_bitrate%][-%_file_size_bytes%]

Current output example -
1997-11-01-Helter Skelter-Time-Sanctuary Warehouse (Ratpack)-Denbigh Leisure Complex-Milton Keynes-UK-Lipmaster Mark feat. Evenson Allen-Part 1-192-71081665.mp3

I hope you understand my problem, and really appreciate all your help. :nerd_face:

Edit: In case you wondered, the NOTES field we're using is just for rare occassions when we have many different items with very vague information and need to use the user's collection name to help tell things apart, but it's usually empty.

Honestly - if you really want to remove unnecessary characters, then I would seriously consider to supply a lot less information in the link.

On the technical side: to generate a filename without a certain set of characters, try $replace() like
Format string: $replace([%year%][-%promoter%][-%event%][-%set%][-%venue%][-%town_city%][-%state%][-%country%][-%artist%][~%notes%][-Part %track%][-%_video_width%x%_video_height%][-%_bitrate%][-%_file_size_bytes%],{,_,},_,|,_,\,_,^,_,~,_,[,_,],_)
Check the preview if that leads to the desired results.
You can append the list of replacements if you find any more.

Thanks but that string is not translating into anything. :thinking:

That is why I asked to use the preview.
And then I would expect a little adventurousness and play around with the apostrophe and stuff.
I mean: you should be able to construct an expression for $replace() once you have seen the basic idea.
Anyway - try this:
Format string: $replace([%year%][-%promoter%][-%event%][-%set%][-%venue%][-%town_city%][-%state%][-%country%][-%artist%][~%notes%][-Part %track%][-%_video_width%x%_video_height%][-%_bitrate%][-%_file_size_bytes%],{,_,},_,|,_,\,_,^,_,~,_,[,_,],_)

Thanks, there's a space missing before your open square brackets in order to make it work so it looks like the solution is -

$replace([%year%][-%promoter%][-%event%][-%set%][-%venue%][-%town_city%][-%state%][-%country%][-%artist%][~%notes%][-Part %track%][-%_video_width%x%_video_height%][-%_bitrate%][-%_file_size_bytes%],{,_,},_,|,_,\,_,^,_,~,_, [,_,],_)

I appreciate the help, despite my ignorance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.