Finished processing functionality
my $outdir = $ENV{HOME} . "/dspod";
my $name = "playlist";
my ($size, $time);
+
+# The proc subroutine stands in for the standard symlink operation if it is
+# defined. Because the conversion might mangle the filename, the subroutine
+# should return the actual output filename. In this example, I'm using conv
+# (http://bytex64.net/code/conv/), but you can use anything you'd like.
my $proc;
-#$proc = sub {
-# my ($in, $out) = @_;
-#};
+$proc = sub {
+ my ($in, $out) = @_;
+ $in =~ s/"/\\"/g;
+ $out =~ s/\.\w+$/.ogg/;
+ $out =~ s/"/\\"/g;
+ system(qq!conv -f ~/dspod/Convfile -o "$out" "$in"!);
+ return $out;
+};
GetOptions(
"outdir=s" => \$outdir,
while (@files) {
my $file = shift @files;
my $length = songlength($file);
- #print "$file\n$length\t$time\n";
next if $time && $length > $time;
- my $outfile = sprintf("%04d_", $i) . basename $file;
+ my $outfile = $dir . '/' . sprintf("%04d_", $i) . basename $file;
print PLAYLIST "$outfile\n";
- die "$dir/$outfile already exists!" if -e "$dir/$outfile";
+ die "$outfile already exists!" if -e $outfile;
if ($proc) {
if ($residual) {
- move $residual, "$dir/$outfile";
+ move $residual, $outfile;
+ undef $residual;
} else {
# Process the file somehow
- &$proc($file, "$dir/$outfile");
+ $outfile = &$proc($file, $outfile);
}
} else {
- symlink $file, "$dir/$outfile"
- or copy $file, "$dir/$outfile"
- or die "Could not symlink or copy $file to $dir/$outfile";
+ symlink $file, $outfile
+ or copy $file, $outfile
+ or die "Could not symlink or copy $file to $outfile";
}
- if ($size && -s "$dir/$outfile" > $size) {
- unlink "$dir/$outfile";
+ if ($size && -s $outfile > $size) {
+ unlink $outfile;
next;
}
# The size of a file will change if it is processed, but
# (unless something screwy is going on) the length will not.
- if ($size && $c + -s "$dir/$outfile" > $size ||
- $time && $t + $length > $time) {
+ if (($size && $c + -s $outfile > $size) ||
+ ($time && $t + $length > $time)) {
$n++;
unshift @files, $file;
if ($proc) {
- $residual = "$dir/$outfile";
+ $residual = $outfile;
}
print PLAYLIST "# $c bytes, $t seconds\n";
# come across this and freak out.
goto LIST;
}
- $c += -s "$dir/$outfile";
+ $c += -s $outfile;
$t += $length;
} continue {
$i++;