#!/usr/bin/perl print "Enter the <dir> where the mp3's are found: "; chomp ($dir = <stdin>); chdir($dir) or die "Canot change $dir :$!\n"; opendir(DIR, $dir) or die "Cannot open $dir:$!\n"; @songs = readdir(DIR); closedir(DIR); @songs=grep(/(.mp3)|(.MP3)|(.mP3)|(.Mp3)/,@songs); foreach(@songs) { @id = id3check($_); if($id[0] && $id[1]) { rename $_,"$id[0] - $id[1].mp3"; print "$id[0] - $id[1].mp3\n"; } elsif($_ =~ m/(\s*[^-]*)-\s*([^.]*).mp3/i) { my @id; $id[0] = $1; $id[1] = $2; s/\s*$|{|}//g for ($id[0], $id[1]); rename $_,"$id[0] - $id[1].mp3"; print "$id[0] - $id[1]\n"; } else { print "Could not rename $_\n"; } } sub id3check { if (open(FILE, '+<' . $_[0])) { my @id; binmode FILE; seek FILE,-128,2; read FILE,$tag,3; if($tag eq "TAG") { read FILE,$id[0],30; read FILE,$id[1],30; s/\s*$|{|}//g for ($id[0],$id[1]); return @id; } } }
In reply to Re: Re: Mp3 Renamer
by Anonymous Monk
in thread Mp3 Renamer
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |