#!/usr/bin/perl -w # # cddb_cleanup # $Id$ # # Copyright (C) 2002 by John Heidemann # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License, # version 2, as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. # require 5.000; sub usage { print STDERR <= 0 && $ARGV[0] eq '-?'); my(%opts); &GetOptions(\%opts, qw(o=s d)); # v a e=s o=s@ &usage if ($#ARGV < 0); my($debug) = defined($opts{'d'}); my($out) = $opts{'o'}; my $fix_the = 0; my $fix_reversed_names = 1; my %reversed_name_exceptions; foreach (split(/;/, q{ XMission, LLC; y, J; Various, BBC; Various, Classical; Various, Country; Various, EdgeCore; Various, Independent; Various, Rock; Various, Sony; to, organ; Rappa, o; Rachmaninov, Listz; n, Manu; I, Napoleon; in, Jerusalem; I, Parasite; e, Cambridge; Bartok, Copland; Bartok, Ravel; Beethoven, Bruch; Beethoven, Mendelssohn; Beethoven, Mozart; Beethoven, Perl; Beethoven, Schubert; Bernstein, Sondheim; Bernstein, Tchaikovsky; Bizet, Tchaikovsky; Brahms, Beethoven; Brahms, Dvorak; Brahms, Elgar; Brahms, Reger; Dvorak, Brahms; Dvorak, Schubert; Faure, Durufle; Holst, Elgar; Kreisler, vln; Lassus, Palestrina; Mussorgsky, Prokofiev; Mussorgsky, Stravinsky; Mussorgsky, Tschaikowsky; Paganini, Lalo; Prokofiev, Britten; Rachmaninov, Listz; Ravel, Debussy; RNO, Pletnev; Schumann, Strauss; Smetana, Debussy; Smetana, Dvorak; Stravinsky, Borodin; Stravinsky, Debussy; Stravisnksy, Boulez; Tomita, Debussy; Various, Classical; Various, Sony; })) { s/^[ \t\n]+//; s/[ \t\n]+$//; $reversed_name_exceptions{lc($_)} = 1; }; if (defined($out)) { open(LOG, ">$out") || die "$0: cannot write log $out\n"; } else { open(LOG, ">/dev/null") || die "$0: cannot write log $out\n"; }; foreach (@ARGV) { cleanup_file($_); }; sub cleanup_file { my($f) = @_; my($e) = CDDB::File->new($f); my($has_the) = ($fix_the && $e->_title_line =~ /^The /i && !($e->_title_line =~ /^The The /i)); # egrep -i 'DTITLE=[a-z]+, [a-z]+ /' * my($has_reversed_name) = ($fix_reversed_names && $e->artist =~ /^([A-Za-z]+, [A-Za-z]+)$/ && !defined($reversed_name_exceptions{lc($e->artist)})); return if (!($has_the || $has_reversed_name)); # # needs fix # my(@lines) = $e->_data; my($fixes) = ''; # remember it print LOG $f if (defined($out)); # # Remove "The" in band names: # try and preserve capitalization # if ($has_the) { $fixes .= "-the"; grep(s/(DTITLE=)The ([a-z])/$1\u$2/, @lines); grep(s/(DTITLE=)The /$1/, @lines); }; # # Fixe reversed names # if ($has_reversed_name) { $fixes .= "-rn"; grep(s/(DTITLE=)([A-Za-z]+), ([A-Za-z]+)/$1$3 $2/, @lines); }; # # write out the update # rename($f, "$f$fixes~") || die "$0: rename failed.\n"; open(OUTF, ">$f") || die "$0: cannot create $f.\n"; print OUTF join("\n", @lines); close OUTF; } exit 0;