From d7b25a12a2f0d87f312e07722a40229eecc47d7f Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Thu, 25 Mar 2010 15:16:37 -0400 Subject: [PATCH] Added a script that copies files to a DAP, converting flac files to ogg to save space --- conv2ogg | 2 +- copy_to_dap | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100755 copy_to_dap diff --git a/conv2ogg b/conv2ogg index a874868..692da2e 100755 --- a/conv2ogg +++ b/conv2ogg @@ -26,7 +26,7 @@ # 0.0.1: Initial bash script $VERSION = "0.2.4"; -$HELP_MSG = "# MP3 - Ogg Converter v$VERSION\n\tusage: mp32ogg "; +$HELP_MSG = "# Audio file - Ogg Converter v$VERSION\n\tusage: conv2ogg "; $DEC_ERROR = "Couldn't find a decoder to use. Please install one of mplayer, mpg321, or mpg123"; $ENC_ERROR = "Couldn't find oggenc, which is necessary for encoding. Please install the package that provides oggenc (probably named 'oggenc' or 'vorbistools')"; diff --git a/copy_to_dap b/copy_to_dap new file mode 100755 index 0000000..9e964c6 --- /dev/null +++ b/copy_to_dap @@ -0,0 +1,70 @@ +#!/usr/bin/perl +# +# Expects a list of directories that contain ogg|flac +# Directories should be of the form: artist/album +# (i.e., not full paths or relative paths other than this) +# +# Changelog: +# 0.2.4: Initial release + +$VERSION = "0.2.4"; +$HELP_MSG = "# Copy files to DAP, converting flac to ogg v$VERSION\n\tusage: copy_top_dap artist1/album1 artist2/album2 ..."; + + +use File::Path qw(make_path remove_tree); + +my $dest='/mnt/dap/MUSIC'; +my $tmpdir='/tmp/copy_to_dap'; + + + +# Do we need help? +foreach (@ARGV) +{ + if (/^(--help)|(-h)$/) { die $HELP_MSG; } +} + +# Abort if dest doesn't exist - its existence should be a prereq +die "Destination directory not found. Is the DAP mounted?" unless -d $dest; + +# Clean out any tmpdir cruft +remove_tree $tmpdir; + + +foreach (@ARGV) +{ + next unless (-d); + + # Are any of the files flac? + my $has_flac; + my @files = `ls $_`; + foreach (@files) + { + chomp; + if (/\.flac$/i) + { + $has_flac = true; + break; + } + } + + # If we have flac, copy to tmpdir and convert first, then copy to + # dest + if ($has_flac) + { + make_path "$tmpdir/$_"; + make_path "$dest/$_"; + system("cp -r $_/* $tmpdir/$_/"); + system("conv2ogg $tmpdir/$_/*.flac"); + system("cp -r $tmpdir/$_/* $dest/$_/"); + } + else + { + make_path "$dest/$_"; + system("cp -r $_/* $dest/$_/"); + } + + undef $has_flac; +} + +remove_tree $tmpdir;