抓取OVI的Mp3文件

execute("set names 'utf8'"); class album_mp3_ovi { public static function getContent($url, $timeout = 0) { $ch = curl_init(); // create cURL handle (ch) $useragent = " Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"; $header = array ( 'Accept-Language: zh-cn,zh;q=0.5', 'Connection: Keep-Alive', 'Cache-Control: no-cache' ); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); // execute return $result; } static function download_mp3($down_url, $cookie_file) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://account.music.ovi.com/cn/zh/pc/account/signin/"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POSTFIELDS, '__RequestVerificationToken='.self::getkey($cookie_file).'&joinType=ExistingUser&username=用户名&password=密码&signin=%E7%99%BB%E5%BD%95'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); $w = curl_exec($ch); //$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $down_url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); // curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $w = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, "https://account.music.ovi.com/cn/zh/pc/account/signout/"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); // curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); $w = preg_replace('/(/t+|/r|/n|/s{2,})/i', '', $w); preg_match('/Location: (.{0,200})Server:/Uis',$w, $arr); //$info = curl_getinfo($ch); return $arr[1]; } function getkey($cookie_file) { $url = "https://account.music.ovi.com/cn/zh/pc/account/signin/"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); curl_setopt($ch, CURLOPT_HEADER , 0); //写cookie curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); curl_close($ch); $result = preg_replace('/(/t+|/r|/n|/s{2,})/i', '', $result); preg_match('/getarray("SELECT * FROM ovi_no_match_second WHERE mp3_download=0 ORDER BY source_id LIMIT $min,$max"); foreach ($list as $item) { $url = album_mp3_ovi::download_mp3("https://account.music.ovi.com/cn/zh/pc/product/download/".$item['source_id']."/",tempnam('./cookie/', 'account.music.ovi.com')); echo $url."/n"; if(substr($url, 0, 5)=='http:') { $is_down = album_mp3_ovi::download($url, $item['source_id']); if($is_down) { $db->execute('UPDATE ovi_no_match_second SET mp3_download=1 WHERE source_id='.$item['source_id']); } else { $db->execute('UPDATE ovi_no_match_second SET mp3_download=2 WHERE source_id='.$item['source_id']); } } else { $db->execute('UPDATE ovi_no_match_second SET mp3_download=3 WHERE source_id='.$item['source_id']); } } } else { echo "Parameters format must be singer ID 'min-max'"; } } else { echo "Parameters format must be singer ID 'min-max'"; } //var_dump(album_mp3_ovi::download_mp3('https://account.music.ovi.com/cn/zh/pc/product/download/12185884',999)); echo "Mission accomplished!"; ?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值