tagged
view release on metacpan or search on metacpan
TAG/ID3v1.pm view on Meta::CPAN
package MP3::TAG::ID3v1;
# reads ID3v1 and ID3v1.1 mp3-tags
# writes ID3v1.1 mp3-tags
use strict;
use vars qw /@mp3_genres @winamp_genres $AUTOLOAD %ok_length/;
# allowed fields in ID3v1.1 and max length of this fields (expect for track and genre which are coded later)
%ok_length = (song => 30, artist => 30, album => 30, comment => 28, track => 3, genre => 30, year=>4, genreID=>1);
=pod
=head1 NAME
MP3::TAG::ID3v1 - Perl extension for reading / writing ID3v1 tags of mp3-files
=head1 SYNOPSIS
MP3::TAG::ID3v2 is designed to be called from the MP3::Tag module.
It then returns a ID3v2-tag-object, which can be used in a users
program.
use MP3::TAG::ID3v1;
$id3v1 = MP3::TAG::ID3v1->new($mp3obj);
C<$mp3obj> is a object from MP3::Tag. See according documentation.
C<$tag> is undef when no tag is found in the C<$mp3obj>.
* Reading the tag
print " Song: " .$id3v1->song . "\n";
print " Artist: " .$id3v1->artist . "\n";
print " Album: " .$id3v1->album . "\n";
print "Comment: " .$id3v1->comment . "\n";
print " Year: " .$id3v1->year . "\n";
print " Genre: " .$id3v1->genre . "\n";
print " Track: " .$id3v1->track . "\n";
@tagdata = $mp3->all();
foreach (@tagdata) {
print $_;
}
* Changing / Writing the tag
$id3v1->comment("This is only a Test Tag");
$id3v1->song("testing");
$id3v1->artist("Artest");
$id3v1->album("Test it");
$id3v1->year("1965");
$id3v1->track("5");
$id3v1->genre("Blues");
# or at once
$id3v1->all("song title","artist","album","1900","comment",10,"Ska");#
$id3v1->writeTag;
=head1 AUTHOR
Thomas Geffert, thg@users.sourceforge.net
=head1 DESCRIPTION
=item new()
$id3v1 = MP3::TAG::ID3v1->new($mp3obj[, $create]);
Generally called from MP3::TAG, because a $mp3obj is needed.
If $create is true, a new tag is created. Otherwise undef is
returned, if now ID3v1 tag is found in the $mp3obj.
=cut
# create a ID3v1 object
sub new {
my ($class, $mp3obj, $create) = @_;
my $self={mp3=>$mp3obj};
my $buffer;
if (defined $create && $create) {
$self->{new} = 1;
} else {
$mp3obj->seek(-128,2);
$mp3obj->read(\$buffer, 128);
}
if ($create || substr ($buffer,0,3) eq "TAG") {
bless $self, $class;
TAG/ID3v1.pm view on Meta::CPAN
sub id2genre {
my $id=shift;
return "" unless defined $id && $id<$#winamp_genres;
return $winamp_genres[$id];
}
# convert genre name to one byte id
sub genre2id {
my $genre = shift;
my $i=0;
foreach (@winamp_genres) {
if (uc $genre eq uc $_) {
return $i;
}
$i++,
}
return 255;
}
# nothing to do for destroy
sub DESTROY {
}
1;
######## define all the genres
BEGIN { @mp3_genres = ( 'Blues', 'Classic Rock', 'Country', 'Dance',
'Disco', 'Funk', 'Grunge', 'Hip-Hop', 'Jazz', 'Metal', 'New Age',
'Oldies', 'Other', 'Pop', 'R&B', 'Rap', 'Reggae', 'Rock', 'Techno',
'Industrial', 'Alternative', 'Ska', 'Death Metal', 'Pranks',
'Soundtrack', 'Euro-Techno', 'Ambient', 'Trip-Hop', 'Vocal',
'Jazz+Funk', 'Fusion', 'Trance', 'Classical', 'Instrumental', 'Acid',
'House', 'Game', 'Sound Clip', 'Gospel', 'Noise', 'AlternRock',
'Bass', 'Soul', 'Punk', 'Space', 'Meditative', 'Instrumental Pop',
'Instrumental Rock', 'Ethnic', 'Gothic', 'Darkwave',
'Techno-Industrial', 'Electronic', 'Pop-Folk', 'Eurodance', 'Dream',
'Southern Rock', 'Comedy', 'Cult', 'Gangsta', 'Top 40',
'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American', 'Cabaret', 'New Wave',
'Psychadelic', 'Rave', 'Showtunes', 'Trailer', 'Lo-Fi', 'Tribal',
'Acid Punk', 'Acid Jazz', 'Polka', 'Retro', 'Musical', 'Rock & Roll',
'Hard Rock', );
@winamp_genres = ( @mp3_genres, 'Folk', 'Folk-Rock',
'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival',
'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock',
'Progressive Rock', 'Psychedelic Rock', 'Symphonic Rock',
'Slow Rock', 'Big Band', 'Chorus', 'Easy Listening',
'Acoustic', 'Humour', 'Speech', 'Chanson', 'Opera',
'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus',
'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba',
'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul',
'Freestyle', 'Duet', 'Punk Rock', 'Drum Solo', 'Acapella',
'Euro-House', 'Dance Hall', );
}
=pod
=head1 SEE ALSO
MP3::Tag, MP3::TAG::ID3v2
ID3v1 standard - http://www.id3.org
=cut
( run in 0.675 second using v1.01-cache-2.11-cpan-f52f0507bed )