2 # torn - Musical files renaming with russian language transliteration
3 # Copyright (C) 2007-2020 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, version 3 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 This Perl script takes directory file list and renames all files,
22 making some substitution changes. It has some rules for musical
23 files and rules to convert russian filenames to translit.
27 Simply run this script in directory where you want files and/or
28 directorires to be renamed.
34 =item * Transliterate everything
36 =item * Replaces spaces with underscore
38 =item * Downcase all extensions
40 =item * "_-_" so good looking on the screen is replaced by single dash
42 =item * Remove spaces before and after brackets
44 =item * Remove "[]" brackets
46 =item * Replace ampersand with "and" word
52 Sergey Matveev L<mailto:stargrave@stargrave.org>
60 binmode STDOUT, ":utf8";
69 print "torn version $VERSION, Copyright (C) 2007-2020 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
72 Usage: just run inside the directory. Look for POD inside the script itself.\n";
75 opendir DIR, "." or die "Can not open directory\n";
76 foreach (sort readdir DIR) {
77 # Skip directory itself
82 $src = decode "utf-8", $src_filename;
85 # Basic corrections for music files
99 $dst =~ y/абвгдеёзийклмнопрстуфхцьъыэ/abvgdeezijklmnoprstufhcjjye/;
100 $dst =~ y/АБВГДЕЁЗИЙКЛМНОПРСТУФХЦЬЪЫЭ/ABVGDEEZIJKLMNOPRSTUFHCJJYE/;
114 # Lowercase file extensions
115 if($dst =~ /^(.*)\.([^\.]+)$/){
116 $dst = $1 . "." . lc $2;
119 # Change looking of track numbers
120 # And renaming itself
121 if($dst =~ /^(\d+)\-(.+)$/){
122 print "$src -> $1.$2\n";
123 rename $src_filename, "$1.$2";
125 print "$src -> $dst\n";
126 rename $src_filename, $dst;