获取豆瓣FM加心歌曲
程序员文章站
2022-05-13 14:42:36
...
代码
<?php /** * * @category * @package * @listence Apache Listens,Version 2.0 * @version 2012-04-30 */ $email=isset($_GET['email'])?$_GET['email']:''; $password=isset($_GET['pwd'])?$_GET['pwd']:''; $count=isset($_GET['count'])?$_GET['count']:'10'; if(!preg_match('/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/',$email)){ return; } $login_info=login($email,$password); $liked_list= get_liked($login_info,$count); //var_dump($liked_list); if($liked_list->r!=0){ echo "wrong"; return; } $urls=''; $cmd=''; foreach($liked_list->songs as $songs){ $urls.=$songs->url.'<br/>'; $title=$songs->title; //文件名 $offset1=strrpos($songs->url,'/')+1; $tempName=substr($songs->url,$offset1); //扩展名 $offset2=strrpos($songs->url,'.'); $ext=substr($songs->url,$offset2); //生成cmd $cmd.='ren '.$tempName.' "'.$title.$ext.'"<br/>' ; } echo $urls; echo "<hr/>"; echo $cmd; return; function login($email,$password) { // if(s.contains("@")) // s2 = "email"; // else // s2 = "username"; $PostData = "email=".$email."&password=".$password."&app_name=radio_android&version=606&client=s%3Amobile%7Cy%3Aandroid+2.3.5%7Cf%3A606%7Cm%3ADouban%7Cd%3A-1629744272%7Ce%3Ahkcsl_cht_htc_desire_s"; $ch = curl_init("https://www.douban.com/j/app/login"); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_USERAGENT,'Android-2.3.5'); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CAINFO,'mozilla.pem'); /* fixed! */ //post curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData); $result = curl_exec($ch); curl_close($ch); $jsonObj=json_decode($result); return $jsonObj; } function get_liked($login_info=array(),$count){ $url='http://www.douban.com/j/app/radio/liked_songs?count='.$count.'&token='.$login_info->token. '&exclude=&version=606&client=s%3Amobile%7Cy%3Aandroid+2.3.5%7Cf%3A606%7Cm%3ADouban%7Cd%3A-1629744272%7Ce%3Ahkcsl_cht_htc_desire_s&app_name=radio_android&from=android_606_Douban'. '&user_id='.$login_info->user_id. '&expire='.$login_info->expire.'&formats=aac'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_USERAGENT,'Android-2.3.5'); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $curlResponse = curl_exec($ch); $curlErrno = curl_errno($ch); if ($curlErrno) { $curlError = curl_error($ch); } curl_close($ch); $jsonObj=json_decode($curlResponse); return $jsonObj; }
推荐阅读