Compare commits

...

No commits in common. "0.2.3" and "master" have entirely different histories.

10 changed files with 401 additions and 152 deletions

21
INSTALL
View File

@ -9,12 +9,27 @@ export PATH=$PATH:~/bin
Install ALL of the scripts, since some of them depend on others.
cdripper requires the CDDB and CDDB_get perl modules.
You will need the following perl modules for cdripper to work:
CDDB
CDDB_get
These are only needed if you want to pass '-y' to tagfromfilename:
Music::Tag::OGG
Music::Tag::FLAC
Music::Tag::MP3
Music::Tag::MusicBrainz
You will also need the following programs:
cdparanoia
mplayer, mpg321, or mpg123
oggenc
cdrecord
oggenc
vorbiscomment
metaflac (for flac support)
metaflac
id3v2

58
NEWS Normal file
View File

@ -0,0 +1,58 @@
simple-audiotools changes
-------------------------
v 0.2.4 ():
* cdripper: fixed bug with file tagging
Added options: -T, -0, -q, -f
* conv2ogg: Allow mplayer to handle any non-ogg file
Make invocations of files in other directories work
Use File::Path where appropriate
Added -q option
* fixname: Added ability to read from stdin
Better stripping of special characters
* tagfromfilename: added -T option
added releasedate support through MusicBrainz
added mp3 support and refactored code heavily
added -y option to explicitly look for the year
v 0.2.3:
* tagfromfilename: added -0 option
v 0.2.2:
* tagfromfilename: added flac support, documentation
v 0.2.1:
* conv2ogg: Added new options to mplayer for mplayer's new features
Added support for m4a if using mplayer
* tagfromfilename: fixed handling of dashes in artist name and title
v 0.2:
* cdripper: Implemented CDDB support
Ability to preview and edit track names before they're used
Added -y and -a options
* fixname: made everything more robust
v 0.1.4:
* fixname: added -o option
v 0.1.3:
* conv2ogg: Added mplayer support, automatically select decoder
Secured passing args to system() calls
v 0.1.2:
* added version variables
* cdripper: Removed the erroneous fixname, updated fixname to do what I need
Name prompt uses natural characters (capitals and spaces)
Added -o option
* conv2ogg: Use a temp dir for storage of intermediate wav file
Cleaned up some syntax
v 0.1.1:
* burnmusic: added command-line wrapper
v 0.1:
* Converted to perl
* cdripper: improved file naming system
* cdripper: integrated with vcfromfilename
* conv2ogg: use command-line args instead of stdin/stdout
v 0.0.4:
* cdripper: bug fixes
* fixname: fixed __ becoming - instead of _
v 0.0.3:
* cdripper: fixed bug with track numbers
v 0.0.2:
* Converted to bash
* fixname: use command-line args
v 0.0.1:
* Initial release

24
README Normal file
View File

@ -0,0 +1,24 @@
simple-audiotools is just a collection of perl scripts that I created over time as I found myself needing to do various things with my audio files in Linux.
Enjoy! And if you find anything doesn't work, feel free to file a bug on github :)
burnmusic - This program takes a speed to burn at, a CD-RW device file, and then a list of files to burn. It automatically converts them to .wav files, then burns them in CDDA-format (compatible with CD players). I never use this any more, so it is probably buggy and hasn't been updated in a very, very long time.
cdripper - cdripper rips the CD in whatever drive cdparanoia reads by default. It does a lot of neat stuff, including using CDDB to automatically generate filenames - if it can't find them, you'll be prompted to enter them interactively.
conv2ogg - transcodes anything you give it to ogg vorbis (decodes to PCM using mplayer, then encodes that into vorbis). This incurs a loss of quality, but if you want to take your music somewhere you don't have mp3 capability, this is nice.
cp2dap - designed for devices that support mp3 and ogg vorbis but not flac, such as most Android phones. Converts flacs to ogg, then copies everything over to your player (which is assumed to be mounted at /mnt/phone, and have /mnt/phone/music where music should be placed - these defaults are smart for Android)
dirclean - Possibly useful outside of music management - I wrote it as an easy way to list artist/album combinations on my filesystem.
fixname - renames files to fit my preferred standard, which is very Linux-friendly. Used in conjunction with rename, it can help you clean up odd filenames quickly.
tagfromfilename - Uses the filename and parent directory of a file to create metadata (vorbis comments, flac metadata, or ID3v2, as appropriate).

View File

@ -7,14 +7,8 @@
# The track order is as passed on the commandline
#
# Requires oggdec, mpg321, cdrecord
#
# ChangeLog:
# 0.2: Aligned version with ds-audiotools
# 0.1.2: Added version variable
# 0.1.1: Added command-line wrapper, cleaned code
# 0.1: Initial code
$VERSION = "0.2.3";
$VERSION = "git";
$HELP_MSG = "# Music Burner v$VERSION\n\tusage: burnmusic <cdspeed> <device> <files>\n";
$temp_dir = '/tmp/burnmusic-' . `whoami`;
@ -48,8 +42,7 @@ system('cdrecord', '-v -pad -audio', "speed=$cdspeed", "dev=$device", "$temp_dir
system("rm -rf $temp_dir");
# Copyright (c) 2005 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
# the Free Software Foundation; either version 2 of the License, or

View File

@ -1,46 +1,30 @@
#!/usr/bin/perl
#
# CD Ripper
# usage: cdripper [-o num] [--no-cddb] [-a] [-y] [target_directory]
# usage: cdripper [-o num] [--no-cddb] [-T] [-0] [-a] [-y] [target_directory]
#
# Rips the contents of an audio CD into Ogg Vorbis files
# Puts the files in target_directory/artist/album_name/
# (default target_directory is ./)
#
# Requires cdparanoia, oggenc, vcfromfilename
#
# Changelog:
# 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
# -y option to suppress all user input, taking defaults
# -a option to be asked about CDDB options
# 0.1.2: Removed the erroneous fixname, updated fixname to do what I need
# Now you can name things with natural characters, and it should be
# automatically fixed
# Added the -o option, functions as -o num, makes the first track
# num + 1
# 0.1.1: Added version variable
# 0.1: changed to perl (from bash)
# improved file naming mechanism
# added Vorbiscomment updating (using vcfromfilename script)
# added program to ds-audio package
# 0.0.4: fixed track #s above 10 not happening :P
# 0.0.3: fixed the bug with track #s
# 0.0.2: changed entire code to bash script (from C++)
# 0.0.1: basic code in place
use CDDB_get qw( get_cddb );
$VERSION = "0.2.3";
$VERSION = "git";
$HELP_MSG = "# CD Ripper v$VERSION\n\tusage: cdripper [--no-cddb] [-a] " .
"[-y] [-o num] [target_directory]\n\n" .
"[-y] [-T] [-0] [-o num] [target_directory]\n\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" .
"-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\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`);
@ -49,6 +33,9 @@ $offset = 0;
$useCDDB = 1;
$noInput = 0;
$askCDDB = 0;
$flac_mode = 0;
$tagoptions = '';
foreach (@ARGV)
{
@ -57,13 +44,22 @@ 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
{
$target_directory = $_;
@ -71,6 +67,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);
@ -81,7 +82,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);
@ -100,7 +108,11 @@ chdir($final_location);
warn "Some files were not automatically named." if $unhandledFiles;
# Add vorbiscomment data
system('vcfromfilename', @new_tracks);
#debug
print `pwd`;
print `ls`;
#end debug
system('tagfromfilename', $tagoptions, @new_tracks);
# Clean up
chdir($orig_dir);
@ -138,8 +150,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++;
@ -167,7 +179,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++;
@ -202,7 +214,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/;
@ -267,8 +279,7 @@ sub get_number_of_tracks()
return pop @tracks;
}
# Copyright (c) 2004 - 2007 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
# the Free Software Foundation; either version 2 of the License, or

View File

@ -1,38 +1,37 @@
#!/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
#
# Changelog:
# 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
# 0.1.3: Added mplayer support, automatically select decoder
# Fixed option passing to system() calls to be as secure as possible
# 0.1.2: added support for passing flags
# Use a temp dir for storage of intermediate wav file
# Cleaned up some syntax
# Added version variable
# 0.1: converted to perl
# changed to use command-line args
# 0.0.1: Initial bash script
# Requires mplayer for support for non-mp3 filetypes
$VERSION = "0.2.3";
$HELP_MSG = "# MP3 - Ogg Converter v$VERSION\n\tusage: mp32ogg <files>";
$VERSION = "git";
$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')";
chomp($tempdir = '/tmp/mp32ogg-' . `whoami`);
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
@ -53,17 +52,28 @@ 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 unless (/\.(m4a|mp3)/);
$short_name =~ s/\.(mp3|m4a)$//;
next if (/\.ogg/);
$short_name =~ s/\..*?$//;
}
else
{
@ -72,19 +82,19 @@ 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, "-q $quality", "$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
#
# 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
# the Free Software Foundation; either version 2 of the License, or

73
cp2dap Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/perl
#
# Expects a list of directories that contain ogg|flac
# Directories should be of the form: artist/album
# (i.e., not full paths or relative paths other than this)
$VERSION = "git";
$HELP_MSG = "# Copy files to DAP, converting flac to ogg v$VERSION\n\tusage: copy_top_dap artist1/album1 artist2/album2 ...";
use File::Path qw(make_path remove_tree);
use Cwd;
my $dest='/mnt/phone/music/';
my $tmpdir='/tmp/cp2dap/';
# Do we need help?
foreach (@ARGV)
{
if (/^(--help)|(-h)$/) { die $HELP_MSG; }
}
# Abort if dest doesn't exist - its existence should be a prereq
die "Destination directory not found. Is the DAP mounted?" unless -d $dest;
# Clean out any tmpdir cruft
remove_tree $tmpdir;
foreach (@ARGV)
{
next unless (-d);
# Are any of the files flac?
my $has_flac;
my @files = `ls $_`;
foreach (@files)
{
chomp;
if (/\.flac$/i)
{
$has_flac = true;
break;
}
}
# If we have flac, copy to tmpdir and convert first, then copy to
# dest
if ($has_flac)
{
make_path "$tmpdir/$_";
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
{
make_path "$dest/$_";
system("cp -r $_/* $dest/$_/");
}
undef $has_flac;
}
remove_tree $tmpdir;

View File

@ -10,12 +10,9 @@
#
# This information is printed to stdout.
# Further, the script only goes two levels deep.
#
# ChangeLog:
# 0.2 - aligned version with ds-audiotools
# 0.1 - initial version
$VERSION = "0.2.3";
$VERSION = "git";
$HELP_MSG = "# dirclean v$VERSION\n\tusage: dirclean <directory>\n\t";
foreach (@ARGV)

35
fixname
View File

@ -3,29 +3,17 @@
# File Name Fixer
# usage: fixname <files>
#
# Renames files to comply with darkside's arbitrary standard
# Renames files to comply with Anna's arbitrary standard
#
# This is darkside's standard:
# This is Anna's standard:
# 1) all letters are lowercase
# 2) Whitespace becomes underscore
# 3) Never more than one consecutive underscore
# 4) No underscores flanking dashes
# 4) Never more than one consecutive dash
#
# ChangeLog:
# 0.2: Made everything more robust - better at multiple spaces and special
# characters now. Also now renumbering along with ds-audiotools
# 0.1.4: Added -o option, which prints to stdout instead of renaming the file
# 0.1.3: Added version variable
# 0.1.2: Added help message
# 0.1.1: Made code compile and run, no known bugs
# 0.1: Switched code to perl with regular expressions
# 0.0.4: Minor bugs fixed, __ was becoming - instead of _
# 0.0.3: Minor bugs fixed, code improved
# 0.0.2: Takes command-line arguments instead of parsing entire directory
# 0.0.1: basic code in place
$VERSION = "0.2.3";
$VERSION = "git";
$HELP_MSG = "# Filename fixer v$VERSION\n\tusage: fixname <files>\n\t fixname -o \"name\"\n";
die $HELP_MSG if ($#ARGV < 0);
@ -36,19 +24,30 @@ foreach (@ARGV)
{
$toStdOut = true;
}
if (/^-i$/)
{
$fromStdIn = true;
}
}
@ARGV = grep(!/^-o$/, @ARGV) if ($toStdOut);
@ARGV = grep(!/^-i$/, @ARGV) if ($fromStdIn);
if ($fromStdIn) { @names = <STDIN>; }
else { @names = @ARGV; }
foreach (@ARGV)
{
my $oldname = $_;
s/(.*)/lc($1)/e; # Lowercase it
s/[^\w\s\.-]//g; # Remove odd characters
s/[()\[\]{}!@#\$%^*,;:\'~]//g; # Remove odd characters that could break bash
s/[&]/and/g; # & to 'and'
s/\s/_/g; # Change whitespace to _
s/_+/_/g; # Squash multiple spaces
s/\.+/\./g; # Squash multiple dots
s/^_*//; # Remove leading space
s/_*$//; # Remove trailing space
s/_*(-|\.)_*/$1/g; # Remove space flanking a - or .
@ -58,8 +57,6 @@ foreach (@ARGV)
}
# Copyright (c) 2004 - 2007 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
# the Free Software Foundation; either version 2 of the License, or

View File

@ -5,28 +5,24 @@
# options:
# -n: Only set the track number
# -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.
# Files should be in Patrick's arbitrary file name standard, which is:
# artist/album/artist-tracknum-title.(ogg|flac)
# Files should be in Anna's arbitrary file name standard, which is:
# artist/album/artist-tracknum-title.(ogg|flac|mp3)
#
# 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
#
# Changelog:
# 0.2.3: added documentation, -0 command-line option
# 0.2.2: added flac support, documentation
# 0.2.1: fixed version in help message
# fixed handling of dashes in artist name and title
# 0.2: aligned version with ds-audiotools
# 0.1.1: added version variable
# 0.1: initial implementation
$VERSION = "0.2.3";
$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";
$VERSION = "git";
$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\n";
use Music::Tag;
chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
@ -34,42 +30,80 @@ chomp($COMMENTFILENAME = '/tmp/vcfromfilename-' . `whoami`);
foreach (@ARGV)
{
if (/^(-h)|(--help)$/) { die $HELP_MSG; }
if (/^-n$/) { $tracknumonly = true; s/.*//g; }
if (/^-0$/) { $extrazero = true; s/.*//g; }
elsif (/^-n$/) { $tracknumonly = true; s/.*//g; }
elsif (/^-T$/) { $captagnames = true; s/.*//g; }
elsif (/^-0$/) { $extrazero = true; s/.*//g; }
elsif (/^-y$/) { $get_year = true; s/.*//g; }
else { push @tracks, $_; }
}
# Set the mode
if ($tracks[0] =~ /\.flac$/) { $mode = 'flac'; }
elsif ($tracks[0] =~ /\.mp3$/) { $mode = 'mp3'; }
elsif ($tracks[0] =~ /\.ogg$/) { $mode = 'ogg'; }
else { die "Couldn't detect mode"; }
# Set the album name
$album = `pwd`; # We WANT the newline here
$album =~ s/^.*\///; # Remove everything up to the last /
$album = formatName($album, 'album=');
$album = formatName($album, 'album=', $captagnames, $mode);
# Parse the file list, set vorbiscomments
# Try to find the release date
$year;
if ($get_year)
{
$mbinfo = Music::Tag->new($tracks[0]);
if ($mode eq 'ogg') { $mbinfo->add_plugin($mbinfo->plugin("OGG")); }
elsif ($mode eq 'flac') { $mbinfo->add_plugin($mbinfo->plugin("FLAC")); }
elsif ($mode eq 'mp3') { $mbinfo->add_plugin($mbinfo->plugin("MP3")); }
$mbinfo->add_plugin("MusicBrainz");
$mbinfo->get_tag();
$year = formatName($mbinfo->year, 'year=', $captagnames, $mode);
}
# Parse the file list, set comments
foreach (@ARGV)
{
next if (/^$/);
# check filename format
next unless (/^\w+-\d{1,2}-(\w|-|\d)+\.(ogg|flac)$/);
next unless (/^\w+-\d{1,2}-(\w|-|\d)+\.(ogg|flac|mp3)$/);
$isflac = true if (/\.flac$/);
open COMMENTFILE, '>' . $COMMENTFILENAME;
# Remove old flac comments that match
if ($isflac)
if ($mode eq 'flac' || $mode eq 'ogg')
{
open COMMENTFILE, '>' . $COMMENTFILENAME;
}
# Remove old comments
if ($mode eq 'flac')
{
system("metaflac --remove-tag=TRACKNUMBER $_");
system("metaflac --remove-tag=tracknumber $_");
if (!$tracknumonly)
{
system("metaflac --remove-tag=title --remove-tag=artist --remove-tag=album $_");
system("metaflac --remove-tag=TITLE --remove-tag=ARTIST --remove-tag=ALBUM --remove-tag=YEAR $_");
system("metaflac --remove-tag=title --remove-tag=artist --remove-tag=album --remove-tag=year $_");
}
}
# Preserve existing comments, except the ones we'll replace
elsif ($mode eq 'mp3')
{
system("id3v2 -D $_");
}
# For ogg, preserve existing comments, except the ones we'll replace
else
{
foreach (`vorbiscomment -l $_`)
{
if ($tracknumonly) { print COMMENTFILE $_ unless (/^tracknumber/); }
else { print COMMENTFILE $_ unless (/^(title)|(artist)|(tracknumber)|(album)/); }
if ($tracknumonly) { print COMMENTFILE $_ unless (/^tracknumber/i); }
else { print COMMENTFILE $_ unless (/^(title)|(artist)|(tracknumber)|(album)|(year)/i); }
}
}
@ -77,51 +111,88 @@ foreach (@ARGV)
if (!$tracknumonly)
{
# Add the artist
my $artist = $_;
$artist = $_;
$artist =~ s/^(.*?)-\d{2}-.*/\1/; # grab everything to the track number
$artist = formatName($artist, 'artist=');
print COMMENTFILE $artist;
$artist = formatName($artist, 'artist=', $captagnames, $mode);
# Add the title
my $title = $_;
$title =~ s/.*-\d{2}-(.*)\.(ogg|flac)$/\1/; # grab everything after the track number
$title = formatName($title, 'title=');
print COMMENTFILE $title;
$title = $_;
$title =~ s/.*-\d{2}-(.*)\.(ogg|flac|mp3)$/\1/; # grab everything after the track number
$title = formatName($title, 'title=', $captagnames, $mode);
# And the album
# For some modes, print everything to a comment file
if ($mode eq 'flac' || $mode eq 'ogg')
{
print COMMENTFILE $year;
print COMMENTFILE $artist;
print COMMENTFILE $title;
print COMMENTFILE $album;
}
}
# Now get the track number
my $tracknum = $_;
$tracknum =~ s/.*-(\d{2})-.*/\1/;
if (!$extrazeros) { $tracknum =~ s/\b0*//; } # removing leading zeros
$tracknum = formatName($tracknum, 'tracknumber=');
if (!$extrazero) { $tracknum =~ s/\b0*//; } # removing leading zeros
$tracknum = formatName($tracknum, 'tracknumber=', $captagnames, $mode);
if ($mode eq 'flac' || $mode eq 'ogg')
{
print COMMENTFILE $tracknum;
close COMMENTFILE;
}
if ($isflac) { system("metaflac --import-tags-from=$COMMENTFILENAME $_"); }
else { system("vorbiscomment -c $COMMENTFILENAME -w $_"); }
system('rm', $COMMENTFILENAME);
if ($mode eq 'flac') { system("metaflac --import-tags-from=$COMMENTFILENAME $_"); }
elsif ($mode eq 'mp3')
{
$tags = "";
$tags .= "-T $tracknum" if $tracknum;
if (!$tracknumonly)
{
$tags .= " -a '$artist'" if $artist;
$tags .= " -t '$title'" if $title;
$tags .= " -A '$album'" if $album;
$tags .= " -y $year" if $year;
}
system("id3v2 $tags $_");
}
elsif ($mode eq 'ogg')
{
system("vorbiscomment -c $COMMENTFILENAME -w $_");
}
if ($mode eq 'flac' || $mode eq 'ogg') { system('rm', $COMMENTFILENAME); }
}
# 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
{
my $name = shift;
my $prepend = shift;
my $upper = shift;
my $mode = shift;
if ($upper) { $prepend = uc($prepend); }
chomp $name; # we add a newline ourselves
$name =~ s/_/ /g; # underscore - space
$name =~ s/^\s*//; # Remove leading space
$name =~ s/\s*$//; # Remove trailing space
$name =~ s/\b(\w)/uc($1)/eg; # Cap the words
if ($mode eq 'flac' || $mode eq 'ogg')
{
$name = $prepend . $name . "\n";
}
return $name;
}
# Copyright (c) 2005 - 2008 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
# the Free Software Foundation; either version 2 of the License, or