Home  >  Article  >  php教程  >  获取豆瓣FM加心歌曲

获取豆瓣FM加心歌曲

PHP中文网
PHP中文网Original
2016-05-25 17:11:26960browse

代码

<?php
/**
 *
 * @category
 * @package
 * @listence Apache Listens,Version 2.0
 * @version  2012-04-30
 */
$email=isset($_GET[&#39;email&#39;])?$_GET[&#39;email&#39;]:&#39;&#39;;
$password=isset($_GET[&#39;pwd&#39;])?$_GET[&#39;pwd&#39;]:&#39;&#39;;
$count=isset($_GET[&#39;count&#39;])?$_GET[&#39;count&#39;]:&#39;10&#39;;

if(!preg_match(&#39;/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/&#39;,$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=&#39;&#39;;
$cmd=&#39;&#39;;
foreach($liked_list->songs as $songs){
    $urls.=$songs->url.&#39;<br/>&#39;;
    $title=$songs->title;
    //文件名
    $offset1=strrpos($songs->url,&#39;/&#39;)+1;
    $tempName=substr($songs->url,$offset1);
    //扩展名
    $offset2=strrpos($songs->url,&#39;.&#39;);
    $ext=substr($songs->url,$offset2);
    //生成cmd
    $cmd.=&#39;ren &#39;.$tempName.&#39; "&#39;.$title.$ext.&#39;"<br/>&#39;  ;
}
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,&#39;Android-2.3.5&#39;);

    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,&#39;mozilla.pem&#39;); /* 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=&#39;http://www.douban.com/j/app/radio/liked_songs?count=&#39;.$count.&#39;&token=&#39;.$login_info->token.
      &#39;&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&#39;.
      &#39;&user_id=&#39;.$login_info->user_id.
      &#39;&expire=&#39;.$login_info->expire.&#39;&formats=aac&#39;;
    $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,&#39;Android-2.3.5&#39;);

    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;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn