Added support for keeping leading 0s in metadata

This commit is contained in:
Anna Rose 2009-03-26 09:45:25 -04:00 committed by Patrick Wiggins
parent 7f26f287c1
commit 5dddb1f08e

View File

@ -4,23 +4,29 @@
# usage: vcfromfilename [options] <files> # usage: vcfromfilename [options] <files>
# options: # options:
# -n: Only set the track number # -n: Only set the track number
# -0: Leading 0s in track number are preserved
# #
# 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 darkside's arbitrary file name standard, which is: # Files should be in Patrick's arbitrary file name standard, which is:
# album/artist-tracknum-title.(ogg|flac) # artist/album/artist-tracknum-title.(ogg|flac)
#
# The top-level directory (artist) is optional. Filenames should contain no
# spaces; underscores in the filename are converted to spaces in the resulting
# metadata
# #
# Requires vorbiscomment and metaflac # Requires vorbiscomment and metaflac
# #
# Changelog: # Changelog:
# 0.2.2: added flac support # 0.2.3: added documentation, -0 command-line option
# 0.2.2: added flac support, documentation
# 0.2.1: fixed version in help message # 0.2.1: fixed version in help message
# fixed handling of dashes in artist name and title # fixed handling of dashes in artist name and title
# 0.2: aligned version with ds-audiotools # 0.2: aligned version with ds-audiotools
# 0.1.1: added version variable # 0.1.1: added version variable
# 0.1: initial implementation # 0.1: initial implementation
$VERSION = "0.2.2"; $VERSION = "0.2.3";
$HELP_MSG = "Vorbiscomment from Filename $VERSION\n\tusage: vcfromfilename [options] <files>\n"; $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";
chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`); chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
@ -29,6 +35,7 @@ foreach (@ARGV)
{ {
if (/^(-h)|(--help)$/) { die $HELP_MSG; } if (/^(-h)|(--help)$/) { die $HELP_MSG; }
if (/^-n$/) { $tracknumonly = true; s/.*//g; } if (/^-n$/) { $tracknumonly = true; s/.*//g; }
if (/^-0$/) { $extrazero = true; s/.*//g; }
} }
# Set the album name # Set the album name
@ -88,7 +95,7 @@ foreach (@ARGV)
# Now get the track number # Now get the track number
my $tracknum = $_; my $tracknum = $_;
$tracknum =~ s/.*-(\d{2})-.*/\1/; $tracknum =~ s/.*-(\d{2})-.*/\1/;
$tracknum =~ s/\b0*//; # removing leading zeros if (!$extrazeros) { $tracknum =~ s/\b0*//; } # removing leading zeros
$tracknum = formatName($tracknum, 'tracknumber='); $tracknum = formatName($tracknum, 'tracknumber=');
print COMMENTFILE $tracknum; print COMMENTFILE $tracknum;