#!/usr/bin/env perl # ASCIIfy all filenames on command line # # Copyright (c) 2006..2013 Dirk Jagdmann # # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you # must not claim that you wrote the original software. If you use # this software in a product, an acknowledgment in the product # documentation would be appreciated but is not required. # # 2. Altered source versions must be plainly marked as such, and # must not be misrepresented as being the original software. # # 3. This notice may not be removed or altered from any source # distribution. use strict; foreach(@ARGV) { my $o=$_; s/\%20|_20/_/g; # Converts netscape screwup to a _ s/\s+/ /g; # remove multiple whitespaces s/\s/_/g; # Converts space to a _ s/\(|\[|\{/-/g; # Removes (,[,{ and subs - s/\)|\]|\}//g; # Removes ),],} s/\#|\!|\~//g; # Removes #,!,~ s/\&/And/g; # replaces & with "And" s/\'|\'|\`//g; # Hickey remover s/-_/-/g; # Clean up -_ to - s/_-/-/g; # Clean up _- to - s/_-_/-/g; # Shorten _-_ to - s/-+/-/g; # Shorten 2 or more -- to 1 - s/_+/_/g; # Shorten 2 or more __ to 1 _ s/\,/-/g; # Set up for format artist1+artist2 s/_\+_/\+/g; # Shorten _+_ to + s/-\./\./g; # Remove extra -'s infront of .mp3 s/\.-/\./g; # Remove extra -'s behind a dot s!^./!!; # Remove ./ at start s/^-|^_|^\.//g; # Remove - , _ , . at beginning of filename while(s/(.+?)\.(.+?)(\..+)/\1\u\2\3/) { } # Remove . in the middle s/\.\./\./g; # Remove multiple dots # Latin1 s//ae/g; s//oe/g; s//ue/g; s//Ae/g; s//Oe/g; s//Ue/g; s//ss/g; # Windows umlaute s//ae/g; s//oe/g; s//ue/g; s//Ae/g; s//Oe/g; s//Ue/g; s//ss/g; # hypenathe the leading number if(/^\d+/) { s/^(\d+)-?/$1-/; } s/_(\w)/\u\1/g; # remove _ s/_\.(.+?)$/\.\1/; # remove trailing _ s/-(\w)/-\u\1/g; # uppercase before - s/\.(.+?)$/\.\L$1/; # lowercase extension next if /^\s*$/; # skip if we optimized everything away if (-f $_) { print STDERR "not renaming $o to $_: target name already exists\n"; next; } if($_ ne $o) { rename $o, $_ or die "could not rename $o to $_: $!"; } }