#!/usr/bin/perl -w
use strict;
use MP3::Info;
#############################################################
# #
# #
# #
# NOAH SUSSMAN #
# #
# id3 #
# #
# Created 6/27/01 at 11:07 PM #
# #
# This script takes a list of directories as its argument. #
# For mp3s that don't have any id3 information, guess #
# the name of the artist and track based on the filename #
# and use the MP3-Info module to insert that guess into #
# the file as id3v1 tags. #
# #
#############################################################
# get_mp3tag returns the following hash values: TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE, TRACKNUM
foreach my $dir (@ARGV){ # Get a list of directories from the command line, then cycle through each directory performing the following:
chdir $dir or die qq{Can't open the directory "$dir" because : $!
} if $dir; # Go to the directory.
# search nested directories
while (<*>) { #for all files in the directory
if (-d "$_"){ # If the current file is a directory.
my $look_here = $dir."$_"; # Add the full path to the directory name
#$look_here =~ s/::/:/g; # UNCOMMENT THIS LINE ON MAC ONLY: Remove doubled colons (this fixes what I think may be a bug in MacPerl)
push @ARGV, $look_here; # Add the directory name to @ARGV
next;
}
}
# add id3 tags to files that don't have them
while (<*.mp3>) { # Then do the following to files that have the .mp3 file extension:
if (get_mp3tag($_)){ # if the current file already has id3 tags, skip it!
#print "Skipping $_ because it already has id3 tags!
";
next;
}
my $name = $_; # copy the current file's full name into $name
$name =~ s{
(.*?) # capture the filename up to
.mp3 # but not including the ".mp3" file extension
}{
$1
}ix;
# Now, most of my mp3s are named something like: "Tom Waits- Small Change.mp3", so I'm going to treat the name of the current file as a dash-delimited list, where the list items are ARTIST NAME - TRACK NAME. If there are more than two items in the list, they'll be ignored-- for now.
my @name = split (/-/, $name); # Store each item in our tab-delimited list in an array called @name
my $counter = 0;
foreach my $i (@name) { # For each item stored in the @name array
$i =~ s{^s*(.*?)s*$}{$1}g; #destroy trailing and leading whitespace
}
my $artist = $name[0]; # The name of the artist (hopefully!)
my $song = $name[1]; # (hopefully) the name of the track
# The script thinks "Gil Scott-Heron" is a dash-delimited list! So I wrote the Gil Scott-Heron filter:
my $gsf = $artist . $song ;
if ($gsf =~ /gil scottheron/i){ #If $artist is Gil Scott and $song is Heron, that's very wrong.
$artist = "Gil Scott-Heron"; # The artist's name is actually Gil Scott-Heron
$song = $name[2]; # Get the track name from the array, where it's been waiting patiently.
}
# Same problem with "Deee-Lite"
elsif ($gsf =~ /deeelite/i){
$artist = "Deee-Lite";
$song = $name[2];
}
# Same problem with "The Chi-Lites"
elsif ($gsf =~ /chilites/i){
$artist = "Chi-Lites";
$song = $name[2];
}
# Same problem with "T-Rex"
elsif ($gsf =~ /trex/i){
$artist = "T-Rex";
$song = $name[2];
}
#$song =~ s{.mp3}{}gi; # NT ONLY: I know I did this above, but that doesnt seem to work on my old NT workstation here at work, so I'm stripping the file extension again...
# set_mp3tag (FILE, TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE [, TRACKNUM]) is the syntax used by the MP3-Info module for defining the ID3v1 tags on an MP3 file
set_mp3tag ($_, $song, $artist, "", "", "I love music!"); # write the track and artist names to the mp3 file and that's it!
}
}
snippets |
December 24, 2011
id3.pl
Leave a Reply Cancel reply
You must be logged in to post a comment.