Hello, this is a Perl script I made to make burning mp3-cd's for my mp3-cd player easier. What I did here was make a script that renames any "live" file of an mp3 existing to mp3file(1).mp3. (All my bands are in different folders in my root music directory, D:/Music. ie: D:/Music/Bandname/Album.) THis is my script, and I want to know if it works and what I can do to make it better: It uses the MP3::ID3v1Tag module, as you can tell. (The module itself generates many warnings;)
#!/usr/bin/perl -w
use strict;
use mp3::ID3v1Tag;
sub Renamer {
foreach (@_) {
my($artist, $title) = (split '-');
($artist, $title) = &splitter($artist, $title);
rename "$_", "$artist - ${title}(1).mp3" or die "cannot rename
+ to $_ to ${title}.mp3: $!";
}
print "finished Renaming.\n";
}
sub Tagger {
foreach (@_) {
my($artist, $title) = (split '-');
($artist, $title) = &splitter($artist, $title)
my $mp3_file = new MP3::ID3v1Tag($_);
$mp3_file->set_title($title) or die "cannot set title: $!";
$mp3_file->set_artist($artist) or die "cannot set title: $!";
$mp3_file->save() or die "Cannot save changes: $!";
}
print "finished ID3 Tagging.\n";
}
sub splitter {
substr($_[0], -1, 1, ''); print "\$_[0] = ${_[0]}END\n";
substr($_[1], 0,1, ''); print "\$_[1] = BEGIN$_[1]\n";
substr($_[1], -4, 4, '') if substr($_[1], -4, 4) eq '.mp3';
return ($_[0], $_[1]);
}
print "MASS ID3 Tagger and Renamer by Incst. Input a directory or typ
+e exit to exit.\n";
while (1) {
chomp(my $dir = <STDIN>);
if ($dir eq exit) { last; }
else { chdir $dir or die "Cannot change to specified directory: $!
+";
my @MP3_files = <*.mp3>;
&Tagger(@MP3_files);
&Renamer(@MP3_files);
}
Thats the Perl script. Please reply asap.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.