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?
-
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.
|