Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Perl Programming Media Music

Cultured Perl: Fun with MP3 and Perl, Part 1 232

Ted writes "Every self-respecting computer and music fan needs to be able to manipulate MP3s -- the defacto standard for recreational digital music use. In this article, I'll look at ways to manage and manipulate MP3s (searching, tagging, renaming, commenting, etc.) using the autotag.pl application. I'll also take you through the application, illustrating how CPAN modules enable the application."
This discussion has been archived. No new comments can be posted.

Cultured Perl: Fun with MP3 and Perl, Part 1

Comments Filter:
  • by rf0 ( 159958 ) * <rghf@fsck.me.uk> on Tuesday December 16, 2003 @12:33PM (#7735660) Homepage
    I'm going to say "Where the ogg version?" :)

    Rus
    • I'm going to say "Where the ogg version?" :)

      That's the beauty of open source. You have the perl script, look at the OGG documentation and write it yourself.
    • here [cpan.org] you go:
      An object-oriented interface to Ogg Vorbis information and comment fields, implemented entirely in Perl.
    • just search [cpan.org] for some ogg modules on cpan, and put something together :)
    • by Josh Coalson ( 538042 ) on Tuesday December 16, 2003 @12:41PM (#7735745) Homepage
      I'm going to say "Where the ogg version?"

      Right here. [cpan.org] Or here for FLAC [cpan.org].

      Josh

    • by bwhaley ( 410361 ) <bwhaley@g m a i l . c om> on Tuesday December 16, 2003 @01:11PM (#7736011)
      I'm going to say "Where the ogg version?" :)

      At the risk of wasting some karma...

      I'm sick of hearing about Ogg. Great, it's free as in beer and freedom. I'm pro freedom. But seriously, it's not going to catch on. mp3 is here to stay my friends, and while ogg may be a technically superior format, the rest of the world is not going to convert the mp3 collection to ogg's. It's just not going to happen. And if nobody converts their files to ogg's, why would manufacturers waste development time and costs putting ogg support into their products?

      Maybe I'm being cynical but I think it would take a miracle at this point.
      • by Minna Kirai ( 624281 ) on Tuesday December 16, 2003 @01:28PM (#7736196)
        And if nobody converts their files to ogg's, why would manufacturers waste development time and costs putting ogg support into their products?

        So they can have a superior format without the risk of Apple or Microsoft quadrupling the license fees 9 months down the line.

        Actually, because Microsoft is pushing their own audio format, manufacturers will have a low-cost chance to push Ogg. They're going to have to expand the devices to recognize non-mp3 files anyhow... why not throw in the free integerized Ogg code while they're at it?
        • And if nobody converts their files to ogg's, why would manufacturers waste development time and costs putting ogg support into their products? So they can have a superior format without the risk of Apple or Microsoft quadrupling the license fees 9 months down the line. Actually, because Microsoft is pushing their own audio format, manufacturers will have a low-cost chance to push Ogg. They're going to have to expand the devices to recognize non-mp3 files anyhow... why not throw in the free integerized Og

        • Man, I sure hope that Apple and Microsoft don't quadruple the $0 license fee for a decoder that they don't own rights to anyway. I hope they don't quadruple the licenes fee for lame, either, cause 4 times $0 will be *way* more than people would normally be willing to pay.

          Now the Fraunhofer people, I'd worry a little bit about. However, given that the compression scheme has been pretty widley disseminated with no attempt to collect license fees since their initial little fiasco, that's not much of a worry
      • About 4 years ago I bought an mp3 player. People told me mp3 would never catch on. "Oh it's too difficult" "but it doesn't sound as good as CD". Then I showed somebody else "wow - no moving parts, that's cool". Guess who was on the right track and who was wrong ?
        • Re:I remember (Score:3, Insightful)

          by (trb001) ( 224998 )
          You had 'discovered' a new way to store music...that being a small in size, digital way to store music. Prior to mp3, there was no way to store music digitally without taking up a lot of honking space. Remember, this is also before hard drives were sickly big (in 1996 when I started ripping to mp3, I had a 6 gig hard drive...and that was large).

          Ogg is *nothing new*. It's different, not *new*. Until mp3 licensing fees start affecting Joe User, he's not going to care about different formats. MP3 is main
      • I think you have a good point. But I also think this is somewhat analagous to VHS vs. DVD. It might take a while, but ppl will start to use it, and companies will start to support it. The geek segment is the biggest market segment for most of the high end mp3 stuff, if they hear ogg being talked about, and it's not too hard to do, they'll include it. Some manufacturers already do. I do agree it gets old to keep hearing ppl moan about it though.
        • Ah, but is that the correct analogy or is it more like VHS vs. Beta? Beta is a clearly superior videotape format, yet VHS had the manufacturer's support (you would think Sony would have remembered that when they came out with the memory stick). Try to find a Betamax VCR these days - good luck. I don't pretend to know which audio format will "win", but don't underestimate the impact of manufacturer's support and don't forget all the hidden business agendas present in decisions to support a given format. It's
        • I also think this is somewhat analagous to VHS vs. DVD. It might take a while, but ppl will start to use it, and companies will start to support it.

          Hmmm... perhaps I'm remembering things incorrectly, but DVD uptake was actually quite rapid. Maybe three or so years from geeky high-end to mass mass mass consumption? I seem to recall its adoption rate being something to crow about among manufacturers.

          Ogg seems to me more like a LaserDisc than a DVD if you really want to stretch an analogy. Geeky, offe

      • Errr. OGG support is like really tiny, and could EASILY fit into space left on a ROM etc... I'm sorry, but there is no excuse not to support all the major codecs on a player (MP3/OGG/WMA/WAV) as the data they take up is minimal. Who fills up a ROM chip these days anyway? They're ridiculously cheap, and they often have loads of space...
      • the rest of the world is not going to convert the mp3 collection to ogg's

        I certainly hope not. Once you go lossy, you're stuck. Re-encoding with lossy compression would be (in a metaphorical sense) like replacing your 2nd generation analog tapes with 3rd generation copies: pointless.

        If you have a collection of mp3's which you don't have the original cd-quality audio for, the best thing you can do is leave it alone.

      • Ogg files do not decompress as simply as MP3s. More processing activity == more power used == less battery life. So Ogg is dead in the portable market.
        • Ogg files do not decompress as simply as MP3s. More processing activity == more power used == less battery life. So Ogg is dead in the portable market.


          The excess power taken up by that is exceedingly minimal. Absolutely nothing compared to the power going to your headphones, for example. In my experience, OggDrop, the encoder I use, encodes much faster than Lame. If this power consumption was such a problem, then why do you think so many mp3 player manufacturers have Ogg support?

          People here seem to hav
      • I use eMule quite a bit. There is a huge, huge amount of Ogg music and RAR-archived albums on the eDonkey network. It's already very well established. In addition to that, a huge number of video files, close to 50%, on that network have Ogg audio. Everyone who at all cares about digital music has the ogg codec. Even electronics companies are taking notice. Many new MP3 players have Ogg support.

        Ogg is big now. It's not just some obscure codec.
      • and while ogg may be a technically superior format, the rest of the world is not going to convert the mp3 collection to ogg's. It's just not going to happen.

        No, they're not going to convert their mp3 collection. But if they're like me, they may start ripping new cds using ogg instead of mp3. Personally, I find the difference in sound quality between the two formats to be very noticable, especially with classical music rips (to the extent that before oggs came along I refused to rip any classical cds to
      • the rest of the world is not going to convert the mp3 collection to ogg's.

        Good, and I don't ever want to download an OGG file that was converted from an MP3. No point in making a high-quality OGG file from an MP3 file that has (in my opinion) worse quality. All my OGG files are ripped straight from the CD at a nice high (192 kbit nominal) bitrate.
  • by tcopeland ( 32225 ) * <tom AT thomasleecopeland DOT com> on Tuesday December 16, 2003 @12:35PM (#7735682) Homepage
    ...written in Ruby, can be found right here [rubyforge.org]. From the project page:

    mp3taglib is a id3v1/id3v2 mp3 tagging library for ruby, based on id3lib. At
    this early stage it already supports most of the fields of id3v2 tags. Mp3
    encoding informations can also be retrieved.
    • On the Windows side of things, I favor Renamer [albert.nu] for organizing my MP3s. I've used it since version 3.5 and it's a godsend for large collections. You can really make file listings look professional and easy to read in just a few minutes if you set it up right.
  • Nice to know... (Score:5, Informative)

    by jargoone ( 166102 ) on Tuesday December 16, 2003 @12:36PM (#7735697)
    It's nice to know you can do this, and I've used the modules referenced for custom fixes. But don't reinvent the wheel if you don't have to: EasyTag [sourceforge.net] probably does 90% of what you would write something custom for.
    • Re:Nice to know... (Score:5, Insightful)

      by rf0 ( 159958 ) * <rghf@fsck.me.uk> on Tuesday December 16, 2003 @12:50PM (#7735835) Homepage
      Hes an engineer so he will, like most of us spend 20 hours writing something when he could do it in 10 with someone else code or in 5 if doing it manually

      Rus
    • Re:Nice to know... (Score:3, Insightful)

      by redtail1 ( 603986 )
      Good point about reinventing the wheel but I appreciate tutorials like this one when I've been wondering how to go about writing such a thing. Sometimes I want to learn how it is done more than I want to use the finished result.
    • Another good one is cantus, although I don't think it's active anymore. Cantus does batch retagging based on filenames, or batch renaming based on tags. Also has great controls for stripping leading/trailing spaces, fixing buggy tags, etc.

      Can't someone please integrate cantus or easytag with a library management system, along with an mp3 player?!? It can be a gnome or kde app, I don't care. I want an (xmms | noatun | juk) & (madman | rhythmbox) & (easytag | cantus) combo.
    • I've tried a lot of tagging software over the years, and a lot of it is pretty good, but the authors always seemed to have their own notions about which features were important and what was the easiest way to do thing. And figuring out exactly how to get the software to do what I want is also a lot of work. I've mostly ended up thinking that major retagging is not worth the trouble. I haven't tried doing it in Perl, but for what I need it might actually be less work than a high-level application.

      You claim

  • Perl.com article (Score:4, Interesting)

    by twoshortplanks ( 124523 ) on Tuesday December 16, 2003 @12:36PM (#7735699) Homepage
    On a similar note, there's a perl.com article on using MusicBrainz that was published recently.

    Identifying Music with MusicBrainz [perl.com]

    • Re:Perl.com article (Score:5, Informative)

      by blech ( 8859 ) on Tuesday December 16, 2003 @01:02PM (#7735938) Homepage
      To be fair, the MusicBrainz article for perl.com [perl.com] (that, full disclosure time, I wrote) doesn't cover as much ground as the Developer Works article, which seems to be going through all the steps needed to write an autotagger in Perl.

      However, I was a little dissapointed that Teodor didn't spell out more of his reasoning for his choice of modules. I covered the (then) available Perl mp3 modules for a talk at YAPC::Europe this summer, and if you're not sure which modules to use, I'd suggest having a look at the slides (80K PDF) [husk.org] and notes [husk.org].

      In any case, I look forward to the second part of the article, to see how the script shakes out in the end.
  • Perkasdflop (Score:2, Funny)

    by Anonymous Coward
    To be honest, I'm waiting for the Common Lisp port...
  • Self-respect (Score:2, Insightful)

    by trentblase ( 717954 )
    Every self-respecting computer and music fan needs to be able to manipulate MP3s

    Have those lossless compression afficionados [monkeysaudio.com] no dignity?

  • by GeorgeH ( 5469 ) on Tuesday December 16, 2003 @12:40PM (#7735733) Homepage Journal
    MP3s -- the defacto standard for recreational digital music use
    Really? I had no idea! What's next, the Internet on computers? Man, that would be cool, maybe they could put dancing hamsters on it.
  • by Dr. Zowie ( 109983 ) * <slashdotNO@SPAMdeforest.org> on Tuesday December 16, 2003 @12:42PM (#7735762)
    Perl (with PDL [perl.org]) is powerful enough to remix, comb-filter, compress, depop, noise-gate, and generally munge your mp3s as much as you want.

    We're in an exciting time when many of the scripting languages are being augmented to be able to handle Real Data (Numpy [pfdubois.com] is another example).

    • ...deleting! Don't forget deleting! unlink() forever! ;)))

      Oh, you said "generally munge"...
  • by crow ( 16139 ) on Tuesday December 16, 2003 @12:54PM (#7735874) Homepage Journal
    Seriously, I've been thinking it would be cool to have an emacs mode for MP3 files. The raw data wouldn't be displayed, but the ID3 tags would be available for editing.
    • by Anonymous Coward
      30 seconds with google revealed, among several MP3 player modes, this MP3 tag editor mode for emacs [google.com], released in 1999. Next question?
  • genre splitting (Score:3, Interesting)

    by digitalsushi ( 137809 ) * <slashdot@digitalsushi.com> on Tuesday December 16, 2003 @12:55PM (#7735883) Journal
    Does anyone remember that perl module that would "listen" to the mp3 and decide which musical genre it thought it was? I'm not referring to matching the ID3 tags against something... it would make a guess based on stuff like the tempo and frequency range, et cetera. (I have no idea how it actually works, and I have no idea if it is even real. I just know I read about it a long time ago and figured someday it might be something a nonprogrammer like me could use)
  • How did it come to pass that mp3 ripper's don't pull this data from the CD? RealPlayer, Windows Media player, etc. all show me data for the CD I am listening to, if available. Are there really that few CD's that include the proper information?
    Furthermore, are there programs that are erasing the data from these MP3's when they are being circulated?
    • by blech ( 8859 ) on Tuesday December 16, 2003 @01:14PM (#7736043) Homepage
      Generally, CDs don't have all the track information on the CD. RealPlayer, Windows Media, iTunes and so on all use a computed identifier of some sort, based on the length of tracks, typically, to look up the CD information from an online database.

      Of course, because this means that *someone*, *somewhere*, ended up typing in the data, there are errors in a lot of the data. Most of the CD lookup databases are very bad at handling compiliations, and can have problems with any of the items of metadata other than title and artist (for example, 'year' often ends up as the year the CD is ripped, not the year the music was produced).

      There aren't many programs that strip the data that's produced, though. Thankfully.
    • No standard audio CDs contain digital author or title information. It was an oversight or stupidity on the part of the people who invented the CD standard. When you fire up Grip or WMP and pop in your CD, the track listing you get is retrieved from a database, based on a hash made from (among other things) the precise length of each track that is found.
    • You're referring to CD-TEXT, a standard of sorts introduced by Sony where Artist, Album name, and track titles are encoded onto an audio CD in the subcodes.

      It's true, not every commercial pressed CD out there has this feature, and believe it or not, not every CD-ROM (particularly older ones) can read the subcodes to extract the CD-TEXT info.

      Sony Music includes CD-TEXT on all the CDs in it's catalog (to complement the CD-TEXT display features on most of it's car CD players.) I don't know about the other ma
  • $filename =~ m/([^-_]{3,})\s*-\s*(.{3,})\s*\.[^.]+$/

    ;-)

  • MusicBrainz (Score:4, Interesting)

    by Mr_Silver ( 213637 ) on Tuesday December 16, 2003 @01:22PM (#7736124)
    MusicBrainz::Client and AudioFile::Identify::MusicBrainz were not used because MusicBrainz appears to be a less comprehensive database of released CDs than FreeDB.

    True, but the point of MusicBrainz is not to hold a database of released CD's but more snapshots of MP3 tracks.

    At the moment, without MusicBrainz I cannot automatically populate my ID3 tags with the information about an album unless I get it out of the cupboard and type the details in myself.

    MusicBrainz allows me to do all this without any access to the CD's

    • Yes, he's right, it is less complete, but MB tries to be accurate and consistant. freedb has a huge number of different capitalization schemes ways of people entering artist information (Eagles, The Eagles, Eagles, The, THE EAGLES, etc). MB takes it's information from Freedb, but reliese on it's users and moderators to munge the information into something consistant.

      The beauty of it is that if you find something that's missing, it's very very easy to add it :)
      • actually freedb states somewhere that the prefix "the" should be eliminated, except for the band "the the", which will retain the 'the'. since i use lower case for everything, this isnt much of a problem.

        the problem is more pertinatnt imo when you have things like multi disc sets is it: dis{c|k} 1, dis{c|k} 1 of 3, etc. is it '&', or 'and' etc. so yeah mb is more accurate and consistant. plus mb frequently merges the freedb into their own, with moderation of course.
  • while on the subject of Perl & mp3, I put together a object persistence [patentinvestor.com] module I called AudioDBI for audio metadata. It works with PostgreSQL, but with a little work it should play nicely with any database DBI supports (it extends DBI).

    I know their are currently about five thousand object persistence modules for Perl, but I wanted one that was designed for audio metadata (artist name, album title, genres, etc etc) and provided for easy searching of metadata.

  • How is it done in python?

    Any takers?
  • Anyone have a good suggestion as to what to use for creating CD inserts for jewel cases? I use eroaster and I've ended up writing a script that parses the CD songlist and creates a printable text document. I'm pretty sure eroaster is not writing the song/artist track info to the CD :-(
  • I wrote my own little Perl scripts using MP3::Info [uwinnipeg.ca] and MP3::ID3v1Tag [uwinnipeg.ca]. While you're at it, you may want to check out Apache::MP3 [uwinnipeg.ca] and my own pet project, TVDinner Streaming MP3 Server [dnsalias.com].

  • freedb.org haven't added a general purpose search to the cddbd server. [sourceforge.net] It can only be searched by discid.

    The full-text search is still labelled experimental in CVS [sourceforge.net], though the page at freedb.org [freedb.org] doesn't warn about that anymore.

    I've chosen to download the database [freedb.org] to a local server and tweak the server code (in C-- I'm nowhere with Perl) to allow full-text searches. I ripped about 30 CDs with EAC before I knew how to set the tagging options right so I'm missing track numbers.
  • I've tried some German program called MP3Tag, but I'm looking for something better. Does anyone have a recommendation for the best mp3 tagging and renaming utility for windows?
  • Shit, I didn't mean to post this anonymously... Here it is again logged in...

    This looks very similar to a little Perl program I recently wrote, although mine doesn't use a CDDB-type system.

    Anyway, it's called 'Audiotag,' and is designed to be a decent mass tagger with sane options and supports MP3, OGG, and FLAC.

    If you're interested... Audiotag [freshmeat.net]

  • Perl is my favorite dataprocessing language. Tag editing is great, but where's the Perl module for extracting metadata from the audio data? Tempos? Rhythms? Instrument identification? Tablature transcription? Bayesian correlation? Or in-stream editing MP3S? Mixing? Volume? EQ? Looping/branching on pitches? C'mon, Perl, impress me with your eclecticism.

1 + 1 = 3, for large values of 1.

Working...