Help for Automagic Do-All Action

I am looking for an action that will remove from filenames any character(s) other than dash, underscore, letters and numbers. Does anyone have an example or a solution to this besides creating a replace action for each character that is to be omitted?

My goal is to have one action that (after tagging all mp3's correctly) will remove all unsupported characters from the filename, then put the filename in the format of artist-album-track-title.extension in lowercase and with underscores instead of spaces. So far, I've all the actions for this except one to remove unsupported characters.

Any help would be greatly appreciated.

BTW, this is such a marvelous application.

1 Like

Why do you need to clean the filename first when you are generating it a moment later based on the tag information?

Anyways, I have to jet to school right now, but have a look at these functions in https://docs.mp3tag.de/scripting :

$replace()
$validate()
$lower()

I'm actually cleaning the filename after it is generated from the tags. As far as I know, the validate function only removes these characters: /?*"<>|.

I'm trying to make something that will keep a character if it is a letter, number, underscore or dash. If it is not, it will remove it.

Hmm... Well, it can be done with RegEx (dano knows more about RegEx than me), but are you sure you want that? It would also change "That's_it" into "Thats_it".

That's what I'm trying to do.

Based on these parts of the help file on scripting,

  • $if(x,y,z) if x is true, y is returned, otherwise z.
  • "\w" Any word character - all alphanumeric characters plus the underscore.
  • The dot character "." matches any single character.
I'm trying to do something like this:

Format Value:
Field: _FILENAME
Format String: $if(character= (\w or -), leave alone, delete)

but can't achieve the proper syntax.

You cannot mix the different action types.
Things like \w are only available at Replace with regular expressions

You can make an action Replace with regular expressions, but it will also remove the dot before the file extension, you will need a 2nd action to put it back:

Action #1:
Action type: Replace with regular expressions
Field: _FILENAME
Regular expression: [^-\w]
Replace matches with:

[ ] case-sensitive comparison

Action #2:
Action type: Replace with regular expressions
Field: _FILENAME
Regular expression: (mp3)$
Replace matches with: .$1

[ ] case-sensitive comparison

Thanks Dano that worked great. This is my action now:

Action #1:
Action type: Format value
Field: _FILENAME
Formatstring: %artist%-%album%-$num(%track%,2)-%title%

Action #2:
Action type: Case conversion
Field: _FILENAME
Case conversion: lower case
Words begin from/after any of:

Action #3:
Action type: Remove fields
Fields to remove (semicolon-separated): Comment

Action #4:
Action type: Replace with regular expression
Field: _ALL
Regular expression: ^\s+
Replace matches with:

[ ] case-sensitive comparison

Action #5:
Action type: Replace with regular expression
Field: _ALL
Regular expression: \s+$
Replace matches with:

[ ] case-sensitive comparison

Action #6:
Action type: Replace with regular expression
Field: _FILENAME
Regular expression: \s+.(mp3|m4a|flac|ogg|mpc|wma)$
Replace matches with: .$1

[ ] case-sensitive comparison

Action #7:
Action type: Replace with regular expression
Field: _ALL
Regular expression: \s{2,}
Replace matches with:

[ ] case-sensitive comparison

Action #8:
Action type: Replace with regular expression
Field: FILENAME
Regular expression: \s
Replace matches with:

[ ] case-sensitive comparison

Action #9:
Action type: Replace with regular expression
Field: _FILENAME
Regular expression: [^-\w]
Replace matches with:

[ ] case-sensitive comparison

Action #10:
Action type: Replace with regular expression
Field: _FILENAME
Regular expression: (mp3|m4a|flac|ogg|mpc|wma)$
Replace matches with: .$1

[ ] case-sensitive comparison

Does everything look clean? I'm trying to avoid redundancy and going about things the wrong way.

Moderation: Formatted raw action file that was posted.

I think it's ok. But you could change the first one to
$lower(%artist%-%album%-$num(%track%,2)-%title%)
and remove the second.

Awesome. Thanks a bunch dano and Sebastian Mares.