Added flac options

This commit is contained in:
Anna Rose 2010-09-13 23:14:57 -04:00 committed by Anna
parent d7b25a12a2
commit 6b4e37c667
3 changed files with 51 additions and 8 deletions

View File

@ -13,6 +13,7 @@
# 0.2.4: Fixed bug - files should get tagged again
# Added support for -T option
# Added support for -0 option
# Added -q and -f options
# 0.2: Aligned version with ds-audiotools
# Implemented CDDB support (disabled with --no-cddb)
# Ability to preview and edit all text before it's used
@ -43,9 +44,12 @@ $HELP_MSG = "# CD Ripper v$VERSION\n\tusage: cdripper [--no-cddb] [-a] " .
"-y:\t\tDon't prompt for user confirmation of CDDB information\n\t\t(assume defaults are okay).\n" .
"--no-cddb:\tDon't use CDDB. Prompt the user for all information.\n" .
"-T:\t\tWrite uppercase tag names. Passes -T to tagfromfilename\n" .
"-q <number>:\tquality to encode the vorbis data. Defaults to 10. Unused in FLAC mode.\n" .
"-f:\t\tencode to FLAC instead of vorbis\n" .
"-0:\t\tPreserve leading 0 in track numbers\n";
$CDPARANOIA_FORMAT = 'track*.cdda';
$quality = '7';
$TRACK_ZERO = 'track00';
chomp($orig_dir = `pwd`);
chomp($temp_dir = '/tmp/ds-cdripper-' . `whoami`);
@ -54,6 +58,7 @@ $offset = 0;
$useCDDB = 1;
$noInput = 0;
$askCDDB = 0;
$flac_mode = 0;
$tagoptions = '';
@ -64,13 +69,20 @@ foreach (@ARGV)
$offset = $_;
$offsetOnNext = 0;
}
elsif ($qualityOnNext)
{
$quality = $_;
$qualityOnNext = 0;
}
else
{
if (/^(--help)|(-h)$/) { print $HELP_MSG; exit; }
elsif (/^-o$/) { $offsetOnNext = 1; }
elsif (/^--no-cddb$/) { $useCDDB = 0; }
elsif (/^-f$/) { $noInput = 1; }
elsif (/^-y$/) { $noInput = 1; }
elsif (/^-a$/) { $askCDDB = 1; }
elsif (/^-f$/) { $flac_mode = 1; }
elsif (/^-q$/) { $qualityOnNext = 1; }
elsif (/^-T$/) { $tagoptions .= ' -T'; }
elsif (/^-0$/) { $tagoptions .= ' -0'; }
else
@ -80,6 +92,11 @@ foreach (@ARGV)
}
}
# Extension, for use in later commands
if ($flac_mode) { $extension = 'flac'; }
else { $extension = 'ogg'; }
# Create temp location
system("rm -rf $temp_dir 2> /dev/null");
mkdir($temp_dir);
@ -90,7 +107,14 @@ handle_names();
# Rip, convert
system('cdparanoia -B');
system("oggenc $CDPARANOIA_FORMAT.wav");
if ($flac_mode)
{
system("flac $CDPARANOIA_FORMAT.wav");
}
else
{
system("oggenc -q $quality $CDPARANOIA_FORMAT.wav");
}
$sanityTest = `ls -1 | wc -l`;
chomp $sanityTest;
die "No files were created. Aborting." unless ($sanityTest > 0);
@ -109,6 +133,10 @@ chdir($final_location);
warn "Some files were not automatically named." if $unhandledFiles;
# Add vorbiscomment data
#debug
print `pwd`;
print `ls`;
#end debug
system('tagfromfilename', $tagoptions, @new_tracks);
# Clean up
@ -147,8 +175,8 @@ sub getinfo_user
chomp (my $input = <STDIN>);
my $input = `fixname -o "$input"`;
my $track_name = $artist . '-' . $current_track . '-' . $input .
'.ogg';
my $track_name = $artist . '-' . $current_track . '-' . $input . '.' .
$extension;
push @new_tracks, $track_name;
$current_track++;
@ -176,7 +204,7 @@ sub getinfo_cddb
foreach (@{$cd{track}})
{
my $track_name = $artist . '-' . $current_track . '-' .
`fixname -o "$_"` . '.ogg';
`fixname -o "$_"` . '.' . $extension;
push @new_tracks, $track_name;
$current_track++;
@ -211,7 +239,7 @@ sub init_current_track
# Populates the @old_tracks array
sub init_old_tracks
{
foreach (`ls $CDPARANOIA_FORMAT.ogg`)
foreach (`ls $CDPARANOIA_FORMAT.$extension`)
{
chomp;
next if /$TRACK_ZERO/;

View File

@ -12,6 +12,7 @@
# 0.2.4: Allow mplayer to handle any non-ogg file
# Make invocations of files in other directories work
# Use File::Path where appropriate
# Added -q option
# 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
@ -26,7 +27,8 @@
# 0.0.1: Initial bash script
$VERSION = "0.2.4";
$HELP_MSG = "# Audio file - Ogg Converter v$VERSION\n\tusage: conv2ogg <files>";
$HELP_MSG = "# Audio file - Ogg Converter v$VERSION\n\tusage: conv2ogg [-q] <files>\n" .
"\t\t-q <number>: Use quality for encoding. Default 10";
$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')";
@ -34,11 +36,19 @@ use File::Path qw(make_path remove_tree);
chomp($tempdir = '/tmp/conv2ogg-' . `whoami`);
$quality = 7;
# Do we need help?
foreach (@ARGV)
{
if (/^(--help)|(-h)$/) { die $HELP_MSG; }
if ($qualityOnNext)
{
$quality = $_;
$qualityOnNext = 0;
}
elsif (/^-q$/) { $qualityOnNext = 1; }
}
# Select the encoder and decoder
@ -90,7 +100,7 @@ foreach(@ARGV)
# Transcode the file
system("$decoder $directory/$filename $decoder_options$tempdir/$short_name.wav");
system($encoder, "$tempdir/$short_name.wav", '-o', "$directory/$short_name.ogg");
system($encoder, "-q $quality", "$tempdir/$short_name.wav", '-o', "$directory/$short_name.ogg");
# Remove old file
system('rm', "$directory/$filename");

View File

@ -12,6 +12,7 @@ $HELP_MSG = "# Copy files to DAP, converting flac to ogg v$VERSION\n\tusage: cop
use File::Path qw(make_path remove_tree);
use Cwd;
my $dest='/mnt/dap/MUSIC';
my $tmpdir='/tmp/copy_to_dap';
@ -56,6 +57,10 @@ foreach (@ARGV)
make_path "$dest/$_";
system("cp -r $_/* $tmpdir/$_/");
system("conv2ogg $tmpdir/$_/*.flac");
my $dir = cwd;
chdir "$tmpdir/$_";
system("tagfromfilename *");
chdir $dir;
system("cp -r $tmpdir/$_/* $dest/$_/");
}
else