#!/usr/bin/perl -w # File: rename-mp3s, v0.01 # Purpose: Rename a set of incorrectly named MP3 files based on the ID3 tags # Synopsis: rename-mp3s # Author: Bill Jonas # # Copyright (C) 2000 Bill Jonas # # 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 (at your option) any later version. # # 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. # # An electronic copy of the GPL is available at # . use strict; use MPEG::MP3Info; defined @ARGV || die "Usage: $0 \n"; my $file; my $tag; my $title; my $artist; my $newfilename; my $count = 0; foreach $file (@ARGV) { $tag = get_mp3tag($file); $artist = $tag->{ARTIST}; $title = $tag->{TITLE}; if (defined $artist && defined $title ) { $artist =~ tr/ /_/; $title =~ tr/ /_/; $newfilename = $artist . "-" . $title . ".mp3"; unless (-e $newfilename) { print "Renaming $file to $newfilename\n"; rename $file, $newfilename and $count++ or warn "Couldn't rename $file: $!\n"; } } } print "$count files successfully renamed!\n";