#!/usr/bin/perl # getmsmp3 v0.1 - download myspace mp3s # Copyright (C) 2007 Peter Willis print <{playlist}->{song} } ) { my $_id = "$id^$s_hr->{bsid}"; if ( !exists $IDS{$_id} ) { $IDS{$_id} = 1; } } return(keys %IDS); } sub find_mp3s { my $content_r = shift; my %IDS; while ( $$content_r =~ /\"(http:\/\/lads\.myspace\.com\/[^"]+?)"/img ) { my $url = $1; # band playlist if ( $url =~ /\/music\/musicplayer\.swf.+&d=([^&]+?)$/i ) { my $id = (split(/\^/, decode_base64($1)))[0]; if ( !exists $IDS{$id} ) { $IDS{$id} = 1; } } elsif ( $url =~ /\/mini\/mini\.swf\?b=([^&]+)&o=([^&]+)/ig ) { my $id = join("^", (decode_base64($2),decode_base64($1))); if ( !exists $IDS{$id} ) { $IDS{$id} = 1; } } } return(keys %IDS); } # takes "o=" and "b=" base64-encoded form elements as arguments # optionally a file name to save to, or "guesses" sub save_mp3 { #my ($O, $B) = ( decode_base64($_[0]), decode_base64($_[1]) ); my ($O, $B) = split(/\^/, $_[0]); my $XMLstring = get("http://mediaservices.myspace.com/services/media/musicplayerxml.ashx?b=$O&s=$B") || die "Error: could not retrieve XML ($!)\n"; my $h = XMLin($XMLstring); if ( $h->{curl} !~ /&p=(.+)$/ ) { die "Bad p ($h->{curl})\n"; } my $newurl = "$h->{durl}?bandid=$O&songid=$B&token=$h->{token}&p=$1&a=1"; my @file; foreach my $crap ($h->{bandname}, $h->{songname}) { push(@file, $crap) if (defined $crap and length $crap > 0); } my $file = ( join(" - ", @file) || "$O-$B" ) . ".mp3"; print "Saving \"$file\"\n"; getstore($newurl,$file) || die "Error: could not get MP3 and store in \"$file\": $!\n"; }