|
楼主 |
发表于 2005-10-20 00:35:53
|
显示全部楼层
Post by homesp
#!/usr/bin/perl -I/usr/lib/xlyrics
# parse arguments
@ARGV < 1 && print("Usage: downloadlyrics.pl music [download_dir] [more_lyrics?] \n") && exit(-1);
$music = $ARGV[0];
if(@ARGV > 1){
$lyrics_file = $ARGV[1];
}else{
$lyrics_file = "$ARGV[0].lrc";
}
use HTTP:ite;
$http = new HTTP:ite;
# search lyrics in basic database
%vars = (
"souqu" => "¸èÃû",
"souci" => $music,
"ku" => "db",
"B1" => "Ìá½»"
);
$http->prepare_post(\%vars);
$http->request("http://bbs.hjqing.com/lrc/index.asp")
or die "Unable to get document: $!";
if($http->body() =~ /ûÓÐÄãÏëÕҵĸè´Ê/){
# try the addtion database
glob $http = new HTTP:ite;
%vars = (
"souqu" => "¸èÃû",
"souci" => $music,
"ku" => "dbadd",
"B1" => "Ìá½»"
);
$http->prepare_post(\%vars);
$http->request("http://bbs.hjqing.com/lrc/index.asp")
or die "Unable to get documents $!";
$http->body() =~ /ûÓÐÄãÏëÕҵĸè´Ê/ && die("find nothing");
}
@lines = split(/\n/, $http->body());
open(INFOFILE, ">/tmp/$music.lrc.info")
or die "Can not open info file to wirte";
open(OUTFILE, ">$lyrics_file")
or die "Can not open lyrics file to write";
$count = 0;
for($index = 0; $index < @lines; $index ++){
if($lines[$index] =~ /^\[.*$/){
# write the lyrics content to the file
$lines[$index] =~ s/<\/textarea>//;
print OUTFILE ("$lines[$index]\n");
}elsif($lines[$index] =~ /½øÒ»²½ËÑË÷/){
$index ++;
for(; $index < @lines; $index ++){
# add more infomation
if($lines[$index] =~ /<\/textarea>/){
last;
}else{
print INFOFILE ("$lines[$index]\n");
$count ++;
}
}
# just get lyrics list or first download and more than one file found
if(@ARGV == 3
&& ($ARGV[2] == "list" || ($ARGV[2] == "first" && $count > 1))){
close(OUTFILE);
unlink($lyrics_file);
exit;
}
}
}
downloadlyrics.pl里面怎么乱码?
因为里面的编码是gb2312,你的环境是utf8? |
|