2 # torn - Musical files renaming with russian language transliteration
3 # Copyright (C) 2007-2016 Sergey Matveev (stargrave@stargrave.org)
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 This Perl script takes directory file list and renames all files,
23 making some substitution changes. It has some rules for musical
24 files and rules to convert russian filenames to translit.
28 Simply run this script in directory where you want files and/or
29 directorires to be renamed.
35 =item * Transliterate everything
37 =item * Replaces spaces with underscore
39 =item * Downcase all extensions
41 =item * "_-_" so good looking on the screen is replaced by single dash
43 =item * Remove spaces before and after brackets
45 =item * Remove "[]" brackets
47 =item * Replace ampersand with "and" word
53 Sergey Matveev L<mailto:stargrave@stargrave.org>
61 binmode STDOUT, ":utf8";
69 print "torn version $VERSION, Copyright (C) 2007-2016 Sergey Matveev
70 torn comes with ABSOLUTELY NO WARRANTY. This is free software,
71 and you are welcome to redistribute it under certain conditions.\n\n";
73 opendir DIR, "." or die "Can not open directory\n";
74 foreach (sort readdir DIR) {
75 # Skip directory itself
79 $src = decode "utf-8", $src_filename;
82 # Basic corrections for music files
96 $dst =~ y/абвгдеёзийклмнопрстуфхцьъыэ/abvgdeezijklmnoprstufhcjjye/;
97 $dst =~ y/АБВГДЕЁЗИЙКЛМНОПРСТУФХЦЬЪЫЭ/ABVGDEEZIJKLMNOPRSTUFHCJJYE/;
111 # Lowercase file extensions
112 if($dst =~ /^(.*)\.([^\.]+)$/){
113 $dst = $1 . "." . lc $2;
116 # Change looking of track numbers
117 # And renaming itself
118 if($dst =~ /^(\d+)\-(.+)$/){
119 print "$src -> $1.$2\n";
120 rename $src_filename, "$1.$2";
122 print "$src -> $dst\n";
123 rename $src_filename, $dst;