Info(3pm)

πŸ“¦
version 1.26 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Okay bestie, welcome to the Info(3pm) page πŸ’… β€” this is all about MP3::Info, and its whole job is: Manipulate / fetch info from MP3 audio files. That's it. That's the gig. 🎡


✨ SYNOPSIS ✨

#!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;

🌸 DESCRIPTION 🌸

$mp3 = MP3::Info->new(FILE)

This is the OOP interface to the rest of the module, and she's serving ✨. Every key you can get through get_mp3info and get_mp3tag is also available through the object you get back β€” you can ask in upper case or lower case, no biggie, but heads up: if you ask for the all-caps VERSION, you get the module version, not the MP3 version. Not me mixing those up πŸ™ˆ.

If you pass a value to one of the methods, it sets that value for that tag in the MP3 file β€” but only if applicable. πŸ’«

use_mp3_utf8([STATUS])

Tells MP3::Info whether to return TAG info in UTF-8. TRUE is 1, FALSE is 0. The default is TRUE, if it's available. πŸ¦‹

It can only turn UTF-8 on if Encode is available. ID3v2 tags get converted to UTF-8 according to the encoding specified in each tag; ID3v1 tags get assumed to be Latin-1 and converted to UTF-8. Slay, honestly.

The function returns status (TRUE/FALSE). If you give it no argument, or an argument it doesn't accept, it just returns status and minds its business. πŸ’…

This function is not exported by default, but it can be exported with the :utf8 or :all export tag. iykyk.

use_winamp_genres()

Puts WinAmp genres into @mp3_genres and %mp3_genres β€” that's 68 additional genres on top of the default list of 80. She's a separate function because these genres are non-standard, but they're included anyway because they're widely used. πŸ‘‘

You can import the data structures with one of these, bestie:

use MP3::Info qw(:genres);
use MP3::Info qw(:DEFAULT :genres);
use MP3::Info qw(:all);

remove_mp3tag (FILE [, VERSION, BUFFER])

Can remove ID3v1 or ID3v2 tags. VERSION should be 1 for ID3v1 (that's the default), 2 for ID3v2, and "ALL" for both. 🧹

  • For ID3v1: it removes the last 128 bytes from the file, but only if those last 128 bytes begin with the text 'TAG'. The file ends up 128 bytes shorter.
  • For ID3v2: it removes the ID3v2 tag. Because an ID3v2 tag sits at the beginning of the file, the file gets rewritten after the tag data is removed. The buffer for rewriting the file is 4MB. BUFFER (in bytes) can change the buffer size.

Returns the number of bytes removed, or -1 if no tag was removed, or undef if there's an error. 😭

set_mp3tag (FILE, TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE [, TRACKNUM])

set_mp3tag (FILE, $HASHREF)

Adds/changes tag information in an MP3 audio file. ⚠️ Will clobber any existing information in the file. Like, gone-gone. Be careful, bestie.

Fields are TITLE, ARTIST, ALBUM, YEAR, COMMENT, GENRE. Every field has a 30-byte limit, except YEAR, which has a four-byte limit, and GENRE, which is one byte in the file. The GENRE you pass in is a case-insensitive text string representing a genre found in @mp3_genres.

It'll 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_mp3tag on the file, it will show you the (unchanged) ID3v2 tags β€” unless you specify ID3v1.

get_mp3tag (FILE [, VERSION, RAW_V2, APE2])

Returns a hash reference containing tag information in the MP3 file. The keys returned are the same as the ones supplied for set_mp3tag, except when RAW_V2 is set. πŸŽ€

  • If VERSION is 1, the info comes from the ID3v1 tag (if present).
  • If VERSION is 2, the info comes from the ID3v2 tag (if present).
  • If VERSION isn't supplied, or is false, the ID3v1 tag is read if present, and then, if present, the ID3v2 tag information overrides any existing ID3v1 tag info.

If RAW_V2 is 1, the raw ID3v2 tag data is returned, with no manipulation of text encoding whatsoever. The key name is the same as the frame ID β€” the ID-to-name mappings live 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 APE is 1, an APE tag will be located before all other tags.

If the ID3v2 version is older than ID3v2.2.0 or newer than ID3v2.4.0, it will not be read. Periodt.

Strings returned will be in Latin-1, unless UTF-8 is specified (use_mp3_utf8) β€” (unless RAW_V2 is 1). 🌈

It also returns a TAGVERSION key, containing the ID3 version used for the returned data (if the TAGVERSION argument is 0, it may contain two versions).

get_mp3info (FILE)

Returns a hash reference containing file information for the MP3 file. This data cannot be changed β€” it is what it is. ✨ Returned data:

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
OFFSET          bytes offset that stream begins

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, it returns nothing and sets $@. 😭


🩷 TROUBLESHOOTING 🩷

If you find a bug, please send a patch (check the project page in "SEE ALSO"). If you cannot figure out why it doesn't work for you, put the MP3 file somewhere I can get it (preferably via FTP, or HTTP, or .Mac iDisk) and send mail about where I can grab the file, along with a detailed description of the problem. 🫢

If I download the file: after debugging, I will not keep the MP3 file if it is not legal for me to have it. Just let me know whether it's legal for me to keep it or not. πŸ’œ


πŸ‘‘ TODO πŸ‘‘

ID3v2 Support

Still need to do more for reading tags, like using Compress::Zlib to decompress compressed tags. But until this gets seen in use more, I won't bother. If something doesn't work properly with reading, follow the troubleshooting instructions above. πŸ™ˆ

ID3v2 writing is coming soon. ⏳

Get data from scalar

Instead of passing a file spec or filehandle, pass the data itself. Would take some work, converting the seeks, etc.

Padding bit ?

Do something with padding bit.

Test suite

The test suite could use a bit of an overhaul and update. Patches very welcome. πŸ’–

  • Revamp getset.t. Test all the various get_mp3tag args.
  • Test Unicode.
  • Test OOP API.
  • Test error handling, check more for missing files, bad MP3s, etc.

Other VBR

Right now, only Xing VBR is supported. πŸ’€


🌟 THANKS 🌟

Edward Allen, Vittorio Bertola, Michael Blakeley, Per Bolmstedt, Tony Bowden, Tom Brown, Sergio Camarena, Chris Dawson, Kevin Deane-Freeman, Anthony DiSante, Luke Drumm, Kyle Farrell, Jeffrey Friedl, brian d foy, Ben Gertzfield, Brian Goodwin, Andy Grundman, Todd Hanneken, Todd Harris, Woodrow Hill, Kee Hinckley, Roman Hodek, Ilya Konstantinov, Peter Kovacs, Johann Lindvall, Alex Marandon, Peter Marschall, michael, Trond Michelsen, Dave O'Neill, Christoph Oberauer, Jake Palmer, Andrew Phillips, David Reuteler, John Ruttenberg, Matthew Sachs, scfc_de, Hermann Schwaerzler, Chris Sidi, Roland Steinbach, Brian S. Stephan, Stuart, Dan Sully, Jeffery Sumler, Predrag Supurovic, Bogdan Surdu, Pierre-Yves Thoulon, tim, Pass F. B. Travis, Tobias Wagener, Ronan Waide, Andy Waite, Ken Williams, Ben Winslow, Meng Weng Wong, Justin Fletcher. 🫢✨


πŸŽ€ CURRENT AUTHOR πŸŽ€

Dan Sully <daniel | at | cpan.org> & Logitech.

πŸ¦‹ AUTHOR EMERITUS πŸ¦‹

Chris Nandor <pudge@pobox.com>, http://pudge.net/


Copyright (c) 2006-2008 Dan Sully & Logitech. All rights reserved.

Copyright (c) 1998-2005 Chris Nandor. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


🌈 SEE ALSO 🌈


And that's the whole page, bestie πŸ’– β€” brought to you by perl v5.32.1, dated 2021-12-22. Go tag some MP3s, you absolute icon. πŸ‘‘πŸŽ€

πŸ“¦ where this page comes from