Slashdot Mirror


Cultured Perl: Fun with MP3 and Perl, Part 2

Ted writes "I continues to look at manipulating and guessing MP3 tags with Perl, FreeDB, and various CPAN models via my autotag.pl application. Writing autotag.pl was grueling but fun. I used fuzzy string matching, FreeDB searches, ID3 versions 1 and 2, and lots of text-mode user interactions. It all came together in an application that I tested thoroughly over the course of a month. Info and Slashdot comments about Part One can be seen here, which was posted in December."

55 comments

  1. I swear.... by Anonymous Coward · · Score: 0, Funny

    if the next news item refers to undersea stuff (third in a row), I swear....

  2. Mmm Perl by Michael.Forman · · Score: 4, Informative

    As long as we're on the topic of useful perl scripts for manipulating metadata, let me offer some other scripts as well.
    • ren-regexp - A perl script that renames many files in parallel using a series of regular expressions from the command line. It's a profoundly useful script for those who are command-line and regexp power users.
    • mp3-ren-nice - A perl script that attemts to clean up munged mp3 file names downloaded from P2P networks. For example running the script on "artist-title_title.2.MP3" will yield "Artist - Title Title.mp3".
    • newpl - A perl script that creates an empty perl script template complete with GetOptions code and a POD skeleton for writing more scripts that manipulate mp3 files.
    That and more here. Now wasn't that informative?

    Michael.
    --
    Linux : Mac :: VW : Mercedes
    1. Re:Mmm Perl by sydb · · Score: 1

      So why is this a problem for you?

      --
      Yours Sincerely, Michael.
    2. Re:Mmm Perl by addaon · · Score: 4, Informative

      I wasn't the original poster, but I can tell you why it bothers me. Using spaces and other non-normal characters in filenames means that the files actual name is different from the typed representation of the file name. So "My File" needs to be referred to as "My\ File". Now, this isn't so big a deal if all you ever do is use the command line. But I tend to interact with guis at times. And the two major operations I perform between guis and clis is copy and paste and drag and drop. Both fail with filenames with spaces. If I copy a file name "My File" and paste it to the terminal (or drag and drop the file there, which has exactly the same effect), the text that is automatically entered does not represent what I intended it to. This is broken behavior and, while it could be worked around (especially in the drag and drop case, there's no reason for the gui not to make the correction if it knows it's being dropped in a terminal), it's easier just to avoid it entirely.

      --

      I've had this sig for three days.
    3. Re:Mmm Perl by metamatic · · Score: 4, Insightful

      Personally I'd just type " before and after pasting the filename with the spaces in.

      Filenames are for humans, fix the broken software that doesn't allow filenames with spaces in.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    4. Re:Mmm Perl by Anonymous Coward · · Score: 0

      Get a clue and learn how to use " ".

    5. Re:Mmm Perl by Michael.Forman · · Score: 2, Interesting


      I'm the original poster and I agree with you totally! I do not tollerate spaces in my Unix filenames with the sole exception of mp3 files.

      As a matter of fact, that's one of the main reasons I wrote my ren-regexp perl script. For files with unsightly spaces I simply type:
      ren-regexp "s/ /-/g" *\ *
      and my files are sane again.

      Isn't that strange that I prefer my mp3 file names with spaces? I never really thought about it until now. :)

      Michael.

      --
      Linux : Mac :: VW : Mercedes
    6. Re:Mmm Perl by arkanes · · Score: 4, Interesting

      DnD not working with filenames with spaces in them is because broken applications don't correctly or fully implement XDnD. You're limiting yourself because of flaws in your software and claiming the moral high ground?

    7. Re:Mmm Perl by addaon · · Score: 1

      Right, but I need spaces in my filenames about as much as I need native support for Linear A. Software is for humans, and for this particular human, simple and effective software is more valuable than allowing 0x20.

      --

      I've had this sig for three days.
    8. Re:Mmm Perl by addaon · · Score: 1

      Nope, I'm limiting myself because of design decisions in my software (the decision being that command line arguments can be parsed by crt0, in a common manner, rather than having each application support it's own arbitrary grammar), and I'm saying 'this why I don't like spaces in file names'.... what the heck does morality have to do with anything? I'd just rather main take a char** than a char*.

      And what the heck does XDnD have to do with anything? What made you think I'm using X?

      --

      I've had this sig for three days.
    9. Re:Mmm Perl by Just+Some+Guy · · Score: 4, Funny
      there's no reason for the gui not to make the correction if it knows it's being dropped in a terminal

      In other words, you wish that all combinations of X apps and terminal programs worked like kwin plus konsole? Whenever I drag an icon into a konsole window, I get a context menu to paste, cd, cp, ln, or mv the specified path into my current shell directory.

      In fact, the quickest way I know of to copy a single MP3 from home to the office (assuming I'm currently using X) is to:

      1. Open Konqueror and select the bookmark for "sftp://myhomeserver/usr/share/media/music/singles ",
      2. Type "cd /tmp" (or wherever) in my konsole window, and
      3. Drag the desired icon into that same konsole window.

      Within a couple of minutes, I have the file in my local /tmp directory. Now that is how GUIs and CLIs are supposed to work together.

      Oh, if you're my boss: just kidding ha! ha!

      --
      Dewey, what part of this looks like authorities should be involved?
    10. Re:Mmm Perl by DrSkwid · · Score: 2, Insightful

      #!/usr/local/bin/rc

      for (mp3 in *.mp3) mpg123 $mp3

      fails if the filename contains a space

      ls -l *.mp3 | awk ' { print "%s is %d bytes\n", $9, $5 } '

      fails if the filename contains a space

      etc.

      spaces in filenames should be illegal

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    11. Re:Mmm Perl by Anonymous Coward · · Score: 0
      And the two major operations I perform between guis and clis is copy and paste and drag and drop. Both fail with filenames with spaces. If I copy a file name "My File" and paste it to the terminal (or drag and drop the file there, which has exactly the same effect), the text that is automatically entered does not represent what I intended it to.

      Unix shells are still in the stone age when it comes to filename spaces. Windows has your OS beat on this. Right-click and drag a file to the command prompt window and cmd.exe will automatically surround the filename with quotes. Another thing that cmd.exe does better than most Unix shells is tab complete filenames without regard to case. For example if you have files foo.txt and Foo.txt, cmd.exe will intelligently know to match both files when cycling through the tab completion. Cmd.exe also properly appends a carriage return-line feed to the end of terminal output. Unix shells won't do this. This leaves some programs that don't end with a '\n' to run onto the same line as the prompt.

    12. Re:Mmm Perl by sydb · · Score: 1

      Thanks, I knew there was a good reason why I avoided them but I couldn't remember it!

      Actually I don't use spaces in my ogg filenames but I am quite happy to have spaces in the directory names. I never experience problems. And where I do, I 'quote' the filename.

      Someone complained about for mp3 in *mp3... find . -name '*mp3' -exec.... should do it.

      --
      Yours Sincerely, Michael.
    13. Re:Mmm Perl by Michael.Forman · · Score: 1


      KDE does that too, silly goose.

      Drag and drop a Desktop icon or Konqueror file into a Konsole and it is quoted and the tcsh shell supports case-insensitive file name completion as well if "set complete = enhance" is set.

      *Lick lick* Your tears of sorrow taste so sweet. :)

      Michael.

      --
      Linux : Mac :: VW : Mercedes
    14. Re:Mmm Perl by Smallpond · · Score: 2, Funny

      I think in Linear A, you insensitive clod.

      it actually looks a lot like Perl:
      sample

      - !//!!1\\\!!!

    15. Re:Mmm Perl by metamatic · · Score: 1

      Wellclearlyit'samatterofpersonalopinion,butI'llmak eanotenottounnecessarilycluttermyresponsestoyourco mmentswithspacecharacters.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    16. Re:Mmm Perl by RdsArts · · Score: 1

      Add quotes around the name in the terminal. It will then work correctly.

      <add a quote>"<copy My File Name.ogg to terminal>My File Name.ogg<add a quote>"

    17. Re:Mmm Perl by damballah · · Score: 2, Insightful

      Software problem. Software that do not allow spaces in filenames should be illegal.

    18. Re:Mmm Perl by Anonymous Coward · · Score: 0

      no_offense_but

      multiple filenames without extensions look like files with spaces in them.

      you_can_always_use_underscore

    19. Re:Mmm Perl by Anonymous Coward · · Score: 0

      Wow, your GUI sucks. OS X doesn't break like that. I can drag files/folders from the finder into a terminal window and the entire path to the resource shows up on my command line, perfectly shell escaped and ready for me to hit return.

    20. Re:Mmm Perl by jfx32 · · Score: 1

      Someone mod parent up. The inability for software to deal with spaces in the file name is an error in the software. The user should not have to conform to the limits of poorly designed software. Not letting a user use spaces in a file name is the same as not letting them use more than 8 characters in the file name - it is limiting and a sign of bad design.

    21. Re:Mmm Perl by DrSkwid · · Score: 1

      so are you

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    22. Re:Mmm Perl by DrSkwid · · Score: 1

      you are dumb

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    23. Re:Mmm Perl by ClioCJS · · Score: 1

      Filenames without spaces is like, so, totally 20th century dude. Gag me with a backslash.

      --
      -Clio
      Karma: Bad (mostly from not giving a fuck)
      Blog: http://clintjcl.wordpress.com
    24. Re:Mmm Perl by DrSkwid · · Score: 1

      > Someone complained about for mp3 in *mp3... find . -name '*mp3' -exec.... should do it.

      that's an extra fork, what about symlinks (ugh) and it's dirty

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    25. Re:Mmm Perl by DrSkwid · · Score: 1

      do you really consider that to be quick?

      in plan9 I would just do this

      to play it

      mpg123 /n/home/mp3/Some_file.mp3

      to copy

      cp /n/home/mp3/Some_file.mp3 /tmp

      all this opening applications and dragging, jeesh

      if I didn't know the filename I could do

      ls /n/home/mp3

      then when the text was on screen click to the left of it type 'cp ' click to the right of it type ' /tmp' sweep the desired complete command which is now 'cp /n/home/mp3/Some_file.mp3 /tmp' and middle click, select 'send'

      until you've used plan9, you don't know what usability is

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    26. Re:Mmm Perl by DrSkwid · · Score: 1

      see man ls

      -Q By default, printed file names are quoted if they contain characters special to rc(1). The -Q flag disables this behavior.

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    27. Re:Mmm Perl by sydb · · Score: 1

      Anyone who worries about extra user-driven forks on personal systems nowadays is obviously the kind of person who would obsess over a long-dead academic operating system.

      --
      Yours Sincerely, Michael.
    28. Re:Mmm Perl by DrSkwid · · Score: 1

      lol, good comeback

      it's about elegance

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    29. Re:Mmm Perl by sydb · · Score: 1

      Your post has persuaded me to try out plan9 sometime. I heard about plan9 years back but it seemed very fringe and I never really paid it any attention.

      I was shocked to see there was a release last year and that it's still in active use. Thanks for kindling a flame of curiousity.

      It's just a shame there is no release for Sparc, I have a load of IPX's that would benefit from an interesting operating system.

      --
      Yours Sincerely, Michael.
    30. Re:Mmm Perl by amoe · · Score: 1

      It is useful for the user to keep a clear mental division between the name of a file and its contents, since there is no intrinsic link between the two. More association simply leads to more "metaphor shear", as Neal Stephenson puts it.

      --
      You look beautiful! Incidentally, my favourite artist is Picasso.
    31. Re:Mmm Perl by DrSkwid · · Score: 1


      We're getting more and more users all the time tbh.

      Even Linus pops by to the 9fans mailing list now and again.

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
  3. Musicbrainz? by magnum3065 · · Score: 4, Informative

    Isn't this the kind of thing MusicBrainz was invented for. For those who don't know about it MusicBrainz is like CDDB, but you can look up files based on an audio fingerprint as well as the tag information. This means that files could be tagged completely wrong and you can still match them in the database. They provide open-source software for generating the fingerprints, interfacing with the server, and the server software (should you, for some strange reason want to run your own site). There's a pretty easy-to-use client for Windows, and I've been considering writing my own client for Linux.

    1. Re:Musicbrainz? by windex82 · · Score: 2, Informative

      Informative, bah! Magnum forgot the most important part!


      Latest Version

      The MusicBrainz tagger is currently only available for Windows.

    2. Re:Musicbrainz? by DrSkwid · · Score: 2, Informative

      If anyone was interested they should know the code is in C++

      oh well.

      http://cvs.musicbrainz.org/cvs/mb_tagger/

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    3. Re:Musicbrainz? by magnum3065 · · Score: 1

      Yes, though like I mentioned, there are libraries available to interface with their server, so rather than writing software to interface with FreeDB, you could make a better program that interfaced with MusicBrainz.

    4. Re:Musicbrainz? by BJury · · Score: 1

      Woo, Ive always thought there should be a 'freedb' type solution based upon something like a MD5 has of the actual file.

      This looks like a good solution to my renaming problems, if it wasnt for the damn developers not taking into account people who have WHITE ON BLACK settings. Why do people constantly hard code the text (white) but leave the background colour as a system colour. (In my case also white!)

      ARG!

    5. Re:Musicbrainz? by TedZ · · Score: 2, Informative

      Please read the comments for the first article. And/or the article itself.

      I tried MusicBrainz and didn't like the interface to it, or its capabilities. FreeDB was much better for my purpose.

      Ted (article author)

    6. Re:Musicbrainz? by Darth23 · · Score: 2, Insightful
      Sounds like something worht trying out. In all my years of P2P experience I've learned that there a re a lot of music fans out there who have no clue about what artist performed which songs.

      I just wish there was a way to tell them all that just because a song is a parody, doesn't necesarrily mean it was written and performend by Weird Al.

      --

      -------- In Soviet Russia, "Soviet Russia" sigs hate Slashdot.

    7. Re:Musicbrainz? by windex82 · · Score: 1

      Yeah, I had just woke up when I read your post, I was reading through again later that day and realized you said something about coding your own for linux, I guess that could have also been interpreted as there is no linux client. The point was to save some time for users, like me, who would be looking for "completed" linux software.

  4. This is exactly what I need. by BrookHarty · · Score: 3, Informative

    I copied all my cd's to mp3s on my harddrive, one thing, no ID3 tags.
    Lucky, what I did do, is named them all with tracknumber-band-song.mp3 in each subdirectory.

    Now that I have like 200 some directories, I don't want to go in with id3master on windows and make a id3 version1/2 tags on every file.

    This is exactly what I need! I use cygwin to write small perl scripts to generate reports, so this should be a snap. He even has examples on how to use his perl modules.

    Wow, nice for IBM to have a linux developers forum.

  5. another rite of passage in perl. by j_d · · Score: 2, Funny

    MP3 renaming scripts now rank right up there with the image/ comic downloader and the templating system. Every perl programmer thinks, at some time, "I could get the funnies this way" or "this would be good to use as a templater", and now we're seeing a lot of scripts for MP3 renaming. It's like there's a perl hive-mind or something where we all think "yeah! social software networks in perl! or, yeah! tiny webservers in perl! wooo"

    1. Re:another rite of passage in perl. by tcopeland · · Score: 1

      > another rite of passage in perl

      Don't feel bad, it's the same way for Ruby folks.

      Maybe it's a scripting language thing in general.

    2. Re:another rite of passage in perl. by shotgunefx · · Score: 1

      Probably because you can do things like this so easily with them.

      --

      -William Shatner can be neither created nor destroyed.
    3. Re:another rite of passage in perl. by haystor · · Score: 2, Insightful

      It is a testament to the effectiveness of these various languages that just anyone can produce something useful.

      --
      t
    4. Re:another rite of passage in perl. by FooAtWFU · · Score: 1

      I use a social networking bot in Java, thank you. :)

      --
      The World Wide Web is dying. Soon, we shall have only the Internet.
    5. Re:another rite of passage in perl. by astroboscope · · Score: 1
      Maybe the 1st chapter in any beginner's book on a programming language should be how to use CPAN or whatever public code repository the language uses.

      And editor and/or compilers could raise an error if the code doesn't have enough use/#includes near the start ;->

      --
      If we were ants living on a Rubik's cube, differential geometry would be a little more confusing.
    6. Re:another rite of passage in perl. by TedZ · · Score: 1

      CPAN is nice, but it should not be the starting point for a beginner, unless they don't care about the language.

      CPAN modules are sometimes written badly.

      CPAN modules are "one size fits all" which can be slow or even unusable for specific purposes.

      CPAN modules don't teach.

      Installing CPAN modules requires at least a little understanding of Perl. Otherwise you get cargo cult programmers who only know "perl -MCPAN -eshell" and can't think for themselves.

      Ted

      p.s. this applies to every other language with a public source code repository.

    7. Re:another rite of passage in perl. by astroboscope · · Score: 1
      CPAN is nice, but it should not be the starting point for a beginner, unless they don't care about the language.

      The 1st chapter would have to quickly segue into writing wrapper code to adapt CPAN packages to your needs, and take a more traditional approach from there.

      CPAN modules are "one size fits all" which can be slow

      Slower than DIY? Even if you're a newbie?

      CPAN modules don't teach.

      Reinventing the wheel can be educational, but you could also learn by tinkering with a car. (Maybe not the safest example, but lots of things in real life are learned by clueless tinkering.)

      Installing CPAN modules requires at least a little understanding of Perl.

      Well I wasn't thinking of just reprinting the CPAN manpage. Merely suggesting that the CPAN chapter should come closer to the front than the back. The problem with many perl texts is that CPAN can be lumped in or behind networking, or OO, and people have a tendency to stop reading as soon as they hit something that they don't need right now.

      --
      If we were ants living on a Rubik's cube, differential geometry would be a little more confusing.
  6. Wow... by Bob+The+Cowboy · · Score: 1

    I've been totally planning on doing this myself in the past few weeks, as sort of a next project to teach myself some more perl.

    cool.

    Bill

  7. Spaces separate words. Filenames are words. by astroboscope · · Score: 1
    Filenames are for humans,

    Correct.

    fix the broken software that doesn't allow filenames with spaces in.

    Utterly wrong. According to the philosophy that software should help humans, and bend over backwards if necessary to do so, it should only present humans with filenames that are easy to parse at a glance. That means sticking to the "filenames are separated by spaces" system:

    % ls
    a b.mp3 c
    Is that "a", "b.mp3", and "c", or "a b.mp3" and "c", or "a" and "b.mp3 c"(, etc.)? It's only obvious if
    1. The "filenames are separated by spaces" system is used.
    2. ...or the UI is hobbled by displaying only 1 file per line, or attaching a big icon to each file, drastically reducing the number of files that can be displayed in a given screen area.
    Another poster pointed out how spaces in filenames can break awk 1-liners, etc., and was told to write a smarter script. The point of a 1-liner is that it's off the cuff and saves time. Writing a "smarter" (really, more robust) script is simply not smart in such cases.

    You could argue that humans prefer to put spaces instead of _ or UpperCase in filenames at creation time, but filenames tend to be write once, read many. Avoiding spaces to begin with, or running a space removal script in a directory (tree) is better than dealing with the spaces over and over again.

    Personally I'd just type " before and after pasting the filename with the spaces in.

    It's often easier to type the first few letters and let tab completion fill in the escaping for you.

    --
    If we were ants living on a Rubik's cube, differential geometry would be a little more confusing.
  8. Re:Spaces separate words. Filenames are words. by Just+Some+Guy · · Score: 1
    It's often easier to type the first few letters and let tab completion fill in the escaping for you.

    Just a note: that still works if you type " first.

    --
    Dewey, what part of this looks like authorities should be involved?