Added support for specifying files in directories other than working dir

This commit is contained in:
Anna Rose 2010-03-25 15:14:06 -04:00 committed by Patrick Wiggins
parent 922d8b89ae
commit 2790a51339

View File

@ -1,13 +1,17 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# MP3 - Ogg converter # Ogg converter
# usage: mp32ogg <files> # usage: conv2ogg <files>
# #
# Creates ogg files from the selected mp3 files # Creates ogg files from the selected audio files
# #
# Requires one of mpg321, mpg123 or mplayer, and oggenc # Requires one of mpg321, mpg123 or mplayer, and oggenc
# Requires mplayer for support for non-mp3 filetypes
# #
# Changelog: # Changelog:
# 0.2.4: Allow mplayer to handle any non-ogg file
# Make invocations of files in other directories work
# Use File::Path where appropriate
# 0.2.1: Added new options to mplayer for mplayer's new features # 0.2.1: Added new options to mplayer for mplayer's new features
# Added support for m4a if using mplayer # Added support for m4a if using mplayer
# 0.2: Aligned version with ds-audiotools # 0.2: Aligned version with ds-audiotools
@ -21,12 +25,14 @@
# changed to use command-line args # changed to use command-line args
# 0.0.1: Initial bash script # 0.0.1: Initial bash script
$VERSION = "0.2.3"; $VERSION = "0.2.4";
$HELP_MSG = "# MP3 - Ogg Converter v$VERSION\n\tusage: mp32ogg <files>"; $HELP_MSG = "# MP3 - Ogg Converter v$VERSION\n\tusage: mp32ogg <files>";
$DEC_ERROR = "Couldn't find a decoder to use. Please install one of mplayer, mpg321, or mpg123"; $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')"; $ENC_ERROR = "Couldn't find oggenc, which is necessary for encoding. Please install the package that provides oggenc (probably named 'oggenc' or 'vorbistools')";
chomp($tempdir = '/tmp/mp32ogg-' . `whoami`); use File::Path qw(make_path remove_tree);
chomp($tempdir = '/tmp/conv2ogg-' . `whoami`);
# Do we need help? # Do we need help?
@ -53,13 +59,24 @@ die $DEC_ERROR if (! -x $decoder);
die $ENC_ERROR if (! -x $encoder); die $ENC_ERROR if (! -x $encoder);
# Set up the temp directory # Set up the temp directory
system('rm', '-rf', $tempdir) if (-d $tempdir); remove_tree $tempdir;
mkdir($tempdir); make_path $tempdir;
foreach(@ARGV) foreach(@ARGV)
{ {
my $directory;
if (/\//)
{
$directory = $_;
$directory =~ s|^(.*)/.*?$|\1|;
}
else { $directory = '.'; }
$filename = $_; $filename = $_;
$short_name = $_; $filename =~ s|^.*/(.*)?$|\1|;
$short_name = $filename;
if ($decoder =~ /mplayer/) if ($decoder =~ /mplayer/)
{ {
next if (/\.ogg/); next if (/\.ogg/);
@ -72,18 +89,20 @@ foreach(@ARGV)
} }
# Transcode the file # Transcode the file
system("$decoder $filename $decoder_options$tempdir/$short_name.wav"); system("$decoder $directory/$filename $decoder_options$tempdir/$short_name.wav");
system($encoder, "$tempdir/$short_name.wav", '-o', "$short_name.ogg"); system($encoder, "$tempdir/$short_name.wav", '-o', "$directory/$short_name.ogg");
# Remove cruft # Remove old file
system('rm', "$tempdir/$short_name.wav"); system('rm', "$directory/$filename");
system('rm', "$filename");
} }
# Remove last of the cruft # Remove last of the cruft
system('rm', '-rf', $tempdir); remove_tree $tempdir;
# Copyright (c) 2005 - 2008 John Wiggins
# Copyright (c) 2005 - 2010 John Wiggins
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by