Created
May 5, 2011 21:32
-
-
Save devd/958007 to your computer and use it in GitHub Desktop.
Simple perl script to titlecase all upper case tags in your mp3 collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use MP3::Tag; | |
use File::Util; | |
my %hash=(); | |
#use constant and not argument so that user has to | |
#open the source | |
use constant BASEDIR=>'/tmp/music'; | |
#unsafe -- the MP3::Tag docs say use at your own risk | |
# I used without issues, but I had a backup | |
# uncomment to use | |
#MP3::Tag->config('write_v24'=>1); | |
my $f = File::Util->new(); | |
foreach my $file ($f->list_dir(BASEDIR,'--recurse','--files-only' )){ | |
next unless $file =~ m/mp3$/i; | |
my $mp3 = MP3::Tag->new($file); | |
my $hashref = $mp3->autoinfo(); | |
for my $k ('title','album','artist'){ | |
next unless exists $hashref->{$k}; | |
next if $hashref->{$k} =~ m/\d+/; | |
next unless $hashref->{$k}; | |
if($hashref->{$k} eq (uc $hashref->{$k})){ | |
my $title=$hashref->{$k}; | |
$title =~ s/(\w+)/\u\L$1/g; | |
$mp3->update_tags({$k => $title}); | |
$hash{$file}=1; | |
} | |
} | |
} | |
#print list of files modified | |
print STDERR join("\n",keys %hash); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment