Created
January 17, 2011 12:59
-
-
Save sattellite/782821 to your computer and use it in GitHub Desktop.
Download music from your playlist in vk.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/perl | |
use strict; | |
use LWP::Simple qw(getstore); | |
use LWP::UserAgent; | |
use HTTP::Cookies; | |
use Getopt::Long; | |
my $DIR_TO_SAVE = 'VKplaylist'; | |
my ($cfile, $file, $exclude, $login, $pass, $cookie, $browser, $response, @links, @files, $num, $artist, $title, @excludes, @excluded); | |
$cfile = 'cookie.dat'; | |
$exclude = ''; | |
$cookie = HTTP::Cookies->new(); | |
$browser = LWP::UserAgent->new(); | |
GetOptions ('exclude|e:s{,}' => \@excludes); | |
if (-e $cfile) { | |
$cookie->load($cfile); | |
$browser->cookie_jar($cookie); | |
} else { | |
print "Enter your login: "; | |
$login = <STDIN>; | |
chomp $login; | |
print "Enter your password: "; | |
$pass = <STDIN>; | |
chomp $pass; | |
$browser->cookie_jar($cookie); | |
$response = $browser->post("http://vkontakte.ru/login.php", {success_url => '', fail_url => '', try_to_login => 1, email => $login, pass => $pass}); | |
$cookie->save($cfile); | |
} | |
$response = $browser->get("http://vkontakte.ru/audio.php"); | |
if ($response->is_success) { | |
foreach (split /\n/, $response->content) { | |
if (/return operate\('([0-9]*_??[0-9]*)','(http:\/\/cs[0-9]*\.vkontakte\.ru\/u[0-9]*\/audio\/[0-9a-f]*\.mp3)',[0-9]*\)/) { | |
$num = $1; | |
push @links, $2; | |
} | |
if (/performer$num"><a href='.*'>(.*?)<\/a>.*title$num">(.*?)<\/span>/) { | |
$file = "$1 - $2"; | |
push @files, $file; | |
} | |
} | |
} | |
else { | |
die "HTTP Request failed"; | |
} | |
if (@excludes) { | |
for (my $i=0; $i<@excludes; $i++) { | |
for (my $j=0; $j<@files; $j++) { | |
if ($files[$i] =~ /$excludes[$j]/) { | |
my $excl = splice(@files, $j, 1); | |
push (@excluded, $excl); | |
splice(@links, $j, 1); | |
$j--; | |
} | |
} | |
} | |
} | |
mkdir $DIR_TO_SAVE unless -d $DIR_TO_SAVE; | |
print "This tracks will be not downloaded:\n\n" if (@excluded); | |
if (@excluded) { | |
foreach (@excluded) { | |
print "$_\n"; | |
} | |
print "\n\n"; | |
} | |
for (my $i=0; $i<@links; $i++) { | |
my $dir = "$DIR_TO_SAVE/$files[$i].mp3"; | |
if (-e $dir) { | |
print "\"$files[$i]\" already exists.\n"; | |
} else { | |
print "[" . ($i+1) . "/" . ($#links+1) . "] Downloading \"" . $files[$i] . "\". Please wait...\n"; | |
getstore($links[$i], $dir); | |
print "Done.\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment