#!/usr/bin/perl # Script (C) Stuart Hickinbottom 2004 (stuart@hickinbottom.demon.co.uk). # You are free to use and modify this script as you like, but please leave in # my credit. Thank you. # Configure this script as an external compressor in EAC. # # In the command-to-run field enter: # # # In the command-line-parameters field enter enter the following (probably # best to copy-and-paste from here to avoid slip-ups): # "" --source-filename=%s --original-filename=%o # --artist="%a" --cdname="%g" --year="%y" --genre="%m" # Pick up more errors use warnings; use strict; # Import some facilities use Getopt::Long; use Pod::Usage; use File::Copy; use File::Path; use File::Basename; # Exit more cleanly from signals (ensure destructors/atexits called) use sigtrap qw(die INT QUIT); use sigtrap qw(die untrapped normal-signals stack-trace any error-signals); # Global definitions use constant EXT_WAV => "wav"; use constant EXT_CUE => "cue"; use constant EXT_TAG => "tag"; # Process command-line arguments my $verbose = ""; my $output_dir = "\\\\discovery\\media\\NewMusic"; my $source_filename = ""; my $original_filename = ""; my $artist = "No artist"; my $cdname = "No CD name"; my $year = ""; my $genre = ""; GetOptions("verbose" => \$verbose, "output-directory=s" => \$output_dir, "source-filename=s" => \$source_filename, "original-filename=s" => \$original_filename, "artist=s" => \$artist, "cdname=s" => \$cdname, "year=s" => \$year, "genre=s" => \$genre, "version" => sub { versionMessage(); }, "help|?" => sub { pod2usage(1) }) or die "Failed to understand command options"; # Output options in use print "Output directory: $output_dir\n" if $verbose; print "Source filename: $source_filename\n" if $verbose; print "Original filename: $original_filename\n" if $verbose; print "Artist: $artist\n" if $verbose; print "CD name: $cdname\n" if $verbose; print "Year: $year\n" if $verbose; print "Genre: $genre\n" if $verbose; # Create the destination directory. # Safely translate any dangerous characters. my $safe_artist = $artist; my $safe_cdname = $cdname; $safe_artist =~ tr/\/\\:*?"<>|/_________/; $safe_cdname =~ tr/\/\\:*?"<>|/_________/; my $output_directory = "$output_dir\\$safe_artist\\$safe_cdname"; print "Creating destination directory: $output_directory\n" if $verbose; mkpath $output_directory; unless (-d $output_directory && -w $output_directory) { die "Cannot create destination directory $output_directory: $!\n"; } # Break down the source filename. my $base_name; my $base_path; my $base_suffix; my $orig_base_name; my $orig_base_path; my $orig_base_suffix; ($base_name, $base_path, $base_suffix) = fileparse($source_filename, qr(\..*)); ($orig_base_name, $orig_base_path, $orig_base_suffix) = fileparse($original_filename, qr(\..*)); # Create a new output name (minus any extension). my $dest_filename = "$safe_artist - $safe_cdname"; # We now copy the WAV. my $dest_wav_filename = "$output_directory\\$dest_filename$base_suffix"; print "Copying source file $source_filename to $dest_wav_filename\n" if $verbose; move($source_filename, $dest_wav_filename) or die "Unable to copy source file $dest_wav_filename: $!\n"; # Now copy the CUESHEET (if present). my $source_cue_filename = "$base_path$orig_base_name." . EXT_CUE; my $dest_cue_filename = "$output_directory\\$dest_filename." . EXT_CUE; if (-r $source_cue_filename && -f $source_cue_filename) { print "Copying $source_cue_filename to $dest_cue_filename\n" if $verbose; move($source_cue_filename, $dest_cue_filename) or die "Unable to copy CUESHEET $dest_cue_filename: $!\n"; } else { print "No CUESHEET $source_cue_filename\n" if $verbose; } # Create our tags file. my $dest_tag_filename = "$output_directory\\$dest_filename." . EXT_TAG; print "Writing tags file $dest_tag_filename\n" if $verbose; open(TAGFILE, ">$dest_tag_filename") or die "Unable to create tag file $dest_tag_filename: $!\n"; print TAGFILE "# Tags applicable to this audio file\n"; print TAGFILE "artist: $artist\n"; print TAGFILE "cdname: $cdname\n"; print TAGFILE "year: $year\n"; print TAGFILE "genre: $genre\n"; close(TAGFILE) or die "Unable to close tag file $dest_tag_filename: $!\n"; # We've finished, so exit. exit 0; ############################# # The help text __END__ =head1 SYNOPSIS eac-wav-cue-tags.pl [options] Options: -help Show this help description -verbose Output progress messages -output-directory Override default location of output directory -source-filename Name of temporary source file (full pathname) -original-filename Eventual source filename (no pathname) -artist Artist name -cdname CD title -year Year of recording -genre Music genre =cut