2 # torn - Musical files renaming with russian language transliteration
3 # Copyright (C) 2007-2021 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.
25 This version is unsupported! Use Z shell-based implementation instead.
29 Simply run this script in directory where you want files and/or
30 directories to be renamed. Directories are not transliterated by
31 default, but you can use FORCE_DIR=1 environment variable.
37 =item * Transliterate everything
39 =item * Replaces spaces with underscore
41 =item * Downcase all extensions
43 =item * "_-_" so good looking on the screen is replaced by single dash
45 =item * Remove spaces before and after brackets
47 =item * Remove "[]" brackets
49 =item * Replace ampersand with "and" word
55 Sergey Matveev L<mailto:stargrave@stargrave.org>
63 binmode STDOUT, ":utf8";
72 print "torn version $VERSION, Copyright (C) 2007-2023 Sergey Matveev
73 torn comes with ABSOLUTELY NO WARRANTY. This is free software,
74 and you are welcome to redistribute it under certain conditions.\n
75 Usage: just run inside the directory. Look for POD inside the script itself.\n";
78 opendir DIR, "." or die "Can not open directory\n";
79 foreach (sort readdir DIR) {
80 # Skip directory itself
82 next if -d and not $ENV{FORCE_DIR};
85 $src = decode "utf-8", $src_filename;
88 # Basic corrections for music files
102 $dst =~ y/абвгдеёзийклмнопрстуфхцьъыэ/abvgdeezijklmnoprstufhcjjye/;
103 $dst =~ y/АБВГДЕЁЗИЙКЛМНОПРСТУФХЦЬЪЫЭ/ABVGDEEZIJKLMNOPRSTUFHCJJYE/;
117 # Lowercase file extensions
118 if ($dst =~ /^(.*)\.([^\.]+)$/) {
119 $dst = $1 . "." . lc $2;
122 # Change looking of track numbers
123 if ($dst =~ /^(\d+)[-.]_*(.+)$/) {
127 next if ($src_filename eq $dst);
128 print "$src -> $dst\n";
129 die "\"$dst\" exists" if -e $dst;
130 rename $src_filename, $dst;