My script is here, and also pasted below:
http://www.biophile.org/songs/Chinese/playit.cgi
===
#!/usr/bin/perl
print "Content-type: text/html\n\n"; use MP3::Tag;
&get_mp3_tag("Chinese3/Ye Lai Xiang.mp3");
&get_mp3_tag("../17 The Lilac and the Apple.mp3");
sub get_mp3_tag { my($file)=@_;
$mp3 = MP3::Tag->new($file); $mp3->get_tags();
if (exists $mp3->{ID3v1}) {
$title=$mp3->{ID3v1}->title;
$artist=$mp3->{ID3v1}->artist;
$mp3->close();
} else {
$title=$sfil; $artist="unknown";
}
print <<"EOP";
<P>
file:$file<BR>
title:$title<BR>
artist:$artist
EOP
}
===
Thanks for any help!
> Can someone help me decode Chinese metadata in mp3 files?
If you want to decode Chinese characters into Perl's native format, you
need to
use Encode 'decode';
> Here are a couple of mp3 files, one with Chinese and one Ebglish
> metadata:
> http://www.biophile.org/songs/Chinese/Chinese3/Ye%20Lai%20Xiang.mp3
I got a response
404 Not Found
The requested URL does not exist.
It seems you need an "mp3" in the address:
http://www.biophile.org/songs/Chinese/Chinese3/mp3/
It's a nice song, although I don't understand a word of it.
> http://www.biophile.org/songs/17%20The%20Lilac%20and%20the%20Apple.mp3
This one downloaded OK.
> My script is here, and also pasted below:
> http://www.biophile.org/songs/Chinese/playit.cgi
I don't see any output.
> ===
> #!/usr/bin/perl
It's better to have
use warnings;
use strict;
at the top of your script.
> print "Content-type: text/html\n\n"; use MP3::Tag;
You may also find
use CGI;
useful.
> &get_mp3_tag("Chinese3/Ye Lai Xiang.mp3");
> &get_mp3_tag("../17 The Lilac and the Apple.mp3");
>
> sub get_mp3_tag { my($file)=@_;
> $mp3 = MP3::Tag->new($file); $mp3->get_tags();
>
> if (exists $mp3->{ID3v1}) {
> $title=$mp3->{ID3v1}->title;
> $artist=$mp3->{ID3v1}->artist;
On the "Totem Movie Player" on Linux the metadata displayed correctly but
I have no idea what encoding they use.
Assuming these are encoded somehow, you would do something like
$artist = decode ('utf8', $artist);
where you need to replace the string 'utf8' with the name of the encoding
which they're in. Is that what you want to do? The problem then is that
you need to print these out.
> $mp3->close();
> } else {
> $title=$sfil; $artist="unknown";
> }
>
> print <<"EOP";
> <P>
> file:$file<BR>
> title:$title<BR>
> artist:$artist
> EOP
>
> }
> ===
You probably should also print out some html tags somewhere like
<html>
<body>
CGI.pm can do all this for you, so I recommend investigating that.
&get_mp3_tag("Chinese3/Ye Lai Xiang.mp3");
&get_mp3_tag("../17 The Lilac and the Apple.mp3");
sub get_mp3_tag { my($file)=@_;
$mp3 = MP3::Tag->new($file); $mp3->get_tags();
if (exists $mp3->{ID3v1}) {
$title=$mp3->{ID3v1}->title;
$artist=$mp3->{ID3v1}->artist;
$mp3->close();
} else {
$title=$sfil; $artist="unknown";
}
$dtit=decode('gb2312-raw',$title);
print <<"EOP";
<P>
file:$file<BR>
title:$title($dtit)<BR>
artist:$artist
EOP
}
===
Perhaps it's just a matter of findng out what the proper decoding is?
BTW, even if you don't understand what she is singing, at least you
should be able to hum along with the "Ye Lai Xiang" refrain.
Peter
<pe...@for-wild.org>], who wrote in article <ed407ec1-08c4-461b...@j33g2000pri.googlegroups.com>:
> sub get_mp3_tag { my($file)=@_;
> $mp3 = MP3::Tag->new($file); $mp3->get_tags();
>
> if (exists $mp3->{ID3v1}) {
> $title=$mp3->{ID3v1}->title;
> $artist=$mp3->{ID3v1}->artist;
> $mp3->close();
> } else {
> $title=$sfil; $artist="unknown";
> }
Why not use the documented
$title=$mp3->title;
$artist=$mp3->artist;
and
$title = $sfil unless defined $title and length $title;
etc;
then play with MP3TAG_DEFAULT_V1_DECODE etc (if you know the stuff
comes from v1)...
Ilya
Yes, the $title=$mp3->title; worked.
The other thing I need to tweek was the charset to have the output
show properly on the web,
I wound up using "Content-type: text/html; charset=utf-8\n\n"
The script is now at:
http://www.biophile.org/songs/Chinese/playme.cgi
Thanks for yout help!
Peter