PHP音乐采集(部分代码)
程序员文章站
2022-04-28 14:18:45
<?php
set_time_limit(0);
mysql_connect("localhost","root","");
mysql_select_db("music_36g");
$ip = '127.0.0.1';
function _getip()
{
$ip = getenv("remote_addr");
$ip1 = getenv("http_x_forwarded_for");
$ip2 = getenv("http_client_ip");
($ip1) ? $ip = $ip1 : null ;
($ip2) ? $ip = $ip2 : null ;
return $ip;
}
function makepassword($length=10)
{
$password = '';
$chars =
array
(
"1","2","3","4","5","6","7","8","9","0",
"a","a","b","b","c","c","d","d","e","e","f","f","g","g","h","h","i","i","j","j",
"k","k","l","l","m","m","n","n","o","o","p","p","q","q","r","r","s","s","t","t",
"u","u","v","v","w","w","x","x","y","y","z","z"
);
$count = count($chars) - 1;
srand((double)microtime()*1000000);
for($i = 0; $i < $length; $i++)
{
$password .= $chars[rand(0, $count)];
}
return($password);
}
if ( _getip() != $ip )
{
exit("can't run!");
}
for ( $i=2;$i<5769;$i++)//52738
{
$url = "http://music.36g.net/specialinfo/showspecial".$i.".htm";
$file = @fopen($url,'rb');
if ( $file )
{
$makefile = $buffer = "";
$buffer = "";
while ($buffer = fread($file,4096))
{
$makefile = $makefile.$buffer;
}
@fclose($file);
preg_match("/src=\/uppic\/(.*) width=135/",$makefile,$pic);#图片
#下载图片
if ( $pic[1]!='es/nophoto.gif' )
{
$p_url = "http://music.36g.net/uppic/".$pic[1];
$file2 = fopen($p_url,'rb');
if ( $file2 )
{
$buffer2 = $makefile2 = "";
while ($buffer2 = fread($file2,4096))
{
$makefile2 = $makefile2.$buffer2;
}
fclose($file2);
$filename2 = './pic/'.$pic[1];
$fp2 = fopen ($filename2,'w+');
fwrite($fp2,$makefile2);
fclose($fp2);
}
}
else
{
$pic[1] = '';
}
preg_match("/专辑:<\/strong>(.*)<\/td><td width=(\d+) rowspan=6/",$makefile,$name);#专辑名称
$name = addslashes($name[1]);
preg_match("/歌手:<\/strong>(.*)<\/td><\/tr><tr><td>/",$makefile,$songer);#歌手名称
preg_match("/(.*)<\/td><\/tr><tr><td>/",$songer[1],$songer_name);#歌手名称
preg_match("/发行公司:<\/strong>(.*)/",$songer[1],$company);#发行公司
preg_match("/发行时间<\/strong>:(.*)<\/td> <\/tr>/",$makefile,$date);#发行时间
preg_match("/(.*)<\/td>/",$date[1],$date2);#发行时间
preg_match("/<\/strong>(.*)/",$date[1],$language);#发行语言
preg_match("/专辑简介:<\/strong><\/td> <td colspan=2>(.*)<\/td><\/tr><\/table><br>/",$makefile,$descript);#专辑简介
$songer_name = addslashes($songer_name[1]);
$company= addslashes($company[1]);
$descript= addslashes($descript[1]);
#取得歌曲id
preg_match_all("/download1\.asp\?id=(\d+)&which=bakdownurl1/",$makefile,$id2);#歌曲id
$num = count($id2[1]);
for ($jj=0;$jj<$num;$jj++)
{
$sql = " insert into tx_music set musicid='".$id2[1][$jj]."',specialid='$i',specialname='$name',songername='$songer_name',orderbyid='".$id2[1][$jj]."' ";
//echo $id2[1][$jj]."<br>";
mysql_query($sql);
}
//echo $descript."<br><br>";
$sql = " insert into tx_special set orderbyid='$i',specialid='$i',specialname='$name',songername='$songer_name',company='$company',date='$date2[1]',language='$language[1]',picture='$pic[1]',musicnum='$num',createdate='".time()."',description='$descript' ";
echo $sql;
mysql_query($sql);
}
}
?>
set_time_limit(0);
mysql_connect("localhost","root","");
mysql_select_db("music_36g");
$ip = '127.0.0.1';
function _getip()
{
$ip = getenv("remote_addr");
$ip1 = getenv("http_x_forwarded_for");
$ip2 = getenv("http_client_ip");
($ip1) ? $ip = $ip1 : null ;
($ip2) ? $ip = $ip2 : null ;
return $ip;
}
function makepassword($length=10)
{
$password = '';
$chars =
array
(
"1","2","3","4","5","6","7","8","9","0",
"a","a","b","b","c","c","d","d","e","e","f","f","g","g","h","h","i","i","j","j",
"k","k","l","l","m","m","n","n","o","o","p","p","q","q","r","r","s","s","t","t",
"u","u","v","v","w","w","x","x","y","y","z","z"
);
$count = count($chars) - 1;
srand((double)microtime()*1000000);
for($i = 0; $i < $length; $i++)
{
$password .= $chars[rand(0, $count)];
}
return($password);
}
if ( _getip() != $ip )
{
exit("can't run!");
}
for ( $i=2;$i<5769;$i++)//52738
{
$url = "http://music.36g.net/specialinfo/showspecial".$i.".htm";
$file = @fopen($url,'rb');
if ( $file )
{
$makefile = $buffer = "";
$buffer = "";
while ($buffer = fread($file,4096))
{
$makefile = $makefile.$buffer;
}
@fclose($file);
preg_match("/src=\/uppic\/(.*) width=135/",$makefile,$pic);#图片
#下载图片
if ( $pic[1]!='es/nophoto.gif' )
{
$p_url = "http://music.36g.net/uppic/".$pic[1];
$file2 = fopen($p_url,'rb');
if ( $file2 )
{
$buffer2 = $makefile2 = "";
while ($buffer2 = fread($file2,4096))
{
$makefile2 = $makefile2.$buffer2;
}
fclose($file2);
$filename2 = './pic/'.$pic[1];
$fp2 = fopen ($filename2,'w+');
fwrite($fp2,$makefile2);
fclose($fp2);
}
}
else
{
$pic[1] = '';
}
preg_match("/专辑:<\/strong>(.*)<\/td><td width=(\d+) rowspan=6/",$makefile,$name);#专辑名称
$name = addslashes($name[1]);
preg_match("/歌手:<\/strong>(.*)<\/td><\/tr><tr><td>/",$makefile,$songer);#歌手名称
preg_match("/(.*)<\/td><\/tr><tr><td>/",$songer[1],$songer_name);#歌手名称
preg_match("/发行公司:<\/strong>(.*)/",$songer[1],$company);#发行公司
preg_match("/发行时间<\/strong>:(.*)<\/td> <\/tr>/",$makefile,$date);#发行时间
preg_match("/(.*)<\/td>/",$date[1],$date2);#发行时间
preg_match("/<\/strong>(.*)/",$date[1],$language);#发行语言
preg_match("/专辑简介:<\/strong><\/td> <td colspan=2>(.*)<\/td><\/tr><\/table><br>/",$makefile,$descript);#专辑简介
$songer_name = addslashes($songer_name[1]);
$company= addslashes($company[1]);
$descript= addslashes($descript[1]);
#取得歌曲id
preg_match_all("/download1\.asp\?id=(\d+)&which=bakdownurl1/",$makefile,$id2);#歌曲id
$num = count($id2[1]);
for ($jj=0;$jj<$num;$jj++)
{
$sql = " insert into tx_music set musicid='".$id2[1][$jj]."',specialid='$i',specialname='$name',songername='$songer_name',orderbyid='".$id2[1][$jj]."' ";
//echo $id2[1][$jj]."<br>";
mysql_query($sql);
}
//echo $descript."<br><br>";
$sql = " insert into tx_special set orderbyid='$i',specialid='$i',specialname='$name',songername='$songer_name',company='$company',date='$date2[1]',language='$language[1]',picture='$pic[1]',musicnum='$num',createdate='".time()."',description='$descript' ";
echo $sql;
mysql_query($sql);
}
}
?>
上一篇: [NOI2013] 向量内积