X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=torn;h=b85b2697e33a5904abfe3d1cf5c52163c5b84a14;hb=eedef62e6154269b454c0a62012692ffdbc126ab;hp=fe709b97ca8238cbfd0e37103b719b6ad14cc50b;hpb=7c0a9d47891433439f12078a3dc3e7c8ce9f29d4;p=torn.git diff --git a/torn b/torn index fe709b9..b85b269 100755 --- a/torn +++ b/torn @@ -1,17 +1,16 @@ #!/usr/bin/env perl # torn - Musical files renaming with russian language transliteration -# Copyright (C) 2007-2018 Sergey Matveev (stargrave@stargrave.org) +# Copyright (C) 2007-2021 Sergey Matveev (stargrave@stargrave.org) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. +# the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . @@ -60,20 +59,24 @@ use Encode; binmode STDOUT, ":utf8"; -my $VERSION = "0.9"; +my $VERSION = "0.10"; my $src; my $dst; my $src_filename; -print "torn version $VERSION, Copyright (C) 2007-2016 Sergey Matveev +if ($#ARGV >= 0) { + print "torn version $VERSION, Copyright (C) 2007-2020 Sergey Matveev torn comes with ABSOLUTELY NO WARRANTY. This is free software, -and you are welcome to redistribute it under certain conditions.\n\n"; +and you are welcome to redistribute it under certain conditions.\n +Usage: just run inside the directory. Look for POD inside the script itself.\n"; +}; opendir DIR, "." or die "Can not open directory\n"; foreach (sort readdir DIR) { # Skip directory itself next if /^\.{1,2}$/; + next if -d; $src_filename = $_; $src = decode "utf-8", $src_filename; @@ -109,18 +112,18 @@ foreach (sort readdir DIR) { $dst =~ s/Ю/Ju/g; # Lowercase file extensions - if($dst =~ /^(.*)\.([^\.]+)$/){ + if ($dst =~ /^(.*)\.([^\.]+)$/) { $dst = $1 . "." . lc $2; }; # Change looking of track numbers - # And renaming itself - if($dst =~ /^(\d+)\-(.+)$/){ - print "$src -> $1.$2\n"; - rename $src_filename, "$1.$2"; - } else { - print "$src -> $dst\n"; - rename $src_filename, $dst; + if ($dst =~ /^(\d+)[-.]_*(.+)$/) { + $dst = "$1.$2"; }; + + next if ($src_filename eq $dst); + print "$src -> $dst\n"; + die "\"$dst\" exists" if -e $dst; + rename $src_filename, $dst; }; closedir DIR;