#!/usr/bin/env perl # Usage: bulklame tracks_file use warnings; use strict; sub normalize; # # Get the artist name from stdin # my $artist = <>; chomp $artist; # # Get the album name from stdin # my $album = <>; chomp $album; # # Get the track names from stdin # my @titles; while (<>) { # Throw away newlines chomp; # Ignore blank lines next if /^\s*$/; push @titles, $_; } print "$artist\n"; print "$album\n"; print "-----\n"; for my $title (@titles) { print "$title\n"; } print "-----\n"; # # For each track, get the corresponding wav file and # convert to mp3 with the normalized name of the track # for a file name. # # Remove any single quote characters in the album or artist $album =~ s/'//g; $artist =~ s/'//g; my $track_count = 1; for my $title (@titles) { my $wav_name = sprintf 'track%02d.cdda.wav', $track_count; my $file_name = normalize $title; # Remove any single quote characters in the title $title =~ s/'//g; print "$title\n"; system("lame --ta '$artist' --tl '$album' --tt '$title' $wav_name $file_name.mp3"); $track_count++; } # # The normalized name will be all lowercase, using # underscores instead of spaces, and removing all # punctuation marks. # sub normalize { my $title = shift; # Convert to lower case $title = lc $title; # Turn every group of whitespace characters into a single # underscore $title =~ s/\s+/_/g; # Remove all of the punctuation characters (we'll just # define "punctuation" as anything not a letter or a # digit) $title =~ s/\W//g; # And we are done ... return $title; }