Heim  >  Artikel  >  php教程  >  snoopy fetchlinks 应用实例(下载mp3)

snoopy fetchlinks 应用实例(下载mp3)

WBOY
WBOYOriginal
2016-06-06 20:00:431283Durchsuche

include Snoopy.class.php;//创建一个文件夹 if(!is_dir(Music/)) { mkdir(Music/); }$snoopy = new Snoopy;//获得所有链接 $snoopy-fetchlinks(http://mp3.baidu.com/m?f=msrn=tn=baidump3ct=134217728word=frankie+jlm=0); //print_r($snoopy-results);$re

include “Snoopy.class.php”;//创建一个文件夹
if(!is_dir(‘Music/’))
{
mkdir(‘Music/’);
}$snoopy = new Snoopy;//获得所有链接
$snoopy->fetchlinks(“http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word=frankie+j&lm=0″);
//print_r($snoopy->results);$result = array();
foreach($snoopy->results as $song)
{
preg_match(“/^(http:////)?([^//]+)/i”,$song,$matches);
$host = $matches[2];preg_match(“/[^/.//]+/.[^/.//]+$/”, $host, $matches);$matches[0] != ‘baidu.com’)
{
$result[] = $song;
}
}//print_r($result);unset($snoopy);//开始下载歌曲
foreach($result as $song)
{

//还得重来一次
$snoopy = new Snoopy;
$snoopy->fetchlinks($song);$arr = split(‘/’,$snoopy->results[0]);$file = fopen($snoopy->results[0],‘r’);
if(!$file)
{
echo ‘不能打开文件’;
exit;
}$count = count($arr);
$file_name = $arr[$count-1];$fh = fopen(‘Music/’.$file_name,‘w’);//保存文件
while (!feof ($file)) {
$content = fgets($file, 4096);
fwrite($fh,$content);
}
fclose($fh);
fclose($file);$file_name.“下载成功
“;
unset($snoopy);
}
?>

 

http://blog.csdn.net/ljw_army/archive/2009/12/02/4925425.aspx

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn