Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: title/artist info

by dree (Monsignor)
on Jul 27, 2002 at 12:19 UTC ( [id://185743]=note: print w/replies, xml ) Need Help??


in reply to title/artist info

You can also use tagged.

Here a simple mp3 command line renamer that use File::Find to traverse the given directory structure:
use strict; use File::Find; use MP3::Tag; my $dir=$ARGV[0]; die "use mp3ren.pl directory_name" if (!$dir); find (\&wanted, "$dir"); sub wanted { if (&match("$File::Find::name")) { &rename_MP3($File::Find::name); } } sub match { my $filename=$_[0]; if (-d $filename) { return 0; } my $mp3 = MP3::Tag->new($filename); if (defined $mp3) { $mp3->get_tags; if (exists $mp3->{ID3v1}) { return 1; } else { print "$filename is not mp3 or no ID3v1 tag\n"; return 0; } } } sub rename_MP3 { my $fullname_mp3=$_[0]; my $mp3 = MP3::Tag->new($fullname_mp3); my $new_mp3_name; $mp3->get_tags; my $song=$mp3->{ID3v1}->song; my $artist=$mp3->{ID3v1}->artist; if ($artist && $song) { $new_mp3_name="$artist--$song"; } elsif ($song) { $new_mp3_name="$song"; } elsif ($artist) { $new_mp3_name="$artist--untitled"; } else { $new_mp3_name=""; } if ($new_mp3_name) { $new_mp3_name=~s#[\\|\?|\*|\||\:|"|<|>|/]+##g; $new_mp3_name.=".mp3"; $new_mp3_name="$File::Find::dir/$new_mp3_name"; if ($fullname_mp3 eq $new_mp3_name) { print "Error renaming $fullname_mp3 to $new_mp3_name: same nam +e\n" } elsif (!rename("$fullname_mp3","$new_mp3_name")) { print "Error renaming $fullname_mp3 to $new_mp3_name: $!\n" } else { print "Renamed $fullname_mp3 to $new_mp3_name\n" } } else { print "Error renaming $fullname_mp3: no ID3v1 tag\n" } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://185743]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found