UPDATE - mp3.com regularly changes their submit variable names, so, good chance that this code is broken but easily fixed. Not to mention that i wrote this over a year ago without any HTML parsers ...
Please inform me of any problems. Now all you monks out there with mp3 Artist accounts rush to use this. Hmm, do I hear crickets chirpin'?#!/usr/bin/perl -w # mp3admin-display.cgi use strict; use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; # form variables my $email = ''; # SET THIS TO YOUR EMAIL my $password = ''; # SET THIS TO YOUR PASSWORD my $band_id = ''; # SET THIS TO YOUR BAND ID # bot variables my $agent = LWP::UserAgent->new; my $cookie_jar = HTTP::Cookies->new; my $res; # URL's of importance my $login_url = 'https://login.mp3.com/login'; my $admin_url = 'http://stats.mp3.com/cgi-bin/artist-stats.cgi'; # list of songs and their id's my %songs = (); print "Content-type: text/html\n\n"; &login($agent, $res, $cookie_jar, $email, $password, $login_url); &printImageAndFindSongs($agent, $res, $cookie_jar, $band_id, \%songs, $admin_url); foreach my $song_id (keys %songs) { &dumpAttribs($agent, $res, $cookie_jar, $band_id, $song_id, $songs{$song_id}, $admin_url); } exit; # login is necessary to set cookies sub login($$$) { my( $agent, $res, $cookie_jar, $email, $password, $login_url) = @_; # build request for login web page (so we get the set of cookies) my $req = POST ($login_url, [ cmd => 'login', dest => 'http://studio.mp3.com/cgi-bin/artist-admin/login.cgi?ste +p=Intro', tmpl => 'login_artist.html', email => $email, password => $password, ]); # issue the request $res = $agent->request($req); # extract the cookies $cookie_jar->extract_cookies($res); } # prints out Total Stat Image and builds list of songs sub printImageAndFindSongs ($$$$) { my( $agent, $res, $cookie_jar, $band_id, $songs, $admin_url) = @_; my @lines; my $start; my $last; # build the request for the stats page my $req = GET ("$admin_url?band_id=$band_id"); # add the cookies we got from the previous request $cookie_jar->add_cookie_header($req); # issue the request $res = $agent->request($req); if ($res->is_success) { # print stat image first @lines = split(/\n/, $res->content); for (my $i=0; $i <= $#lines; $i++) { if ($lines[$i] =~ /^\s*<form.+?name="stats">$/i) { $start = $i; } elsif ($lines[$i] =~ /Estimated payments/i) { $last = $i; } } print join("\n", @lines[$start..$last]); print "</td></tr></table>\n"; # now get the songs @lines = grep { /^<OPTION/ } @lines; map { /^\s*<OPTION\s+\w*\s*\w+="(\d+)">(.+)\s*$/i; $songs{$1} = $2; } @lines; } else { print "Error trying to load first admin page\n"; } } # loads song page and prints stats sub dumpAttribs ($$$$) { my( $agent, $res, $cookie_jar, $band_id, $song_id, $song, $admin_url) = @_; my @lines; my $start; my $last; # build the request for the stats page my $req = GET ("$admin_url?band_id=$band_id&song_id=$song_id"); # add the cookies we got from the previous request $cookie_jar->add_cookie_header($req); # issue the request $res = $agent->request($req); if ($res->is_success) { @lines = split(/\n/, $res->content); for (my $i=0; $i <= $#lines; $i++) { if ($lines[$i] =~ /^\s*<input type=hidden name="report_month +".*$/i) { $start = $i; } elsif ($lines[$i] =~ /^\s*<!-- Outer Table -->.*$/i) { $last = $i - 3; } } print "<form>\n"; print join("\n", @lines[$start..$last]); } else { print "Error trying to load song page $song_id\n"; } }
In reply to (jeffa) Re: mp3.com stats
by jeffa
in thread mp3.com stats
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |