As a follow up to the mp3 id3 cataloger I posted to SoPW earlier I decided to post the cgi that searchs and returns results from the catalog.

There are some issues i am trying to work out. Right now, the catalog is plain text file with the format:

artist::album::title::track number::path
first of all it isnt very fast. I thought of a couple of ways to speed it up though.

Since the list of mp3s is alphabatized by artist it wouldnt be hard to add a line at the top of the file that specified the start of a particular character, and then jump there when an artist is specified. i.e. someone searchs for 'Fabolous' as the artist, and the F's start on the 200th line, and go till the 240th, i could limit the search to 40 lines rather easily. Another way would be to use a database instead of a plain file. This is really a bigger step then I want to take right now, if only because I dont want to deal with databases under OS X (MySQL got messed up when i tried to install it, even from the package). But if a database is the only way (or the only workable way) then I am more then willing to get MySQL or something similar working.

However, if someone searchs only by album or title, not artist, this is breaks. You could have a couple lines of code at the beginning of the plain file mapping albums to artist, but this is getting overly complicated, and will not work for title (at least not performance wise).

On the feature side of things I would like a search for artist alone to display that artists albums with the correct track order. This I dont know how to do with out reading the matches into an array of array (albums for artist and tracks for album) which is again a little more then I would like to do. But this is a important feature, so I will probably implement it this way anyway. Or, since the performance of the cataloger isn't important, I could have the cataloger just print the id3 info in correct order in the first place.

Another thing that has been requested is approx. searching. i.e. if you search for 'Camron' vs. 'Cam'ron' or 'Jay-z' vs. 'Jay z' vs. 'Jayz'. Is there some module to do this? I would like to avoid re-inventing the wheel, and this feature is pretty important so the a stable module based wheel is probably better then any wobbly code based wheel i could hack together.

A quick note on the formatting. I hate unordered lists, and plan to replace the visual/data repersentation of the results soon with something nicer (tables). If you have any suggestions, that would be great, but that is not paramount to sucess.

Thanks alot! Beware, the code is ugly! Any suggestions are really welcome! Code is below
#!/usr/bin/perl -w use strict; use CGI; my ($q, $artist, $title, $album, $file, $arti, $albu, $tite, $track, $ +path, $results); $file = "/Library/Webserver/Documents/mp3.info"; $q = new CGI; $artist = $q->param( "artist" ); $album = $q->param( "album" ); $title = $q->param( "title" ); if ( length($artist) > 20 or length($title) > 20 or length($album) > 2 +0) { display_page( "I am sorry but the was a malformed query" ); exit; } open (FILE, $file) or die ("Can't open $file: $!\n"); while (<FILE>) { ($arti, $albu, $tite, $track, $path) = $_ =~ m/^(.*?)::(.*?)::(.*? +)::(.*?)::(.+?)$/; if ($arti =~ /*+?$artist*+?/i or $tite =~ /*+?$title*+?/i or $albu + =~ /*+?$album*+?/i) { $results .= $q->li( $q->a( { href => $path }, "$artist - $title") ); } } close (FILE); print $q->header, $q->start_html, $q->h1("Results for $artist :: $title"), $q->ul( $results || "No results found" ), $q->end_html; sub display_page { my $message = shift; print $q->header, $q->start_html, $q->p( $message ), $q->end_html; }

Edit kudra, 2002-05-30 Made reference to previous post a link.


In reply to MP3/CGI Search Features by smgfc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.