MP3::Tag::File(3pm)

πŸ“¦
version 1.16 Β· 2 versions
  • 1.16 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.13 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

MP3::Tag::File β€” the module that handles reading and writing files for MP3::Tag. It's the little backstage bestie that does the actual file I/O so the main module can be the main character. πŸ‘‘


🌸 SYNOPSIS 🌸

my $mp3 = MP3::Tag->new($filename);

($title, $artist, $no, $album, $year) = $mp3->parse_filename();

also like… go look at MP3::Tag, okay? it's the whole reason this thing exists.


πŸ’… DESCRIPTION πŸ’…

okay so real talk: MP3::Tag::File is designed to be called from the MP3::Tag module. It does not want to be summoned directly by you at 3am, it wants to be summoned by its parent module. It's giving ✨supporting role✨.

What it does offer is the ability to read and write data from files through:

  • read()
  • write()
  • truncate()
  • seek()
  • tell()
  • open()
  • close()

and you can find out which file you're dealing with via the filename() method. so handy bestie, literally. 🫢


πŸŽ€ parse_filename() πŸŽ€

($title, $artist, $no, $album, $year) = $mp3->parse_filename($what, $filename);

parse_filename() tries to extract information about artist, title, track number, album and year from the filename. (And for backward compatibility it may also be called by its deprecated name, read_filename() β€” she's an old nickname, we still answer to it. πŸ™ˆ)

⚠️ bestie this is likely to fail for a lot of filenames. Especially the album β€” it will often be wrongly guessed, because the name of the parent directory is just taken as the album name. Like… it's doing its best with what it's got. 😭

$what and $filename are both optional. $what may be title, track, artist, album or year. If $what is defined, parse_filename() will return only that one element β€” just the lil snack you asked for. πŸ“

If $filename is defined, that filename gets used instead of the real filename that was set by MP3::Tag with MP3::Tag->new($filename). Otherwise the actual filename is used β€” which is subject to the configuration variable decode_encoding_filename. iykyk.

These formats will hopefully be recognized (fingers crossed, manifesting ✨):

  • album name/artist name - song name.mp3
  • album_name/artist_name-song_name.mp3
  • album.name/artist.name_song.name.mp3
  • album name/(artist name) song name.mp3
  • album name/01. artist name - song name.mp3
  • album name/artist name - 01 - song.name.mp3

And one more little rule: if the artist or title ends in (NUMBER) where NUMBER is a 4-digit number, that gets considered the year. periodt. πŸ’€


πŸ¦‹ title() πŸ¦‹

$title = $mp3->title($filename);

Returns the title, guessed from the filename. See also parse_filename(). (For backward compatibility, it can also be called by the deprecated name song() β€” vintage name, still slays.)

$filename is optional and will be used instead of the real filename if it's defined. πŸ’œ


⭐ artist() ⭐

$artist = $mp3->artist($filename);

Returns the artist name, guessed from the filename. See also parse_filename().

$filename is optional and will be used instead of the real filename if it's defined. πŸ’œ


🌈 track() 🌈

$track = $mp3->track($filename);

Returns the track number, guessed from the filename. See also parse_filename().

$filename is optional and will be used instead of the real filename if it's defined. πŸ’œ


🧚 year() 🧚

$year = $mp3->year($filename);

Returns the year, guessed from the filename. See also parse_filename().

$filename is optional and will be used instead of the real filename if it's defined. πŸ’œ


πŸŽ€ album() πŸŽ€

$album = $mp3->album($filename);

Returns the album name, guessed from the filename. See also parse_filename(). The album name is guessed from the parent directory, so it is very likely to fail. not her fault, the filesystem is just like that sometimes. 😭

$filename is optional and will be used instead of the real filename if it's defined. πŸ’œ


🫧 comment() 🫧

$comment = $mp3->comment($filename);   # Always undef

🫧 genre() 🫧

$genre = $mp3->genre($filename);       # Always undef

😭 POD ERRORS 😭

Hey! bestie! The above document had some coding errors, which are explained below, no cap:

Around line 184: =over without closing =back

so the docs themselves got a lil vibe check fail. it's giving unclosed block. πŸ™ˆ


that's the whole page, mwah πŸ’– this was pulled from the perl v5.36.0 docs, dated 2022-12-30 β€” shoutout to that version, she ate. slay, bye! πŸ’…βœ¨