#!/usr/bin/perl # Created: 01mar02 # By Jeff Connelly # Perl interface to Audiogalaxy.com's web-based interface # LITE VERSION: Only has getversions() #package Unweb::Search::Audiogalaxy; use LWP::UserAgent; use vars qw($ua $SERVER); use LWP::Simple; $ua = LWP::UserAgent->new; # Webserver to use, specify fast.audiogalaxy.com for gold accounts or # audiogalaxy.com for regular accounts #$SERVER = "http://fast.audiogalaxy.com/"; $SERVER = "http://www.audiogalaxy.com/"; sub login { my ($login, $passwd) = @_; my ($request, $response, $cookie, $content, $sid); # $SERVER/?loginUsername=...&loginPassword=... while(!length($content)) { $request = HTTP::Request->new('GET', "$SERVER/index.php?loginUsername=$login&loginPassword=$passwd"); $request->user_agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90; .NET CLR 1.0.3705)"); $response = $ua->request($request); $cookie = $response->header("Set-Cookie"); $content = $response->content; open(LOG,">out.html")||die;print LOG $content;close(LOG); if (length($content)){ last } print "blank page returned, retrying..."; print $response->{_msg}; sleep(1); print "NOW\n"; } if ($content !~ m/welcome $login/ # Gold and$content !~ m/$login<\/span> home/) # Regular { die "login failure $login, see out.html for details"; } ($sid) = $cookie =~ m/SID=([^;]+)/; return "SID=$sid; cookieUsername=$login; cookiePassword=$passwd"; } # Get list of all versions of a song, from there you can choose a version ID sub getversions { my ($cookie, $id) = @_; my ($request, $response, $content, @versions); my ($artist, $title); $request = HTTP::Request->new('GET', "$SERVER/list/chooseVersion.php?g=$id"); $request->header("Cookie" => $cookie); $response = $ua->request($request); $content = $response->content; open(OUT2, ">out4.html")||die; print OUT2 $content; close(OUT2); # Parse $content into a list of available versions while($content =~ m#fileSetIDStr"[ ]value="([^"]+)">