-
-
Save PaulGuo/4527776 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env php | |
<?php | |
function fetch_page($url, $timeout = 5) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
$songs = array(); | |
for ($i=0;$i<5;$i++) { | |
$body = fetch_page("http://douban.fm/j/mine/playlist?type=n&channel=0"); | |
$list = json_decode($body); | |
foreach ($list->song as $song) { | |
$songs[$song->url] = $song; | |
} | |
} | |
foreach (array_values($songs) as $i=>$song) { | |
echo $i." ".$song->title, " by ", $song->artist,"\n"; | |
} | |
system("mpg123 --gapless -C ". join(array_keys($songs)," ")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment