view bin/ren @ 33:330587be514c

Better vim support.
author Edho Prima Arief <me@myconan.net>
date Sun, 27 Mar 2011 11:32:08 +0000
parents b975a587f8f6
children 3bcef95c376c
line wrap: on
line source

#!/usr/bin/env perl

use warnings;
use strict;
use File::Basename;

my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1);
my $skip=0;
foreach (@files) {
	my $newname = $_;
	print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_;
  $newname =~ s/ \'[^']+\'//;
  #$newname =~ s/ Kiss x Sis OVA / Kiss x Sis OAD /;
  $newname =~ s/x264//;
  #$newname =~ s/ - 0/ - /;
  $newname =~ s/\[HorribleSubs\] Lilpri /[HorribleSubs] Hime Chen! Otogi Chikku Idol Lilpri - /i;
  $newname =~ s/\[HorribleSubs\] Uraboku /[HorribleSubs] Uragiri wa Boku no Namae wo Shitteiru - /i;
  $newname =~ s/ GIG E/ GIG - /;
  $newname =~ s/^Kidou_Keisatsu_Patlabor_\(1990\)_-_([[:digit:]]+)\[16\]_-_.+_\[640x480\]\[DVD\]\[A-Et\]\[([[:xdigit:]]{8})\]\.(mkv)$/[A-Et] Patlabor (1990) - $1 [DVD][${2}].$3/;
  $newname =~ s/^Witchblade_-_([[:digit:]]+)\[24\]_-_.+\[(Makoto|AniSubs)\]\[([[:xdigit:]]{8})\]\.(mkv)$/[$2] Witchblade - $1 [DVD][${3}].$4/;
  $newname =~ s/^Witchblade - ([[:digit:]]+) \[24\] - .+\[(Makoto|AniSubs)\]\[([[:xdigit:]]{8})\]\[v2\]\.(mkv)$/[$2] Witchblade - $1 [DVD][v2][${3}].$4/;
  $newname =~ s/Sakura\.Wars\.([[:digit:]]{2}).*/[AM] Sakura Wars - $1.mkv/;
  $newname =~ s/^Black Lagoon Omake /[OCZ] Black Lagoon - Special /;
  $newname =~ s/_AIR_/ Air /;
  $newname =~ s/\(b-a\)/[B-A] /i;
  #$newname =~ s/ ([[:digit:]]{2}) / 0$1 /;
  #$newname =~ s/^Feather #([[:digit:]]{2}) .*(\.mkv)$/[DmonHiro] Sekirei - $1$2/;
  #$newname =~ s/(Galaxy Angel)/$1 S3 - /;
  #$newname =~ s/Legend Of The Crystals OAV - 0/- Legend of the Crystals OVA - /;
  #$newname =~ s/^Kaleido_Star_-_([[:digit:]]{2}).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - $1 [DVD]$2/i;
  #$newname =~ s/^Kaleido_Star_-_Clean_ED([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Ending $1 (Clean) [DVD]$2/i;
  #$newname =~ s/^Kaleido_Star_-_Clean_OP([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Opening $1 (Clean) [DVD]$2/i;
  #$newname =~ s/^Kidou Keisatsu Patlabor \(1989\) - ([[:digit:]]{2}) \[47\].*(\[[[:xdigit:]]{8}\])v2(\.[^.]+)$/[AM] Patlabor (1989) - $1 [DVD][v2] $2$3/i;
  #$newname =~ s/.*_-_([[:digit:]]{2})\[26\].*(\[[[:xdigit:]]{8}\]\.avi)$/[Triad] Akagi - $1 $2/i;
  #$newname =~ s/^.*\.([[:digit:]]{2})\..*\.mkv$/[AM] Neo Ranga - $1.mkv/;
  #$newname =~ s/.* ([[:digit:]]+) .*/[AonE-AnY] Ah My Goddess - $1.avi/;
  #$newname =~ s/\[24-\(Final\)\]_/24 [End]/;
  #$newname =~ s/\[([[:digit:]]{2})\]/$1/;
  #$newname =~ s/^Otaku no Musume-san c([[:digit:]]+) \[v03\](\[.+\])\.zip$/Otaku no Musume-san - $1 (v03) $2.zip/i;
  #$newname =~ s/ HQ //;
  $newname =~ s/xvid//i;
  $newname =~ s/\(-mp3\)//;
  $newname =~ s/^\[Doremi\]\.HeartCatch\.PreCure!\.([[:digit:]]{2})\.\[1280x720\]\.\[([[:xdigit:]]{8})\]\.mkv$/[Doremi] HeartCatch PreCure! - $1 (1280x720) [$2].mkv/;
  $newname =~ s/^\[Doremi\]\.Motto\.Ojamajo\.Doremi\.([[:digit:]]{2})\.\[([[:xdigit:]]{8})\]\.avi$/[Doremi] Motto Ojamajo Doremi - $1 [$2].avi/;
  $newname =~ s/^(Detective Conan - [[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/;
  $newname =~ s/^(Detective Conan - [[:digit:]]+-?[[:digit:]]*) (\[Kienai[^]]*\])(.+)$/$2 $1 $3/;
  $newname =~ s/^(Detective Conan - OVA[[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/;
  $newname =~ s/^(Kamen Rider W - [[:digit:]]+)HD (\[W-Time\])(.+)$/$2 $1 $3/;
  $newname =~ s/- TV -/-/;
  $newname =~ s/^(\[Keroro\])\.([[:digit:]]+)\..*(\[[[:xdigit:]]{8}\].+)$/$1 Keroro Gunsou - $2 $3/;
  $newname =~ s/SubDESU(.*)_-_Directors_Cut/SubDesu$1/;
  $newname =~ s/\[(480p|360p)\]//;
  $newname =~ s/^(\[EG\])ZZ_Gundam_BD_([[:digit:]]+)\(720p\)(.+)$/$1 Gundam ZZ - $2 (960x720) [BD]$3/;
  $newname =~ s/\]_Working_-/] Working!! -/;
  $newname =~ s/WORKING!!/Working!!/;
  $newname =~ s/\[Retrofit\]_\[Ayako-m\.3\.3\.w\.\]/[Retrofit-Ayako-m.3.3.w]/i;
  $newname =~ s/Rosario\+Vampire/Rosario + Vampire/i;
  $newname =~ s/Rosario \+ Vampire - Capu2 - /Rosario + Vampire Capu 2 - /i;
  $newname =~ s/ Hidamari Sketch Hoshimittsu / Hidamari Sketch - Hoshi Mittsu /i;
  $newname =~ s/ HEROMAN / Heroman /i;
  #$newname =~ s/^/[ETB]/i;
  $newname =~ s/_/ /g;
  $newname =~ s/ asobi ni ikuyo / Asobi ni Iku Yo! /i;
  $newname =~ s/ Eve no Jikan / Time of Eve /i;
  $newname =~ s/ DVD +\[/ [DVD][/i;
  $newname =~ s/^(.+)\[(Z-Z)\](.+)$/[$2] $1 $3/;
  $newname =~ s/\[62\] - .*\[DVD\]/[DVD]/;
  $newname =~ s/S0/Special /;
  $newname =~ s/\(1080p\)/(1920x1080)/;
  $newname =~ s/ Seikimatsu Occult Gakuin / Occult Academy /;
  $newname =~ s/ rockman exe axess / Rockman.EXE Axess /i;
  $newname =~ s/\[& MP3\]//;
  $newname =~ s/\[AAC\]//;
  $newname =~ s/ DVD \[/[DVD][/i;
  $newname =~ s/\[720 \(853\)x480\]\[x264 & HE-AAC\]//;
  $newname =~ s/ Ep - ([[:digit:]]+) / - $1 /;
  $newname =~ s/ Asobi ni Ikuyo! / Asobi ni Iku Yo! /i;
  $newname =~ s/ \(Directors Cut\) / /;
  $newname =~ s/ KimiKiss Pure Rouge / kimikiss pure rouge /i;
  $newname =~ s/ HIGHSCHOOL OF THE DEAD / High School of the Dead /i;
  $newname =~ s/ ARIA The ORIGINATION / Aria the Origination /i;
  $newname =~ s/ Shinseiki Evangelion / Evangelion /;
  $newname =~ s/ Kuro no Keiyakusha / The Black Contractor /i;
  $newname =~ s/ Darker than Black / Darker than Black /i;
  $newname =~ s/ ARIA The NATURAL / Aria the Natural /i;
  $newname =~ s/^Clannad Ep([[:digit:]]+) \[1080p,BluRay,x264\] - THORA\.mkv$/[THORA] Clannad - $1 (1920x1080) [BD].mkv/i;
  $newname =~ s/ Mahou Kishi Rayearth / Magic Knight Rayearth /i;
  $newname =~ s/rune soldier ep/ Rune Soldier /i;
  $newname =~ s/ Harukanaru Toki no Naka de Hachiyoushou / Haruka Naru Toki no Naka de - Hachiyoushou /i;
  $newname =~ s/ Harukanaru Toki no Naka de - / Haruka Naru Toki no Naka de - Hachiyoushou /i;
  $newname =~ s/ -Hachiyoushou - / - Hachiyoushou - /i;
  $newname =~ s/\[Retrofit\] \[Shinsen\] /[Retrofit-SHS] /i;
  $newname =~ s/ You're Under Arrest - / You're Under Arrest! - /i;
  $newname =~ s/ Rosario to Vampire / Rosario + Vampire /i;
  $newname =~ s/\[R2 Video\]//i;
  $newname =~ s/ \(BD-720p\) \[/ (1280x720) [BD][/i;
  $newname =~ s/ TV Ep/ - /i;
  $newname =~ s/\] AIR - /] Air - /i;
  $newname =~ s/ - Episode / - /i;
  $newname =~ s/\[divx[[:digit:].]+\]//i;
  $newname =~ s/\[BD\] \((1280x720|1920x1080)\) \[/($1) [BD][/i;
  $newname =~ s/ Seiken no Blacksmith / The Sacred Blacksmith /i;
  #$newname =~ s/^Rizelmine([[:digit:]]+)\.avi$/[AC] Rizelmine - $1.avi/i;
  #$newname =~ s/\[v2\]/v2/i;
  $newname =~ s/v2/[v2]/i;
  $newname =~ s/\.AAC\]//;
  $newname =~ s/ No / no /g;
  #$newname =~ s/ 0([[:digit:]]) / $1 /;
  $newname =~ s/\[(1280x720|1024x576)\]/($1) /;
  #$newname =~ s/^.*( [[:digit:]]{2}v2).*(\[[[:xdigit:]]{8}\]\.mkv)$/[KAA] Ai Yori Aoshi - $1 [DVD]$2/;
  $newname =~ s/ True Tears / true tears /i;
  $newname =~ s/ Fate stay night TV Reproduction / Fate-stay night - TV Reproduction /i;
  $newname =~ s/ The Tatami Galaxy \(Yojouhan Shinwa Taikei\) / The Tatami Galaxy /i;
  $newname =~ s/ Saint Seiya The Lost Canvas / Saint Seiya - The Lost Canvas /i;
  $newname =~ s/Mayoi Neko Overrun /Mayoi Neko Overrun! /;
  $newname =~ s/Angel Beats /Angel Beats! /i;
  $newname =~ s/Rainbow /Rainbow /i;
  $newname =~ s/ Ookiku Furikabutte - The Summer Tournament Chapter / Ookiku Furikabutte S2 /i;
  $newname =~ s/Senko no night raid /Senkou no Night Raid /i;
  $newname =~ s/To Heart Mini Ep0/To Heart - Special /;
  $newname =~ s/Mai Otome/Mai-Otome/i;
  $newname =~ s/WORKING!!/Working!!/i;
  $newname =~ s/ Sengoku Basara / Sengoku Basara /i;
  $newname =~ s/ K-on!! S2 / K-ON!! /i;
  #$newname =~ s/.*\[([[:digit:]]{2})\].*(\[[[:xdigit:]]{8}\]\.mkv)/[FuktLogik] Hidamari Sketch - $1 [DVD]$2/;
  $newname =~ s/\(BD\) \[/ [BD][/i;
  $newname =~ s/\[\[BD\]/[BD][/;
  $newname =~ s/\(DVD \)/[DVD]/;
  $newname =~ s/ AC3\]/ /;
  $newname =~ s/ *(\.[[:alnum:]]+)[^[:alnum:]]*$/$1/;
  $newname =~ s/\[webrip\]/[Webrip]/i;
  $newname =~ s/\[[^]]*(640x360|[[:digit:]]{3}x480)[^]]*\]//;
  $newname =~ s/([^]])\[/$1 [/;
  #$newname =~ s/- .*x264 AAC\)//;
  #$newname =~ s/ 0([[:digit:]]) / $1 /;
  #$newname =~ s/ - Great Guardians OVA - / Great Guardians - Special - /;
  #$newname =~ s/ ([\d]) / 0$1 /;
	#$newname =~ s/.* ([\d]{2}) .*/[HL] Gundam ZZ - $1.mkv/;
  #$newname =~ s/ \[[[:xdigit:]]{8}\]//;
  $newname =~ s/^\(([^)]+)\)/[$1]/;
  $newname =~ s/sonic x/Sonic X/i;
  $newname =~ s/END/End/;
  #$newname =~ s/\[[^]]*h\.?264[^]]*\]//;
  $newname =~ s/h\.?264//i;
  $newname =~ s/ op([\d]) / Opening $1 /i;
  $newname =~ s/ ed([\d]) / Ending $1 /i;
  $newname =~ s/ dragonball / Dragon Ball /i;
  $newname =~ s/Kissxsis/ Kiss x Sis /i;
  $newname =~ s/k-on/K-ON/i;
  #$newname =~ s/ dvd (\(.*\) )?\[/ $1 [DVD][/i;
  $newname =~ s/ ([\d]+)( |\.)/ - $1$2/;
  $newname =~ s/\(([[:xdigit:]]{8})\)/[$1]/;
  $newname =~ s/ ep([\d]+) / - $1 /i;
  $newname =~ s/- \[/ [/;
  $newname =~ s/&/ & /g;
  $newname =~ s/ ([\d]{2})\[/ $1 [/;
	$newname =~ s/(\[[0-9a-fA-F]{8})/\U$1/;
	$newname =~ s/v([[:digit:].]+)([^\[]+)\[/${2}[v${1}][/i;
  #$newname =~ s/v2 (?=\(.*\) ) \[/ $1 [v2][/;
	$newname =~ s/([^ ])\[DVD\]\[x264\.AAC\]/$1 [DVD]/;
  $newname =~ s/\(DVD\) +\[/[DVD][/;
  $newname =~ s/^(\[[^]]+\])([^ ])/$1 $2/;
	$newname =~ s/(\((1280x720|960x720)[^)]*\))/($2)/;
	#$newname =~ s/(\((1920x1080)[^)]*\)) /($2) [BD]/;
	$newname =~ s/\[[^]]*720p[^]]*\] ?/(1280x720) /;
	$newname =~ s/\[[^]]*1080p[^]]*\] ?/(1920x1080) /;
  $newname =~ s/\(720p\)/(1280x720)/;
  $newname =~ s/\[1280x720[^]]+\]/ (1280x720) /;
  $newname =~ s/\([^)]*704x480[^)]*\)//;
  $newname =~ s/([^ ])\(/$1 (/;
  $newname =~ s/\.avi\.avi/.avi/;
  $newname =~ s/^\[([^]&\-]*) +& +([^]&\-]*)\]/[$1-$2]/;
  $newname =~ s/\(704x396 x264 AAC\)//;
  $newname =~ s/\] +\[/][/;
  $newname =~ s/~([^~]+)~/- $1 /;
  $newname =~ s/\[DVD[^]]+\]/[DVD]/;
  $newname =~ s/(\[BD\])+/[BD]/;
  #$newname =~ s/Ep //;
  $newname =~ s/([[:digit:]])v([[:digit:]]) \[/$1 [v$2][/;
	$newname =~ s/([^-]) ([0-9]{2,3}) /$1 - $2 /;
  $newname =~ s/- *\[/ [/;
	$newname =~ s/( ?- )+/ - /g;
  #$newname =~ s/ Special - / Special /;
  $newname =~ s/ (\)|\])/$1/;
  $newname =~ s/(\(|\[) /$1/;
  $newname =~ s/(\(\)|\[\])+//;
  #$newname =~ s/\) +\[/) [BD][/;
  #$newname =~ s/SP/- Special /;
  $newname =~ s/\[(Final|End)\]/[End]/i;
  #$newname =~ s/Gurren Lagann Parallel Works - 2/Gurren Lagann Parallel Works 2/;
  $newname =~ s/ - special - ([[:digit:]]+)( |\.)/ - Special $1$2/i;
  $newname =~ s/ memories off - 3\.5 - / Memories Off 3.5 - /i;
  $newname =~ s/ - Navigation - / - Navigation /;
  $newname =~ s/ - Picture Drama - / - Picture Drama /;
  $newname =~ s/\[W B\]/[W_B]/;
  $newname =~ s/ OP / - Opening /;
  $newname =~ s/ ED / - Ending /;
  $newname =~ s/ - (Ending|Opening) - 1 / - $1 /;
  $newname =~ s/ (Ending|Opening) - / - $1 /;
  $newname =~ s/ Strike Witches - 2 - / Strike Witches 2 - /;
  $newname =~ s/ Macross - 7 - / Macross 7 - /;
  $newname =~ s/ Samurai - 7 - / Samurai 7 - /;
  $newname =~ s/Seed Character Theater - /SEED - Character Theater /;
  $newname =~ s/ - (Ending|Opening) - ([[:digit:]]+) / - $1 $2 /;
  $newname =~ s/ Captain Tsubasa Road to - 2002 - / Captain Tsubasa Road to 2002 - /i;
  $newname =~ s/ Golgo - 13 - / Golgo 13 - /i;
  $newname =~ s/\]v3\./][v3]./;
  $newname =~ s/^(.+)(\[v2\])(.+)$/$2 $1 $3/;
  $newname =~ s/^(.+)(\[v3\])(.+)$/$2 $1 $3/;
  $newname =~ s/(\[v2\]) (.+) (\[.+)/$2 ${1}$3/;
  $newname =~ s/(\[v3\]) (.+) (\[.+)/$2 ${1}$3/;
  $newname =~ s/\) \./)./;
  $newname =~ s/\[+/[/g;
  $newname =~ s/\]+/]/g;
	$newname =~ s/( ?- )+/ - /g;
  $newname =~ s/\[+ *\]+//g;
	$newname =~ s/ +/ /g;
  $newname =~ s/ VS Knight Lamune & - 40 fire / VS Knight Lamune & 40 fire /;
	print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname;
	if ($_ eq $newname) {
		print("$_: no need to rename, skipping\n");
	} else {
		if($skip==1) { print("Result: $_ --> $newname\n"); }
		else {
			if(rename($_, $newname)) { print("$_ -> $newname\n"); }
			else { print("$_: rename failed\n"); }
		}
	}
	next();
}

exit(0);