Added -T option for cdripper and tagfromfilename.

This commit is contained in:
Anna Rose 2009-03-27 17:44:17 -04:00 committed by Patrick Wiggins
parent d8aa8d9856
commit d629c49b49
2 changed files with 21 additions and 11 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
# #
# CD Ripper # CD Ripper
# usage: cdripper [-o num] [--no-cddb] [-a] [-y] [target_directory] # usage: cdripper [-o num] [--no-cddb] [-T] [-a] [-y] [target_directory]
# #
# Rips the contents of an audio CD into Ogg Vorbis files # Rips the contents of an audio CD into Ogg Vorbis files
# Puts the files in target_directory/artist/album_name/ # Puts the files in target_directory/artist/album_name/
@ -11,6 +11,7 @@
# #
# Changelog: # Changelog:
# 0.2.4: Fixed bug - files should get tagged again # 0.2.4: Fixed bug - files should get tagged again
# Added support for -T option
# 0.2: Aligned version with ds-audiotools # 0.2: Aligned version with ds-audiotools
# Implemented CDDB support (disabled with --no-cddb) # Implemented CDDB support (disabled with --no-cddb)
# Ability to preview and edit all text before it's used # Ability to preview and edit all text before it's used
@ -39,7 +40,8 @@ $HELP_MSG = "# CD Ripper v$VERSION\n\tusage: cdripper [--no-cddb] [-a] " .
"Options:\n-a:\t\tAsk users about multiple CDDB options\n" . "Options:\n-a:\t\tAsk users about multiple CDDB options\n" .
"-o [num]:\tOffset track numbers by num. The first track will be num+1\n" . "-o [num]:\tOffset track numbers by num. The first track will be num+1\n" .
"-y:\t\tDon't prompt for user confirmation of CDDB information\n\t\t(assume defaults are okay).\n" . "-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"; "--no-cddb:\tDon't use CDDB. Prompt the user for all information.\n" .
"-T:\t\tWrite uppercase tag names. Passes -T to tagfromfilename";
$CDPARANOIA_FORMAT = 'track*.cdda'; $CDPARANOIA_FORMAT = 'track*.cdda';
$TRACK_ZERO = 'track00'; $TRACK_ZERO = 'track00';
@ -65,6 +67,7 @@ foreach (@ARGV)
elsif (/^--no-cddb$/) { $useCDDB = 0; } elsif (/^--no-cddb$/) { $useCDDB = 0; }
elsif (/^-f$/) { $noInput = 1; } elsif (/^-f$/) { $noInput = 1; }
elsif (/^-a$/) { $askCDDB = 1; } elsif (/^-a$/) { $askCDDB = 1; }
elsif (/^-T$/) { $uppertags = '-T'; }
else else
{ {
$target_directory = $_; $target_directory = $_;
@ -101,7 +104,7 @@ chdir($final_location);
warn "Some files were not automatically named." if $unhandledFiles; warn "Some files were not automatically named." if $unhandledFiles;
# Add vorbiscomment data # Add vorbiscomment data
system('tagfromfilename', @new_tracks); system('tagfromfilename', $uppertags, @new_tracks);
# Clean up # Clean up
chdir($orig_dir); chdir($orig_dir);

View File

@ -5,6 +5,7 @@
# options: # options:
# -n: Only set the track number # -n: Only set the track number
# -0: Leading 0s in track number are preserved # -0: Leading 0s in track number are preserved
# -T: Tag names (not tag content) written to the metadata in all caps
# #
# Adds Vorbiscomment data to ogg vorbis and flac files based on the filename. # Adds Vorbiscomment data to ogg vorbis and flac files based on the filename.
# Files should be in Patrick's arbitrary file name standard, which is: # Files should be in Patrick's arbitrary file name standard, which is:
@ -17,6 +18,7 @@
# Requires vorbiscomment and metaflac # Requires vorbiscomment and metaflac
# #
# Changelog: # Changelog:
# 0.2.4: added -T option
# 0.2.3: added documentation, -0 command-line option # 0.2.3: added documentation, -0 command-line option
# 0.2.2: added flac support, documentation # 0.2.2: added flac support, documentation
# 0.2.1: fixed version in help message # 0.2.1: fixed version in help message
@ -25,8 +27,8 @@
# 0.1.1: added version variable # 0.1.1: added version variable
# 0.1: initial implementation # 0.1: initial implementation
$VERSION = "0.2.3"; $VERSION = "0.2.4";
$HELP_MSG = "Vorbiscomment from Filename $VERSION\n\tusage: vcfromfilename [options] <files>\n\nValid options:\n\t-n\tOnly set the track numbers\n\t-0\tPreserve leading 0s in track numbers"; $HELP_MSG = "Vorbiscomment from Filename $VERSION\n\tusage: vcfromfilename [options] <files>\n\nValid options:\n\t-n\tOnly set the track numbers\n\t-0\tPreserve leading 0s in track numbers\n\t-T: Write tag names (not tag content) in all caps";
chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`); chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
@ -34,14 +36,15 @@ chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
foreach (@ARGV) foreach (@ARGV)
{ {
if (/^(-h)|(--help)$/) { die $HELP_MSG; } if (/^(-h)|(--help)$/) { die $HELP_MSG; }
if (/^-n$/) { $tracknumonly = true; s/.*//g; } elsif (/^-n$/) { $tracknumonly = true; s/.*//g; }
if (/^-0$/) { $extrazero = true; s/.*//g; } elsif (/^-T$/) { $captagnames = true; s/.*//g; }
elsif (/^-0$/) { $extrazero = true; s/.*//g; }
} }
# Set the album name # Set the album name
$album = `pwd`; # We WANT the newline here $album = `pwd`; # We WANT the newline here
$album =~ s/^.*\///; # Remove everything up to the last / $album =~ s/^.*\///; # Remove everything up to the last /
$album = formatName($album, 'album='); $album = formatName($album, 'album=', $captagnames);
# Parse the file list, set vorbiscomments # Parse the file list, set vorbiscomments
foreach (@ARGV) foreach (@ARGV)
@ -79,13 +82,13 @@ foreach (@ARGV)
# Add the artist # Add the artist
my $artist = $_; my $artist = $_;
$artist =~ s/^(.*?)-\d{2}-.*/\1/; # grab everything to the track number $artist =~ s/^(.*?)-\d{2}-.*/\1/; # grab everything to the track number
$artist = formatName($artist, 'artist='); $artist = formatName($artist, 'artist=', $captagnames);
print COMMENTFILE $artist; print COMMENTFILE $artist;
# Add the title # Add the title
my $title = $_; my $title = $_;
$title =~ s/.*-\d{2}-(.*)\.(ogg|flac)$/\1/; # grab everything after the track number $title =~ s/.*-\d{2}-(.*)\.(ogg|flac)$/\1/; # grab everything after the track number
$title = formatName($title, 'title='); $title = formatName($title, 'title=', $captagnames);
print COMMENTFILE $title; print COMMENTFILE $title;
# And the album # And the album
@ -96,7 +99,7 @@ foreach (@ARGV)
my $tracknum = $_; my $tracknum = $_;
$tracknum =~ s/.*-(\d{2})-.*/\1/; $tracknum =~ s/.*-(\d{2})-.*/\1/;
if (!$extrazeros) { $tracknum =~ s/\b0*//; } # removing leading zeros if (!$extrazeros) { $tracknum =~ s/\b0*//; } # removing leading zeros
$tracknum = formatName($tracknum, 'tracknumber='); $tracknum = formatName($tracknum, 'tracknumber=', $captagnames);
print COMMENTFILE $tracknum; print COMMENTFILE $tracknum;
close COMMENTFILE; close COMMENTFILE;
@ -107,10 +110,14 @@ foreach (@ARGV)
} }
# Formats the first argument, adds the second argument to it # Formats the first argument, adds the second argument to it
# If the third argument is true, the second argument is converted
# to upper case
sub formatName sub formatName
{ {
my $name = shift; my $name = shift;
my $prepend = shift; my $prepend = shift;
my $upper = shift;
if ($upper) { $prepend = uc($prepend); }
chomp $name; # we add a newline ourselves chomp $name; # we add a newline ourselves
$name =~ s/_/ /g; # underscore - space $name =~ s/_/ /g; # underscore - space
$name =~ s/^\s*//; # Remove leading space $name =~ s/^\s*//; # Remove leading space