[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnupod] Add songs recursively
From: |
Benoît Knecht |
Subject: |
[Bug-gnupod] Add songs recursively |
Date: |
Fri, 14 Jan 2005 19:29:01 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041227 |
I wrote the following patch so that gnupod_addsong.pl recursively scans
directories supplied on the command line instead of ignoring them. I
needed it because I couldn't add more than 2000 files at the same time
by just giving each path (it told me "too many arguments").
--- gnupod_addsong-0.97.pl 2005-01-12 22:30:25.000000000 +0100
+++ gnupod_addsong-0.97-recursive.pl 2005-01-12 22:30:07.000000000 +0100
@@ -28,6 +28,7 @@
use GNUpod::FileMagic;
use Getopt::Long;
use File::Copy;
+use File::Find;
use constant MACTIME => 2082931200; #Mac EPOCH offset
use vars qw(%opts %dupdb_normal %dupdb_lazy $int_count);
@@ -98,19 +99,19 @@
my $addcount = 0;
#We are ready to copy each file..
- foreach my $file (@files) {
+ sub copy_file {
#Skip all songs if user sent INT
next if !$int_count;
#Skip all dirs
- next if -d $file;
+ next if -d $_;
#Get the filetype
- my ($fh,$media_h,$converter) = GNUpod::FileMagic::wtf_is($file,
{noIDv1=>$opts{'disable-v1'},
+ my ($fh,$media_h,$converter) = GNUpod::FileMagic::wtf_is($_,
{noIDv1=>$opts{'disable-v1'},
noIDv2=>$opts{'disable-v2'},
decode=>$opts{'decode'}},$con);
unless($fh) {
- warn "* [****] Skipping '$file', unknown file type\n";
+ warn "* [****] Skipping '$_', unknown file type\n";
next;
}
@@ -132,7 +133,7 @@
#Check for duplicates
if(!$opts{duplicate} && (my $dup = checkdup($fh,$converter))) {
- print "! [!!!] '$file' is a duplicate of song $dup, skipping file\n";
+ print "! [!!!] '$_' is a duplicate of song $dup, skipping file\n";
create_playlist_now($opts{playlist}, $dup); #We also add duplicates
to a playlist..
next;
}
@@ -141,10 +142,10 @@
if($converter) {
- print "> Converting '$file' from $wtf_ftyp into $opts{decode},
please wait...\n";
- my $path_of_converted_file =
GNUpod::FileMagic::kick_convert($converter,$file, uc($opts{decode}), $con);
+ print "> Converting '$_' from $wtf_ftyp into $opts{decode}, please
wait...\n";
+ my $path_of_converted_file =
GNUpod::FileMagic::kick_convert($converter,$_, uc($opts{decode}), $con);
unless($path_of_converted_file) {
- print "! [!!!] Could not convert $file\n";
+ print "! [!!!] Could not convert $_\n";
next;
}
@@ -166,19 +167,19 @@
$wtf_ext = $conv_media_h->{extension}; #Set the new possible extension
#BUT KEEP ftyp! (= codec)
- $file = $path_of_converted_file; #Point $file to new file
+ $_ = $path_of_converted_file; #Point $_ to new file
}
#Get a path
- (${$fh}{path}, my $target) =
GNUpod::XMLhelper::getpath($opts{mount}, $file,
+ (${$fh}{path}, my $target) =
GNUpod::XMLhelper::getpath($opts{mount}, $_,
{format=>$wtf_frmt, extension=>$wtf_ext, keepfile=>$opts{restore}});
if(!defined($target)) {
- warn "*** FATAL *** Skipping '$file' , no target found!\n";
+ warn "*** FATAL *** Skipping '$_' , no target found!\n";
}
- elsif($opts{restore} || File::Copy::copy($file, $target)) {
+ elsif($opts{restore} || File::Copy::copy($_, $target)) {
printf("+ [%-4s][%3d] %-32s | %-32s | %-24s\n",
uc($wtf_ftyp),1+$addcount, $fh->{title},
$fh->{album},$fh->{artist});
@@ -187,11 +188,11 @@
$addcount++; #Inc. addcount
}
else { #We failed..
- warn "*** FATAL *** Could not copy '$file' to '$target': $!\n";
+ warn "*** FATAL *** Could not copy '$_' to '$target': $!\n";
}
- unlink($file) if $converter; #File is in $tmp if $converter is set...
+ unlink($_) if $converter; #File is in $tmp if $converter is set...
}
-
+ find(\©_file, @files);
if($opts{playlist} || $addcount) { #We have to modify the xmldoc
- [Bug-gnupod] Add songs recursively,
Benoît Knecht <=