Please help me with moving square brackets.

Advanced Renamer forum
#1 : 29/06-14 06:26
Ral
Ral
Posts: 1
Hello,
could somebody perhaps help me write a script (well, write it for me) that would move the square brackets from the beginning of a file to right before the 2nd square bracket text (or if none exists, to the end of a file)?

I mean to use it for renaming anime fansubs since the way they're released, they're alphabetically sorted by the fansub group's name. I would rather have them be sorted by the anime series name instead.

This is how most fansub release names looks like:

1. [Fansub] Series Name {ep#} [res][crc32].ext
2. [Fansub]_Series_Name_{ep#}_[res][crc32].ext
3. [Fansub] Series Name S# - {ep#} [res][crc32].ext
4. [Fansub] Series Name {ep#}.ext

And this is how I'd like to rename them as:

1-2. Series_Name_{ep#}_[Fansub]_[res][crc32].ext
3. Series_Name_S#_-_{ep#}_[Fansub]_[res][crc32].ext
4. Series_Name_{ep#}_[Fansub].ext

{ep#} is the episode number and consists of 1-4 digits, nothing more - "{}" was there just to differentiate from the square brackets and to make sure that "ep" is not in the name, while "S" for "Season" in "S#" is.

Sometimes "[res]" is also named as: "(res encode type)" or "[res][encode type]". So, I guess, the script should move the first square brackets + " " or "_" that's between it and the series name*, to right before whichever bracket type comes next.

* Or just the "_" if we start by changing all spaces to the underscores.
Also, for the 4th option, remove the space/underscrore that would otherwise appear for no reason at the end of the file.

Can anyone help me with that?


29/06-14 06:26
#2 : 29/06-14 12:35
Stefan
Stefan
Posts: 274
Reply to #1:

Your old names are not very consistent in file names, but we can try with RegEx.



FROM:
[Fansub] Series Name1 {ep#} [res][crc32].ext
[Fansub]_Series_Name2_{ep#}_[res][crc32].ext
[Fansub] Series Name3 S# - {ep#} [res][crc32].ext
[Fansub] Series Name4 {ep#}.ext

TO:
Series_Name1_{ep#}_[Fansub]_[res][crc32].ext
Series_Name2_{ep#}_[Fansub]_[res][crc32].ext
Series_Name3_S#_-_{ep#}_[Fansub]_[res][crc32].ext
Series_Name4_{ep#}_[Fansub].ext


UTILIZE:
3 times Replace Method (http://www.advancedrenamer.com/user_guide/metho d_replace)

1.) (do the main work)
Find: (\[.+?])(\s|_)(.+)(\{.+\})( |_)?([^[]+)?(\[.*)?
Replace: $3$4$6_$1_$7
Occ: All
[x]RegEx
To: Name


2.) (replace space with underscore)
Find: SAPCE
Replace: UNDERSCORE
Occ: All
[x]RegEx
To: Name


3.) (remove trailing underscore, e.g. on file #4)
Find: ^(.+)_$
Replace: $1
Occ: All
[x]RegEx
To: Name



If that don't work you may want to clean up your file names first and make them consistent before rearranging.

The 1.) part could be made a bit easier, but I have not more time right now to test this out.


29/06-14 12:35