#!/usr/bin/perl use warnings; use strict; use LWP::Simple; use Encode qw/encode decode/; # http://music.sogou.com/song/newtop_1.html my $resp = get("http://music.sogou.com/song/newtop_1.html"); my @links = ($resp =~ m/window.open\('(http:\/\/mp3.sogou.com\/down.so\?t=[^']+)/gm); my $i = 0; while ($i < 10) { my ($r, $l, $t, $a); print "\n", $links[$i], "\n"; $r = get($links[$i]); $r =~ m/query.*?title="(.*?)">.*?title="(.*?)"/gms; $t = encode("utf8", $1); $a = encode("utf8", $2); $r =~ m/url=(http:[^']+)/gm; $l = $1; &down($a, $t, $l); $i ++; } sub down { my ($a, $t, $l) = @_; if (! (-d "down_mp3")) { mkdir "down_mp3"; } if (! (-d "down_mp3")) { print "cannot create directory: down_mp3\n"; exit; } { my @f = glob "down_mp3/*.aria2"; foreach (@f) { unlink substr $_, 0, -6; unlink $_; } } if ( -e "down_mp3/$a - $t.mp3.aria2") { print "Continue download: $a - $t.mp3\n"; system("aria2c", "-q", "-o", "down_mp3/$a - $t.mp3", $l); } elsif ( -e "down_mp3/$a - $t.mp3") { print "File exits already:\t$a - $t.mp3\n"; return; } else { print "Now downloading:\t$a - $t.mp3\n"; # system("aria2c", "--all-proxy=127.0.0.1:8889", "-q", "-o", "down_mp3/$a - $t.mp3", $l); system("aria2c", "-q", "-o", "down_mp3/$a - $t.mp3", $l); } }