ID3 Tags written by Perl can not be modified by any other ID3 editor

A

ads

I am trying to write a script that seems to be working fine, except
iTunes (or WinAmp) can't modify the ID3 tag, I am running the script on
Linux and am sure there is something wrong in how I am writing the
file. The wierd part is both applications appear to be reading the file
correctly, but not able to modify or convert the tags. Can anyone see
anything stupid I am doing? I think there is a method to close or
complete things that I am not calling.

inputs are mp3 files in the form:
Chapter 1.mp3
Chapter 2.mp3
....

Thanks,

Tim

#!/usr/bin/perl

use MP3::Tag;

$mydir = $ARGV[0];
print "Using the directory $mydir\n";
print "please enter the author's name: ";
$auth_name = <STDIN>;
print "please enter the pub year: ";
$intYr = <STDIN>;
print "please enter the title: ";
$title = <STDIN>;

while ($filename = <$mydir/*.mp3> ) {
$filename =~ /\d+/;
$number = $&;
# need the file name without the directory
$filename =~ /\//;
$filename = $';

print "Processing $filename with number $number\n";

# create new MP3-Tag object
$mp3 = MP3::Tag->new($filename);
$mp3->get_tags();

# if an existing tag exists, delete it
if (exists $mp3->{ID3v2}) {
$id3v2 = $mp3->{ID3v2};
$id3v2->remove_tag();
}
# create new tag for a fresh start
$id3v2 = $mp3->new_tag("ID3v2");

# now assign values
# $id3v2->add_frame("TPOS", "$number\/25");
$id3v2->add_frame("TPE1", $auth_name);
$id3v2->add_frame("TYER", $intYr);
# $id3v2->add_frame("TCP", "$number");
$id3v2->add_frame("TALB", $title);
$id3v2->add_frame("TIT2", "$filename");
$id3v2->add_frame("TCON", "Books & Spoken");
$id3v2->write_tag();

# clean up
$mp3->close();
}
 
T

terry_lee_2

From: "" <Yoda>
Newsgroups: comp.lang.perl.misc
Subject: Re: ID3 Tags written by Perl can not be modified by any other
ID3 editor
Date: Mon, 19 Dec 2005 11:21:10 -0800

u might want to look at the file on the windows side using a hex
viewer.
unix/linux terminates lines with a LF only.
windows expects a line termination of CR/LF.
 
A

ads

Terry,

Thanks -- I am running the Perl on Linux then looking at the file from
the win32 computer. I don't see how line termination would effect the
ID3 tag input.

thanks for any info . . .

Tim
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to

I am trying to write a script that seems to be working fine, except
iTunes (or WinAmp) can't modify the ID3 tag, I am running the script on
Linux and am sure there is something wrong in how I am writing the
file. The wierd part is both applications appear to be reading the file
correctly, but not able to modify or convert the tags. Can anyone see
anything stupid I am doing? I think there is a method to close or
complete things that I am not calling.

Looks like you are doing

mp3info2 -u -a "Au" -y "Y" -t "tit" foo.mp3

The script should be installed with the newest version.
use MP3::Tag;

What version?
while ($filename = <$mydir/*.mp3> ) {
$filename =~ /\d+/;
$number = $&;
# need the file name without the directory
$filename =~ /\//;
$filename = $';

Usually people try avoiding $& and $'...
print "Processing $filename with number $number\n";

# create new MP3-Tag object
$mp3 = MP3::Tag->new($filename);
$mp3->get_tags();

# if an existing tag exists, delete it
if (exists $mp3->{ID3v2}) {
$id3v2 = $mp3->{ID3v2};
$id3v2->remove_tag();
}
# create new tag for a fresh start
$id3v2 = $mp3->new_tag("ID3v2");

# now assign values
# $id3v2->add_frame("TPOS", "$number\/25");
$id3v2->add_frame("TPE1", $auth_name);
$id3v2->add_frame("TYER", $intYr);
# $id3v2->add_frame("TCP", "$number");
$id3v2->add_frame("TALB", $title);
$id3v2->add_frame("TIT2", "$filename");
$id3v2->add_frame("TCON", "Books & Spoken");
$id3v2->write_tag();

# clean up
$mp3->close();
}

I think
my $t = new MP3::Tag $filename;
$t->author($auth_name);
$t->year($intYr);
...
$t->set_id3v2_frame('TCON', ...);
$t->update_tags()

should be enough. (This will create id3v1 tag as well.)

Hope this helps,
Ilya
 
A

ads

Wow -- cool. I knew there was a way to do that -- maybe my newline is
what is giving me trouble.

thanks -- i'll give it a try . . .

tim
 
A

ads

No -- i made changes per both of your suggestions, but it still doesn't
work.

any other thoughts?

tim

------------------------------------
#!/usr/bin/perl

# use module
use MP3::Tag;

$mydir = $ARGV[0];
print "Using the directory $mydir\n";
print "please enter the author's name: ";
$auth_name = <STDIN>;
print "please enter the pub year: ";
$intYr = <STDIN>;
print "please enter the title: ";
$title = <STDIN>;

$auth_name = chomp($auth_name);
$intYr = chomp($intYr);
$title = chomp($title);


while ($filename = <$mydir/*.mp3> ) {
($number) = $filename =~ /\d+/;
# need the file name without the directory
$filename =~ /\//;
$filename = $';

print "Processing $filename with number $number\n";

# create new MP3-Tag object
my $t = new MP3::Tag $filename;

$t->author($auth_name);
$t->year($intYr);
$t->title($title);

# now assign values
$t->set_id3v2_frame("TPOS", "$number/25");
$t->set_id3v2_frame("TPE1", $auth_name);
$t->set_id3v2_frame("TYER", $intYr);
$t->set_id3v2_frame("TCP", $number);
$t->set_id3v2_frame("TALB", $title);
$t->set_id3v2_frame("TIT2", $filename);
$t->set_id3v2_frame("TCON", "Books & Spoken");
$t->write_tag();

# clean up
$t->close();
}
 
A

A. Sinan Unur

(e-mail address removed) wrote in @g47g2000cwa.googlegroups.com:
No -- i made changes per both of your suggestions,

Whose suggestions? Please quote some context.
but it still doesn't work.

What do you mean "doesn't work"?
$auth_name = chomp($auth_name);
$intYr = chomp($intYr);
$title = chomp($title);

Have you considered reading

perldoc -f chomp

Sinan
 
T

Tad McClellan



No to what?

i made changes per both of your suggestions,


Whose suggestions?

but it still doesn't
work.


That is an information-free symptom.

What does "doesn't work" mean when you say it?

any other thoughts?


Please quote some context in followups like everybody else does.

Soon.

$auth_name = chomp($auth_name);


Read the docs for chomp, that is not how you use it:

perldoc -f chomp

# need the file name without the directory


perldoc File::Basename

(again)
 
T

terry_lee_2

Tim,

I can appreciate your doubts with line terminations causing a problem
with itunes.

Bear with me. Download the editor "ConTEXT" from http://www.context.cx/


Open the MP3 Tag file using the editor "ConTEXT".

Select "TOOLS" then the last item in the drop down, "Convert Text
To..." within the drop down the selection UNIX (LF only) will be
checked. If not, then you were right in ignoring me, and I apologize.
Otherwise select DOS(CRLF) and then save the file.

Now try using it with itunes or whatever. It should be readable by
win32 applications.

"ConTEXT" also has a highlighter feature that enhances the readabily of
text files for different text files, such as perl, java, korn shell,
etc. You will need to download the additional highlighters you desire.

Enough said, I won't bother you again.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,235
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top