I know how you programming folk like music, and I believe there
may be "support the little guys, not the corporations"
people in here too. So I created the script that takes a directory as an argument,
and then checks all the folders using the RIAA Radar database.
The RIAA Radar is a tool that music consumers can use to
easily and instantly distinguish whether an album was
released by a member of the Recording Industry Association of America (RIAA).

Sample output:
Morcheeba -- Safe: 3 Warning: 7
Moby -- Safe: 6 Warning: 4

#!/usr/bin/perl use warnings; use IO::Socket; $somedir = $ARGV[0]; opendir DH, $somedir or die "Cannot open $somedir: $!"; my @files = grep { !-d } readdir DH; closedir DH; foreach $word (@files) { $flag = 0; $safecou = 0; $warcou = 0; @split = split( / /, $word ); $join = join( '+', @split ); $getexp = IO::Socket::INET->new( PeerAddr => 'www.riaaradar.com', PeerPort => '80', Proto => 'tcp', Timeout => '100' ) || print "Error: Connection\n"; print $getexp "GET /search.asp?searchtype=ArtistSearch&keyword=$join HTTP/1.0\ +n"; print $getexp "Host: www.riaaradar.com\n\n"; while ( $exp = <$getexp> ) { if ( $exp =~ m/No results were found/ ) { $flag = 1; } #print "Artist: $1\n" if $exp =~ m/name="artist" value="(.*?)" + \/>/; #print "Album: $1\n" if $exp =~ m/name="album" value="(.*?)" \ +/>/; #print "Result: $1\n\n" if $exp =~ m/name="result" value="(.*? +)" \/>/; if ( $exp =~ m/name="result" value="Warning" \/>/ ) { $warcou ++= 1; } elsif ( $exp =~ m/name="result" value="Safe" \/>/ ) { $safecou + += 1; } } print "$word -- Safe: $safecou Warning: $warcou\n" if $flag != 1; }

Replies are listed 'Best First'.
Re: Band under RIAA?
by Errto (Vicar) on May 06, 2007 at 21:39 UTC
    Interesting idea. For clarity's sake I would suggest using LWP rather than mixing in raw HTTP data into your program logic.
Re: Band under RIAA?
by codeacrobat (Chaplain) on May 17, 2007 at 11:32 UTC
    There are tons of ways to webrobot more easily. In quickndirty scripts I recommend the use of lwp-request or wget. Otherwise use LWP::Simple or for the heavy stuff use WWW::Mechanize ( or WWW::Mechanize::Shell which simplifies script development ).
    Have a look:
    #!/usr/bin/perl # usage: $0 <ARTIST> <#PAGES> use strict; use warnings; use LWP::Simple; my $artist = shift || "Moby"; my $pages = shift || 1; # increase if artist is listed with more than + 1 page for my $pageno ( 0 .. $pages ) { my $page = get( qq(http://riaaradar.com/search.asp?keyword=$artist&page=$pageno) ); my %record; for my $line ( split /\n/, $page ) { if ( $line =~ m{<input type="hidden" name="([^"]+)" value="([^"]+) +} ) { $record{$1} = $2; } if ( $record{result} ) { if ( $record{artist} =~ /$artist/o ) { print "$_ $record{$_}\n" for (qw(artist album result)); print "\n"; } %record = (); } } }
    print+qq(\L@{ref\&@}@{'@'x7^'!#2/"!4'})