我正在尝试使用在这里找到的用 Perl 编写的脚本,但它遇到了错误。我已经联系了作者,但还没有回复。我希望你能帮助我。
错误如下:
错误:无法将 /home/bruno321/.config/Clementine/albumcovers/271b13967f57caba893b366730337fb03439c60a.jpg 复制到 /media/mp3_1/Musica/Amarok/Two%20Lone%20Swordsmen/A%20Bag%20of%20Blue%20Sparks/。错误:文件或目录不存在
我相信错误在于处理空格,因为在没有空格的目录中它运行正常,但是它不会将文件重命名为“cover.jpg”,因为我相信脚本打算这样做(我当然需要它这样做)。
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use DBI;
use strict;
use Data::Dumper;
use File::Basename;
use File::Copy;
my $db_filename = shift(@ARGV);
$db_filename
|| croak
"missing mandatory param: sqlite filename\n(try ~/.config/Clementine/clementine.db\n";
if ( !-f $db_filename ) {
croak "no such database file: $db_filename\n";
}
my $force_rewrite = shift(@ARGV) || 0;
my $dbh =
DBI->connect( "dbi:SQLite:$db_filename", q{}, q{},
{ 'RaiseError' => 1, 'AutoCommit' => 1 } );
my $query = q{SELECT artist,album, art_automatic,art_manual,filename
FROM songs WHERE art_manual IS NOT NULL GROUP BY(album) ORDER BY artist};
my $sth = $dbh->prepare($query);
$sth || croak 'prepare error: ' . $dbh->errstr . "\n";
$sth->execute || croak 'execute error: ' . $dbh->errstr . "\n";
my %treated = ();
while ( my $res = $sth->fetchrow_hashref ) {
( undef, my $dest_dir, undef ) = fileparse( $res->{'filename'} );
next if $treated{$dest_dir};
$treated{$dest_dir}++;
# strip leading file:// -> should do this better
$dest_dir =~ s/^file:\/\///g;
my $dest_file = $dest_dir . 'cover.jpg';
# unless we are given overwrite option, skip dirs that have covers
if ( !$force_rewrite ) {
next if ( -f $dest_file );
}
#print "CMD: cp $res->{'art_manual'} $dest_file\n";
copy( $res->{'art_manual'}, $dest_dir )
|| printf( "ERROR: unable to copy %s to %s. error: %s\n",
$res->{'art_manual'}, $dest_dir, $! );
}
exit;