Instantly share code, notes, and snippets.

What would you like to do?
Raspberry Pi上听豆瓣电台的简易方法:sudo apt-get install mpg123 php5-cli,然后执行本程序即可
#!/usr/bin/env 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);
return $data;
$songs = array();
for ($i=0;$i<5;$i++) {
$body = fetch_page("");
$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)," "));

This comment has been minimized.

andyhuzhill commented Apr 12, 2013

I also write a python version according to this program.
It is very interesting to play with raspberry pi.


This comment has been minimized.

jiemar commented Jul 5, 2014


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment