Created
June 26, 2013 07:09
-
-
Save athurg/5865361 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type:text/html; charset=utf-8'); | |
if (!isset($_GET['email']) || !isset($_GET['password'])) { | |
echo 'Need Params!'; | |
die(); | |
} | |
echo <<<EOF | |
<form> | |
Email:<input name='email' value='{$_GET['email']}' /> | |
Pass:<input name='password' type='password' value='{$_GET['password']}' /> | |
Number:<input name='number' value='10' /> | |
<input type='submit' /> | |
</form> | |
EOF; | |
$email = $_GET['email']; | |
$password = $_GET['password']; | |
$number = $_GET['number']; | |
try { | |
$douban = new DoubanFm($email,$password); | |
$douban->login(); | |
} catch (\Exception $e) { | |
echo '<h2>Login Failed</h2>'; | |
echo $e->getMessage(); | |
die(); | |
} | |
$likes = $douban->getLiked($number); | |
if($likes->r!=0){ | |
echo "wrong"; | |
return; | |
} | |
$cmd=''; | |
foreach ($likes->songs as $song) { | |
$title = $song->title; | |
$title = str_replace('"', "'", $title); | |
$title = str_replace('(', "【", $title); | |
$title = str_replace(')', "】", $title); | |
$title = str_replace(array(' ',"\t",' '), "_", $title); | |
//扩展名 | |
$ext = strrchr($song->url, '.'); | |
//生成cmd | |
$cmd .= "curl -o \"{$title}{$ext}\" \"{$song->url}\"\n"; | |
} | |
echo "<textarea style='width:90%;height:86%'>{$cmd}</textarea>"; | |
return; | |
Class DoubanFm { | |
private $email; | |
private $password; | |
private $login_info; | |
private $token; | |
private $expire; | |
private $user_id; | |
public function __construct($email,$password) | |
{ | |
$this->email = $email; | |
$this->password = $password; | |
} | |
public function login() | |
{ | |
$PostData = array ( | |
"email"=>$this->email, | |
"password"=>$this->password, | |
"app_name"=>"radio_android",//!!IMPORTANT!! | |
"version"=>606,//!!IMPORTANT!! | |
); | |
$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'); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $PostData); | |
$result = curl_exec($ch); | |
$curlErrno = curl_errno($ch); | |
curl_close($ch); | |
if ($curlErrno) { | |
throw new \Exception(curl_error($ch)); | |
} | |
$login_info = json_decode($result); | |
if (!isset($login_info->token)) { | |
throw new \Exception('Login Failed!'.$login_info->err); | |
} | |
$this->token = $login_info->token; | |
$this->expire = $login_info->expire; | |
$this->user_id = $login_info->user_id; | |
return true; | |
} | |
public function getLiked($count=10){ | |
$url = "http://www.douban.com/j/app/radio/liked_songs?count={$count}" | |
."&token={$this->token}&user_id={$this->user_id}&expire={$this->expire}" | |
."&formats=aac&exclude=&version=606&app_name=radio_android&from=android_606_Douban"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_USERAGENT, 'Android-2.3.5'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); | |
$curlResponse = curl_exec($ch); | |
$curlErrno = curl_errno($ch); | |
if ($curlErrno) { | |
$curlError = curl_error($ch); | |
} | |
curl_close($ch); | |
return json_decode($curlResponse); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment