Added support for specifying files in directories other than working dir
This commit is contained in:
parent
922d8b89ae
commit
2790a51339
49
conv2ogg
49
conv2ogg
|
@ -1,13 +1,17 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# MP3 - Ogg converter
|
||||
# usage: mp32ogg <files>
|
||||
# Ogg converter
|
||||
# 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 mplayer for support for non-mp3 filetypes
|
||||
#
|
||||
# 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
|
||||
# Added support for m4a if using mplayer
|
||||
# 0.2: Aligned version with ds-audiotools
|
||||
|
@ -21,12 +25,14 @@
|
|||
# changed to use command-line args
|
||||
# 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>";
|
||||
$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')";
|
||||
|
||||
chomp($tempdir = '/tmp/mp32ogg-' . `whoami`);
|
||||
use File::Path qw(make_path remove_tree);
|
||||
|
||||
chomp($tempdir = '/tmp/conv2ogg-' . `whoami`);
|
||||
|
||||
|
||||
# Do we need help?
|
||||
|
@ -53,13 +59,24 @@ die $DEC_ERROR if (! -x $decoder);
|
|||
die $ENC_ERROR if (! -x $encoder);
|
||||
|
||||
# Set up the temp directory
|
||||
system('rm', '-rf', $tempdir) if (-d $tempdir);
|
||||
mkdir($tempdir);
|
||||
remove_tree $tempdir;
|
||||
make_path $tempdir;
|
||||
|
||||
foreach(@ARGV)
|
||||
{
|
||||
my $directory;
|
||||
if (/\//)
|
||||
{
|
||||
$directory = $_;
|
||||
$directory =~ s|^(.*)/.*?$|\1|;
|
||||
}
|
||||
else { $directory = '.'; }
|
||||
|
||||
$filename = $_;
|
||||
$short_name = $_;
|
||||
$filename =~ s|^.*/(.*)?$|\1|;
|
||||
|
||||
$short_name = $filename;
|
||||
|
||||
if ($decoder =~ /mplayer/)
|
||||
{
|
||||
next if (/\.ogg/);
|
||||
|
@ -72,18 +89,20 @@ foreach(@ARGV)
|
|||
}
|
||||
|
||||
# Transcode the file
|
||||
system("$decoder $filename $decoder_options$tempdir/$short_name.wav");
|
||||
system($encoder, "$tempdir/$short_name.wav", '-o', "$short_name.ogg");
|
||||
system("$decoder $directory/$filename $decoder_options$tempdir/$short_name.wav");
|
||||
system($encoder, "$tempdir/$short_name.wav", '-o', "$directory/$short_name.ogg");
|
||||
|
||||
# Remove cruft
|
||||
system('rm', "$tempdir/$short_name.wav");
|
||||
system('rm', "$filename");
|
||||
# Remove old file
|
||||
system('rm', "$directory/$filename");
|
||||
}
|
||||
|
||||
# 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
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
Reference in New Issue
Block a user