view bin/ren @ 8:b5d0c1892294

Forgot to add remover for inputrc
author Edho Prima Arief <me@myconan.net>
date Mon, 19 Jul 2010 16:49:38 +0700
parents 94ee419ad047
children 8a0391d8e8d0
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/Sakura\.Wars\.([[:digit:]]{2}).*/[AM] Sakura Wars - $1.mkv/;
  #$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/.*_-_([[:digit:]]{2})\[47\].*(\[[[:xdigit:]]{8}\]\.mkv)$/[AniMecha] - $1 [DVD]$2/i;
  #$newname =~ s/.*\.([[:digit:]]{2})\.\[.*([[:xdigit:]]{8}\]\.mkv)$/[Arigatou] Blade of the Immortal - $1 [$2/i;
  #$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/^\[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 - 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\]\.mkv$/.mkv/;
  $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/ ARIA The ORIGINATION / Aria the Origination /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\) \[/(1280x720) [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/\.AAC\]//;
  $newname =~ s/ No / no /g;
  #$newname =~ s/ 0([[:digit:]]) / $1 /;
  $newname =~ s/\[1280x720\]/(1280x720) /;
  #$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 /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/ - (Ending|Opening) - 1 / - $1 /;
  $newname =~ s/Seed Character Theater - /SEED - Character Theater /;
  $newname =~ s/ - (Ending|Opening) - ([[:digit:]]+) / - $1 $2 /;
	$newname =~ s/ +/ /g;
	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);