#!/usr/bin/perl -s ## trackident for cdparanoia v01 ## syntax: trackident -cddb=cddb-file -dir=directory-of-wav-files ## ## trackinent parses the specified cddb database record and ## renames the wav files created by cdparanoia with a string ## containing both artist and track names. ## ## copyright (c) 1998, vipul ved prakash. all rights reserved. ## this program is free software; you can redistribute it and ## or modify it under the same terms as perl itself. die ( "trackident -cddb=cddb-file -dir=directory-of-wav-files [-debug]\n" ) unless ( $cddb && $dir ); die ( "$cddb is not a CDDB entry" ) unless ( -e $cddb ); die ( "$dir is not directory entry" ) unless ( -d $dir ); open ( CDDB, $cddb ); my @CDDB = ; close CDDB; chdir ( $dir ); my @FILES = `ls -1`; chomp @FILES; my $title = &title || die ( "Disk Title Unknown." ); my $track, $number; TRACK: for ( @FILES ) { unless ( defined ( $number = &number ( $_ ) ) ) { print "$_ is not a track. Ignoring.\n"; next TRACK; } unless ( $track = &trackname ( $number ) ) { print ( "Track Number $number doesn't have en entry.\n" ); next TRACK; } my $new = "($title)($track).mp3"; print "Moving $_ --> $new ...\n"; system ( "mv \"$_\" \"$new\"" ) unless $debug; } sub number { my ( $file ) = shift; $file =~ /track(\d+)/; return $1 ? $1 -1 : undef; } sub title { my ( $match ) = grep /DTITLE/, @CDDB; if ( $match ) { my ( $title ) = $match =~ /DTITLE\=(.*?)\//; $title =~ s/\s+$//; return $title; } return undef; } sub trackname { my ( $number ) = shift; my ( $match ) = grep /TITLE$number/, @CDDB; if ( $match ) { my ( $track ) = $match =~ /\=(.*)$/; return $track; } return undef; }