comparison bin/ren @ 13:97f46d6a11d3

Improved (as in, even more monstrous) ren.
author Edho Prima Arief <me@myconan.net>
date Tue, 03 Aug 2010 21:15:04 +0700
parents 8a0391d8e8d0
children b975a587f8f6
comparison
equal deleted inserted replaced
10:876f2c45eeae 13:97f46d6a11d3
7 my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1); 7 my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1);
8 my $skip=0; 8 my $skip=0;
9 foreach (@files) { 9 foreach (@files) {
10 my $newname = $_; 10 my $newname = $_;
11 print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_; 11 print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
12 $newname =~ s/ \'[^']+\'//;
13 #$newname =~ s/ Kiss x Sis OVA / Kiss x Sis OAD /;
14 $newname =~ s/x264//;
15 $newname =~ s/ - 0/ - /;
16 $newname =~ s/\[HorribleSubs\] Lilpri /[HorribleSubs] Hime Chen! Otogi Chikku Idol Lilpri - /i;
17 $newname =~ s/\[HorribleSubs\] Uraboku /[HorribleSubs] Uragiri wa Boku no Namae wo Shitteiru - /i;
18 $newname =~ s/ GIG E/ GIG - /;
19 $newname =~ s/^Kidou_Keisatsu_Patlabor_\(1990\)_-_([[:digit:]]+)\[16\]_-_.+_\[640x480\]\[DVD\]\[A-Et\]\[([[:xdigit:]]{8})\]\.(mkv)$/[A-Et] Patlabor (1990) - $1 [DVD][${2}].$3/;
20 $newname =~ s/^Witchblade_-_([[:digit:]]+)\[24\]_-_.+\[(Makoto|AniSubs)\]\[([[:xdigit:]]{8})\]\.(mkv)$/[$2] Witchblade - $1 [DVD][${3}].$4/;
21 $newname =~ s/^Witchblade - ([[:digit:]]+) \[24\] - .+\[(Makoto|AniSubs)\]\[([[:xdigit:]]{8})\]\[v2\]\.(mkv)$/[$2] Witchblade - $1 [DVD][v2][${3}].$4/;
12 $newname =~ s/Sakura\.Wars\.([[:digit:]]{2}).*/[AM] Sakura Wars - $1.mkv/; 22 $newname =~ s/Sakura\.Wars\.([[:digit:]]{2}).*/[AM] Sakura Wars - $1.mkv/;
23 $newname =~ s/^Black Lagoon Omake /[OCZ] Black Lagoon - Special /;
24 $newname =~ s/_AIR_/ Air /;
25 $newname =~ s/\(b-a\)/[B-A] /i;
26 #$newname =~ s/ ([[:digit:]]{2}) / 0$1 /;
27 #$newname =~ s/^Feather #([[:digit:]]{2}) .*(\.mkv)$/[DmonHiro] Sekirei - $1$2/;
28 #$newname =~ s/(Galaxy Angel)/$1 S3 - /;
13 #$newname =~ s/Legend Of The Crystals OAV - 0/- Legend of the Crystals OVA - /; 29 #$newname =~ s/Legend Of The Crystals OAV - 0/- Legend of the Crystals OVA - /;
14 #$newname =~ s/^Kaleido_Star_-_([[:digit:]]{2}).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - $1 [DVD]$2/i; 30 #$newname =~ s/^Kaleido_Star_-_([[:digit:]]{2}).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - $1 [DVD]$2/i;
15 #$newname =~ s/^Kaleido_Star_-_Clean_ED([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Ending $1 (Clean) [DVD]$2/i; 31 #$newname =~ s/^Kaleido_Star_-_Clean_ED([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Ending $1 (Clean) [DVD]$2/i;
16 #$newname =~ s/^Kaleido_Star_-_Clean_OP([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Opening $1 (Clean) [DVD]$2/i; 32 #$newname =~ s/^Kaleido_Star_-_Clean_OP([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Opening $1 (Clean) [DVD]$2/i;
17 #$newname =~ s/.*_-_([[:digit:]]{2})\[47\].*(\[[[:xdigit:]]{8}\]\.mkv)$/[AniMecha] - $1 [DVD]$2/i; 33 #$newname =~ s/^Kidou Keisatsu Patlabor \(1989\) - ([[:digit:]]{2}) \[47\].*(\[[[:xdigit:]]{8}\])v2(\.[^.]+)$/[AM] Patlabor (1989) - $1 [DVD][v2] $2$3/i;
18 #$newname =~ s/.*\.([[:digit:]]{2})\.\[.*([[:xdigit:]]{8}\]\.mkv)$/[Arigatou] Blade of the Immortal - $1 [$2/i; 34 #$newname =~ s/.*_-_([[:digit:]]{2})\[26\].*(\[[[:xdigit:]]{8}\]\.avi)$/[Triad] Akagi - $1 $2/i;
35 #$newname =~ s/^.*\.([[:digit:]]{2})\..*\.mkv$/[AM] Neo Ranga - $1.mkv/;
19 #$newname =~ s/.* ([[:digit:]]+) .*/[AonE-AnY] Ah My Goddess - $1.avi/; 36 #$newname =~ s/.* ([[:digit:]]+) .*/[AonE-AnY] Ah My Goddess - $1.avi/;
20 #$newname =~ s/\[24-\(Final\)\]_/24 [End]/; 37 #$newname =~ s/\[24-\(Final\)\]_/24 [End]/;
21 #$newname =~ s/\[([[:digit:]]{2})\]/$1/; 38 #$newname =~ s/\[([[:digit:]]{2})\]/$1/;
22 #$newname =~ s/^Otaku no Musume-san c([[:digit:]]+) \[v03\](\[.+\])\.zip$/Otaku no Musume-san - $1 (v03) $2.zip/i; 39 #$newname =~ s/^Otaku no Musume-san c([[:digit:]]+) \[v03\](\[.+\])\.zip$/Otaku no Musume-san - $1 (v03) $2.zip/i;
23 #$newname =~ s/ HQ //; 40 #$newname =~ s/ HQ //;
24 $newname =~ s/xvid//i; 41 $newname =~ s/xvid//i;
42 $newname =~ s/\(-mp3\)//;
25 $newname =~ s/^\[Doremi\]\.HeartCatch\.PreCure!\.([[:digit:]]{2})\.\[1280x720\]\.\[([[:xdigit:]]{8})\]\.mkv$/[Doremi] HeartCatch PreCure! - $1 (1280x720) [$2].mkv/; 43 $newname =~ s/^\[Doremi\]\.HeartCatch\.PreCure!\.([[:digit:]]{2})\.\[1280x720\]\.\[([[:xdigit:]]{8})\]\.mkv$/[Doremi] HeartCatch PreCure! - $1 (1280x720) [$2].mkv/;
26 $newname =~ s/^\[Doremi\]\.Motto\.Ojamajo\.Doremi\.([[:digit:]]{2})\.\[([[:xdigit:]]{8})\]\.avi$/[Doremi] Motto Ojamajo Doremi - $1 [$2].avi/; 44 $newname =~ s/^\[Doremi\]\.Motto\.Ojamajo\.Doremi\.([[:digit:]]{2})\.\[([[:xdigit:]]{8})\]\.avi$/[Doremi] Motto Ojamajo Doremi - $1 [$2].avi/;
27 $newname =~ s/^(Detective Conan - [[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/; 45 $newname =~ s/^(Detective Conan - [[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/;
46 $newname =~ s/^(Detective Conan - [[:digit:]]+-?[[:digit:]]*) (\[Kienai[^]]*\])(.+)$/$2 $1 $3/;
28 $newname =~ s/^(Detective Conan - OVA[[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/; 47 $newname =~ s/^(Detective Conan - OVA[[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/;
29 $newname =~ s/^(Kamen Rider W - [[:digit:]]+)HD (\[W-Time\])(.+)$/$2 $1 $3/; 48 $newname =~ s/^(Kamen Rider W - [[:digit:]]+)HD (\[W-Time\])(.+)$/$2 $1 $3/;
30 $newname =~ s/- TV -/-/; 49 $newname =~ s/- TV -/-/;
31 $newname =~ s/^(\[Keroro\])\.([[:digit:]]+)\..*(\[[[:xdigit:]]{8}\].+)$/$1 Keroro Gunsou - $2 $3/; 50 $newname =~ s/^(\[Keroro\])\.([[:digit:]]+)\..*(\[[[:xdigit:]]{8}\].+)$/$1 Keroro Gunsou - $2 $3/;
32 $newname =~ s/SubDESU(.*)_-_Directors_Cut/SubDesu$1/; 51 $newname =~ s/SubDESU(.*)_-_Directors_Cut/SubDesu$1/;
33 $newname =~ s/\[480p\]\.mkv$/.mkv/; 52 $newname =~ s/\[(480p|360p)\]//;
34 $newname =~ s/^(\[EG\])ZZ_Gundam_BD_([[:digit:]]+)\(720p\)(.+)$/$1 Gundam ZZ - $2 (960x720) [BD]$3/; 53 $newname =~ s/^(\[EG\])ZZ_Gundam_BD_([[:digit:]]+)\(720p\)(.+)$/$1 Gundam ZZ - $2 (960x720) [BD]$3/;
35 $newname =~ s/\]_Working_-/] Working!! -/; 54 $newname =~ s/\]_Working_-/] Working!! -/;
36 $newname =~ s/WORKING!!/Working!!/; 55 $newname =~ s/WORKING!!/Working!!/;
37 $newname =~ s/\[Retrofit\]_\[Ayako-m\.3\.3\.w\.\]/[Retrofit-Ayako-m.3.3.w]/i; 56 $newname =~ s/\[Retrofit\]_\[Ayako-m\.3\.3\.w\.\]/[Retrofit-Ayako-m.3.3.w]/i;
38 $newname =~ s/Rosario\+Vampire/Rosario + Vampire/i; 57 $newname =~ s/Rosario\+Vampire/Rosario + Vampire/i;
39 $newname =~ s/Rosario \+ Vampire - Capu2 - /Rosario + Vampire Capu 2 - /i; 58 $newname =~ s/Rosario \+ Vampire - Capu2 - /Rosario + Vampire Capu 2 - /i;
40 $newname =~ s/ Hidamari Sketch Hoshimittsu / Hidamari Sketch - Hoshi Mittsu /i; 59 $newname =~ s/ Hidamari Sketch Hoshimittsu / Hidamari Sketch - Hoshi Mittsu /i;
41 $newname =~ s/ HEROMAN / Heroman /i; 60 $newname =~ s/ HEROMAN / Heroman /i;
42 #$newname =~ s/^/[ETB]/i; 61 #$newname =~ s/^/[ETB]/i;
43 $newname =~ s/_/ /g; 62 $newname =~ s/_/ /g;
63 $newname =~ s/ asobi ni ikuyo / Asobi ni Iku Yo! /i;
64 $newname =~ s/ Eve no Jikan / Time of Eve /i;
65 $newname =~ s/ DVD +\[/ [DVD][/i;
66 $newname =~ s/^(.+)\[(Z-Z)\](.+)$/[$2] $1 $3/;
67 $newname =~ s/\[62\] - .*\[DVD\]/[DVD]/;
68 $newname =~ s/S0/Special /;
69 $newname =~ s/\(1080p\)/(1920x1080)/;
70 $newname =~ s/ Seikimatsu Occult Gakuin / Occult Academy /;
71 $newname =~ s/ rockman exe axess / Rockman.EXE Axess /i;
72 $newname =~ s/\[& MP3\]//;
73 $newname =~ s/\[AAC\]//;
74 $newname =~ s/ DVD \[/[DVD][/i;
75 $newname =~ s/\[720 \(853\)x480\]\[x264 & HE-AAC\]//;
76 $newname =~ s/ Ep - ([[:digit:]]+) / - $1 /;
77 $newname =~ s/ Asobi ni Ikuyo! / Asobi ni Iku Yo! /i;
78 $newname =~ s/ \(Directors Cut\) / /;
79 $newname =~ s/ KimiKiss Pure Rouge / kimikiss pure rouge /i;
80 $newname =~ s/ HIGHSCHOOL OF THE DEAD / High School of the Dead /i;
44 $newname =~ s/ ARIA The ORIGINATION / Aria the Origination /i; 81 $newname =~ s/ ARIA The ORIGINATION / Aria the Origination /i;
82 $newname =~ s/ Shinseiki Evangelion / Evangelion /;
83 $newname =~ s/ Kuro no Keiyakusha / The Black Contractor /i;
84 $newname =~ s/ Darker than Black / Darker than Black /i;
45 $newname =~ s/ ARIA The NATURAL / Aria the Natural /i; 85 $newname =~ s/ ARIA The NATURAL / Aria the Natural /i;
46 $newname =~ s/^Clannad Ep([[:digit:]]+) \[1080p,BluRay,x264\] - THORA\.mkv$/[THORA] Clannad - $1 (1920x1080) [BD].mkv/i; 86 $newname =~ s/^Clannad Ep([[:digit:]]+) \[1080p,BluRay,x264\] - THORA\.mkv$/[THORA] Clannad - $1 (1920x1080) [BD].mkv/i;
47 $newname =~ s/ Mahou Kishi Rayearth / Magic Knight Rayearth /i; 87 $newname =~ s/ Mahou Kishi Rayearth / Magic Knight Rayearth /i;
48 $newname =~ s/rune soldier ep/ Rune Soldier /i; 88 $newname =~ s/rune soldier ep/ Rune Soldier /i;
49 $newname =~ s/ Harukanaru Toki no Naka de Hachiyoushou / Haruka Naru Toki no Naka de - Hachiyoushou /i; 89 $newname =~ s/ Harukanaru Toki no Naka de Hachiyoushou / Haruka Naru Toki no Naka de - Hachiyoushou /i;
56 $newname =~ s/ \(BD-720p\) \[/ (1280x720) [BD][/i; 96 $newname =~ s/ \(BD-720p\) \[/ (1280x720) [BD][/i;
57 $newname =~ s/ TV Ep/ - /i; 97 $newname =~ s/ TV Ep/ - /i;
58 $newname =~ s/\] AIR - /] Air - /i; 98 $newname =~ s/\] AIR - /] Air - /i;
59 $newname =~ s/ - Episode / - /i; 99 $newname =~ s/ - Episode / - /i;
60 $newname =~ s/\[divx[[:digit:].]+\]//i; 100 $newname =~ s/\[divx[[:digit:].]+\]//i;
61 $newname =~ s/\[BD\] \(1280x720\) \[/(1280x720) [BD][/i; 101 $newname =~ s/\[BD\] \((1280x720|1920x1080)\) \[/($1) [BD][/i;
62 $newname =~ s/ Seiken no Blacksmith / The Sacred Blacksmith /i; 102 $newname =~ s/ Seiken no Blacksmith / The Sacred Blacksmith /i;
63 #$newname =~ s/^Rizelmine([[:digit:]]+)\.avi$/[AC] Rizelmine - $1.avi/i; 103 #$newname =~ s/^Rizelmine([[:digit:]]+)\.avi$/[AC] Rizelmine - $1.avi/i;
64 $newname =~ s/\[v2\]/v2/i; 104 #$newname =~ s/\[v2\]/v2/i;
105 $newname =~ s/v2/[v2]/i;
65 $newname =~ s/\.AAC\]//; 106 $newname =~ s/\.AAC\]//;
66 $newname =~ s/ No / no /g; 107 $newname =~ s/ No / no /g;
67 #$newname =~ s/ 0([[:digit:]]) / $1 /; 108 #$newname =~ s/ 0([[:digit:]]) / $1 /;
68 $newname =~ s/\[1280x720\]/(1280x720) /; 109 $newname =~ s/\[(1280x720|1024x576)\]/($1) /;
69 #$newname =~ s/^.*( [[:digit:]]{2}v2).*(\[[[:xdigit:]]{8}\]\.mkv)$/[KAA] Ai Yori Aoshi - $1 [DVD]$2/; 110 #$newname =~ s/^.*( [[:digit:]]{2}v2).*(\[[[:xdigit:]]{8}\]\.mkv)$/[KAA] Ai Yori Aoshi - $1 [DVD]$2/;
70 $newname =~ s/ True Tears / true tears /i; 111 $newname =~ s/ True Tears / true tears /i;
71 $newname =~ s/ Fate stay night TV Reproduction / Fate-stay night - TV Reproduction /i; 112 $newname =~ s/ Fate stay night TV Reproduction / Fate-stay night - TV Reproduction /i;
72 $newname =~ s/ The Tatami Galaxy \(Yojouhan Shinwa Taikei\) / The Tatami Galaxy /i; 113 $newname =~ s/ The Tatami Galaxy \(Yojouhan Shinwa Taikei\) / The Tatami Galaxy /i;
73 $newname =~ s/ Saint Seiya The Lost Canvas / Saint Seiya - The Lost Canvas /i; 114 $newname =~ s/ Saint Seiya The Lost Canvas / Saint Seiya - The Lost Canvas /i;
118 #$newname =~ s/v2 (?=\(.*\) ) \[/ $1 [v2][/; 159 #$newname =~ s/v2 (?=\(.*\) ) \[/ $1 [v2][/;
119 $newname =~ s/([^ ])\[DVD\]\[x264\.AAC\]/$1 [DVD]/; 160 $newname =~ s/([^ ])\[DVD\]\[x264\.AAC\]/$1 [DVD]/;
120 $newname =~ s/\(DVD\) +\[/[DVD][/; 161 $newname =~ s/\(DVD\) +\[/[DVD][/;
121 $newname =~ s/^(\[[^]]+\])([^ ])/$1 $2/; 162 $newname =~ s/^(\[[^]]+\])([^ ])/$1 $2/;
122 $newname =~ s/(\((1280x720|960x720)[^)]*\))/($2)/; 163 $newname =~ s/(\((1280x720|960x720)[^)]*\))/($2)/;
123 $newname =~ s/(\((1920x1080)[^)]*\)) /($2) [BD]/; 164 #$newname =~ s/(\((1920x1080)[^)]*\)) /($2) [BD]/;
124 $newname =~ s/\[[^]]*720p[^]]*\] ?/(1280x720) /; 165 $newname =~ s/\[[^]]*720p[^]]*\] ?/(1280x720) /;
125 $newname =~ s/\[[^]]*1080p[^]]*\] ?/(1920x1080) /; 166 $newname =~ s/\[[^]]*1080p[^]]*\] ?/(1920x1080) /;
126 $newname =~ s/\(720p\)/(1280x720)/; 167 $newname =~ s/\(720p\)/(1280x720)/;
127 $newname =~ s/\[1280x720[^]]+\]/ (1280x720) /; 168 $newname =~ s/\[1280x720[^]]+\]/ (1280x720) /;
128 $newname =~ s/\([^)]*704x480[^)]*\)//; 169 $newname =~ s/\([^)]*704x480[^)]*\)//;
145 $newname =~ s/(\(\)|\[\])+//; 186 $newname =~ s/(\(\)|\[\])+//;
146 #$newname =~ s/\) +\[/) [BD][/; 187 #$newname =~ s/\) +\[/) [BD][/;
147 #$newname =~ s/SP/- Special /; 188 #$newname =~ s/SP/- Special /;
148 $newname =~ s/\[(Final|End)\]/[End]/i; 189 $newname =~ s/\[(Final|End)\]/[End]/i;
149 #$newname =~ s/Gurren Lagann Parallel Works - 2/Gurren Lagann Parallel Works 2/; 190 #$newname =~ s/Gurren Lagann Parallel Works - 2/Gurren Lagann Parallel Works 2/;
150 $newname =~ s/ - special - ([[:digit:]]+) / - Special $1 /i; 191 $newname =~ s/ - special - ([[:digit:]]+)( |\.)/ - Special $1$2/i;
151 $newname =~ s/ memories off - 3\.5 - / Memories Off 3.5 - /i; 192 $newname =~ s/ memories off - 3\.5 - / Memories Off 3.5 - /i;
152 $newname =~ s/ - Navigation - / - Navigation /; 193 $newname =~ s/ - Navigation - / - Navigation /;
153 $newname =~ s/ - Picture Drama - / - Picture Drama /; 194 $newname =~ s/ - Picture Drama - / - Picture Drama /;
154 $newname =~ s/\[W B\]/[W_B]/; 195 $newname =~ s/\[W B\]/[W_B]/;
196 $newname =~ s/ OP / - Opening /;
197 $newname =~ s/ ED / - Ending /;
155 $newname =~ s/ - (Ending|Opening) - 1 / - $1 /; 198 $newname =~ s/ - (Ending|Opening) - 1 / - $1 /;
199 $newname =~ s/ (Ending|Opening) - / - $1 /;
200 $newname =~ s/ Strike Witches - 2 - / Strike Witches 2 - /;
201 $newname =~ s/ Macross - 7 - / Macross 7 - /;
202 $newname =~ s/ Samurai - 7 - / Samurai 7 - /;
156 $newname =~ s/Seed Character Theater - /SEED - Character Theater /; 203 $newname =~ s/Seed Character Theater - /SEED - Character Theater /;
157 $newname =~ s/ - (Ending|Opening) - ([[:digit:]]+) / - $1 $2 /; 204 $newname =~ s/ - (Ending|Opening) - ([[:digit:]]+) / - $1 $2 /;
205 $newname =~ s/ Captain Tsubasa Road to - 2002 - / Captain Tsubasa Road to 2002 - /i;
206 $newname =~ s/ Golgo - 13 - / Golgo 13 - /i;
207 $newname =~ s/\]v3\./][v3]./;
208 $newname =~ s/^(.+)(\[v2\])(.+)$/$2 $1 $3/;
209 $newname =~ s/^(.+)(\[v3\])(.+)$/$2 $1 $3/;
210 $newname =~ s/(\[v2\]) (.+) (\[.+)/$2 ${1}$3/;
211 $newname =~ s/(\[v3\]) (.+) (\[.+)/$2 ${1}$3/;
212 $newname =~ s/\) \./)./;
213 $newname =~ s/\[+/[/g;
214 $newname =~ s/\]+/]/g;
215 $newname =~ s/( ?- )+/ - /g;
216 $newname =~ s/\[+ *\]+//g;
158 $newname =~ s/ +/ /g; 217 $newname =~ s/ +/ /g;
218 $newname =~ s/ VS Knight Lamune & - 40 fire / VS Knight Lamune & 40 fire /;
159 print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; 219 print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname;
160 if ($_ eq $newname) { 220 if ($_ eq $newname) {
161 print("$_: no need to rename, skipping\n"); 221 print("$_: no need to rename, skipping\n");
162 } else { 222 } else {
163 if($skip==1) { print("Result: $_ --> $newname\n"); } 223 if($skip==1) { print("Result: $_ --> $newname\n"); }