commit:60b835ccf03be20cd9aa879882c43c58006f00f0
author:Chip Black
committer:Chip Black
date:Tue Jun 3 02:50:15 2008 -0500
parents:503a191766eb4d69d5fe695b3d2066d6ad380692
Finished processing functionality
diff --git a/upod.pl b/upod.pl
line changes: +27/-17
index 5987b2b..9707b23
--- a/upod.pl
+++ b/upod.pl
@@ -8,10 +8,20 @@ my $uthome = $ENV{HOME} . '/.utunes';
 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,
@@ -87,37 +97,37 @@ LIST: {
 	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";
 
@@ -128,7 +138,7 @@ LIST: {
 					# come across this and freak out.
 			goto LIST;
 		}
-		$c += -s "$dir/$outfile";
+		$c += -s $outfile;
 		$t += $length;
 	} continue {
 		$i++;