Added a script that copies files to a DAP, converting flac files to ogg to save space

This commit is contained in:
Anna Rose 2010-03-25 15:16:37 -04:00 committed by Patrick Wiggins
parent 2790a51339
commit d7b25a12a2
2 changed files with 71 additions and 1 deletions

View File

@ -26,7 +26,7 @@
# 0.0.1: Initial bash script
$VERSION = "0.2.4";
$HELP_MSG = "# MP3 - Ogg Converter v$VERSION\n\tusage: mp32ogg <files>";
$HELP_MSG = "# Audio file - Ogg Converter v$VERSION\n\tusage: conv2ogg <files>";
$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')";

70
copy_to_dap Executable file
View File

@ -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;