Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
All,
I am taking a break from Perl6 to help solve a problem for a relative. They have a huge library of music CDs and find it difficult to remember what they already have when looking to buy new stuff. I was hoping there was something equivalent to ISBN for books so that I could automate most of the process of building a database. Using the UPC, I was able to come up with the following very rough proof of concept:
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use HTML::Strip; use HTML::TableContentParser; my $upc = $ARGV[0] || die 'UPC required'; my $url= "http://www.amusicarea.com/detail/$upc.html"; my $mech = WWW::Mechanize->new( autocheck => 1 ); $mech->get($url); my %meta; my $table = HTML::TableContentParser->new()->parse($mech->content); my $data = HTML::Strip->new()->parse($table->[7]{rows}[0]{cells}[1]{da +ta}); $data =~ s/\n\s+//; for my $detail ( split /\n/, $data ) { my ($cat, $info) = split /\s*:\s*/, $detail, 2; $meta{$cat} = $info; } my $song = join '', map { HTML::Strip->new()->parse($_->{data}) } @{$table->[9]{rows}[0]{cells}}; $song =~ s/\n\s*/ /g; push @{$meta{track}}, $_ for grep $_, split /\s+\d+\.\s+/, $song; use Data::Dumper; print Dumper( \%meta );
Before I invest any time into this, I was wondering if anyone else was familiar with a better pre-existing wheel? I spent 2 minutes looking at Net::Amazon::UPC, but I couldn't find any info on the CD in my hand with it. Perhaps I just don't know how to use the module as it seems to me that this is a problem someone else would have already solved. If not, I would be happy to put some real development time into and share it publicly. Your thoughts?

Cheers - L~R


In reply to Music CD Data by Limbic~Region

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-02-09 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (44 votes). Check out past polls.

    Notices?