Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use LWP::UserAgent;
- use HTTP::Cookies;
- use HTTP::Response;
- use Digest::MD5 qw(md5_hex);
- # Соль зашитая в js. Используется при генерации ссылок на mp3 файлы.
- $salt = "XGRlBW9FXlekgbPrRHuSiA";
- $ua=LWP::UserAgent->new;
- $ua->agent("Mozilla/5.0 (compatible; Firefox 13.0.1; Windows 7)");
- $ua->cookie_jar(HTTP::Cookies->new(file=>"cookies.dat", autosave=>1));
- print "Insert URL - address: ";
- chomp ($url = <STDIN>);
- $url =~ s/#!/fragment/;
- $response = $ua->get($url);
- $page = $response->content;
- $page =~ s/"/"/g;
- $page =~ s/{/\n{/g;
- foreach (split(/\n/,$page)) {
- if (/id":"(?<id>\d+)".*storage_dir":"(?<storage_dir>[0-9a-f.]+).*title":"(?<title>[^"]+)/) {
- foreach (@id) {
- if ($+{id} == $_) {
- $flag = 1;
- }
- }
- if (!$flag) {
- push (@id, $+{id});
- push (@storage_dir, $+{storage_dir});
- push (@title, $+{title});
- }
- $flag = 0;
- }
- if (/"artist":"(?<artist>[^"]+).*album":"(?<album>[^"]+)/) {
- $artist = $+{artist};
- $album = $+{album};
- }
- }
- mkdir "${artist}_-_$album", 0755 or die "Cannot create directory with album name: $!";
- chdir "${artist}_-_$album" or die "Cannot change directory to ${artist}_-_$album: $!";
- foreach (@storage_dir) {
- push (@links, "http://storage.music.yandex.ru/get/$_/2.xml");
- }
- foreach (@links) {
- $response = $ua->get(@links[$counter]);
- $url = $response->content;
- $url =~ s/\n//gs;
- $url =~ /="(?<mp3url>[^\"]+mp3)/;
- $shit = $+{mp3url};
- @links[$counter] =~ s/2.xml/$shit/;
- @links[$counter] =~ s/get/download-info/;
- $response = $ua->get(@links[$counter]);
- $url = $response->content;
- $url =~ /<host>(?<host>.*)<\/host>/;
- $host = $+{host};
- $url =~ /<path>(?<path>.*)<\/path>/;
- $path = $+{path};
- $url =~ /<ts>(?<ts>.*)<\/ts>/;
- $ts = $+{ts};
- $url =~ /<s>(?<ss>.*)<\/s>/;
- $ss = $+{ss};
- $path =~ /^.(.*)/;
- $md5 = md5_hex($salt.$1.$ss);
- @finish[$counter] = "http://$host/get-mp3/$md5/".$ts.$path."?track-id=@id[$counter]&from=service";
- printf "%-60s", "Downloading @title[$counter].mp3 file:";
- $response = $ua->get("@finish[$counter]",
- ':content_file' => "@title[$counter]"
- );
- if ($response->is_success) {
- print "Done!\n";
- } else {
- print "Error!\n";
- }
- $counter++;
- }
- chdir "../" or die "Cannot change directory to previous: $!";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement