InfoSection: User Contributed Perl Documentation (3)Updated: 2003-03-02 |
InfoSection: User Contributed Perl Documentation (3)Updated: 2003-03-02 |
#!perl -w
use MP3::Info;
my $file = 'Pearls_Before_Swine.mp3';
set_mp3tag($file, 'Pearls Before Swine', q"77's",
'Sticks and Stones', '1990',
q"(c) 1990 77's LTD.", 'rock & roll');
my $tag = get_mp3tag($file) or die "No TAG info";
$tag->{GENRE} = 'rock';
set_mp3tag($file, $tag);
my $info = get_mp3info($file);
printf "$file length is %d:%d\n", $info->{MM}, $info->{SS};
my $mp3 = new MP3::Info $file;
$mp3->title('Perls Before Swine');
printf "$file length is %s, title is %s\n",
$mp3->time, $mp3->title;
Passing a value to one of the methods will set the value for that tag in the MP3 file, if applicable.
Will only be able to it on if Unicode::String is available. ID3v2 tags will be converted to UTF-8 according to the encoding specified in each tag; ID3v1 tags will be assumed Latin-1 and converted to UTF-8.
Function returns status (TRUE/FALSE). If no argument is supplied, or an unaccepted argument is supplied, function merely returns status.
This function is not exported by default, but may be exported with the ":utf8" or ":all" export tag.
You can import the data structures with one of:
use MP3::Info qw(:genres);
use MP3::Info qw(:DEFAULT :genres);
use MP3::Info qw(:all);
For ID3v1, removes last 128 bytes from file if those last 128 bytes begin with the text 'TAG'. File will be 128 bytes shorter.
For ID3v2, removes ID3v2 tag. Because an ID3v2 tag is at the beginning of the file, we rewrite the file after removing the tag data. The buffer for rewriting the file is 4MB. BUFFER (in bytes) ca change the buffer size.
Returns the number of bytes removed, or -1 if no tag removed, or undef if there is an error.
Fields are TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE. All fields have a 30-byte limit, except for YEAR, which has a four-byte limit, and GENRE, which is one byte in the file. The GENRE passed in the function is a case-insensitive text string representing a genre found in @mp3_genres.
Will accept either a list of values, or a hashref of the type returned by "get_mp3tag".
If TRACKNUM is present (for ID3v1.1), then the COMMENT field can only be 28 bytes.
ID3v2 support may come eventually. Note that if you set a tag on a file with ID3v2, the set tag will be for ID3v1[.1] only, and if you call "get_mp3_tag" on the file, it will show you the (unchanged) ID3v2 tags, unless you specify ID3v1.
If VERSION is 1, the information is taken from the ID3v1 tag (if present). If VERSION is 2, the information is taken from the ID3v2 tag (if present). If VERSION is not supplied, or is false, the ID3v1 tag is read if present, and then, if present, the ID3v2 tag information will override any existing ID3v1 tag info.
If RAW_V2 is 1, the raw ID3v2 tag data is returned, without any manipulation of text encoding. The key name is the same as the frame ID (ID to name mappings are in the global %v2_tag_names).
If RAW_V2 is 2, the ID3v2 tag data is returned, manipulating for Unicode if necessary, etc. It also takes multiple values for a given key (such as comments) and puts them in an arrayref.
If the ID3v2 version is older than ID3v2.2.0 or newer than ID3v2.4.0, it will not be read.
Strings returned will be in Latin-1, unless UTF-8 is specified (use_mp3_utf8), (unless RAW_V2 is 1).
Also returns a TAGVERSION key, containing the ID3 version used for the returned data (if TAGVERSION argument is 0, may contain two versions).
VERSION MPEG audio version (1, 2, 2.5)
LAYER MPEG layer description (1, 2, 3)
STEREO boolean for audio is in stereo
VBR boolean for variable bitrate
BITRATE bitrate in kbps (average for VBR files)
FREQUENCY frequency in kHz
SIZE bytes in audio stream
SECS total seconds
MM minutes
SS leftover seconds
MS leftover milliseconds
TIME time in MM:SS
COPYRIGHT boolean for audio is copyrighted
PADDING boolean for MP3 frames are padded
MODE channel mode (0 = stereo, 1 = joint stereo,
2 = dual channel, 3 = single channel)
FRAMES approximate number of frames
FRAME_LENGTH approximate length of a frame
VBR_SCALE VBR scale from VBR header
On error, returns nothing and sets $@.
If I download the file, after debugging the problem I will not keep the MP3 file if it is not legal for me to have it. Just let me know if it is legal for me to keep it or not.
ID3v2 writing is coming soon.
Copyright (c) 1998-2003 Chris Nandor. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License, distributed with Perl.
http://projects.pudge.net/
http://www.zevils.com/linux/mp3tools/
http://www.dv.co.yu/mpgscript/mpgtools.htm
http://www.dv.co.yu/mpgscript/mpeghdr.htm
http://www.dtek.chalmers.se/~d2linjo/mp3/mp3tool.html
http://www.id3.org/
http://www.xingtech.com/support/partner_developer/mp3/vbr_sdk/
http://rupert.informatik.uni-stuttgart.de/~mutschml/MP3ext/
http://www.xmms.org/