Hi there!

I'm in a middle of programming a drupal based radio station and wonder if someone can tell me

and easy way to take the songs&band title and put it on the block.

I'm working rith winamp and shoutcast.

I saw a very nice example at http://kwhl.com - which also have a link to buy it in amazon.

What is the best way to get this done? How they did it?

thanks

ori

Comments

lyricnz’s picture

Have you looked at http://drupal.org/handbook/modules/station and http://groups.drupal.org/radio ?

If these modules don't have what you need, then your problem is twofold. You need:

- a way for the Drupal server to query the backend (shoutcast?) and find out what's currently playing. Presumably it's got some API? Check the module.

- a way to present this on the page, presumably in a block, maybe with AJAX refresh

Look at the links above, then post here if you're no closer to a solution.

pbull’s picture

Shoutcast server provides a very simple method to request real-time stats as an XML file. Model your URL as follows:
http://adminuser:adminpass@example.com:port/admin.cgi?mode=viewxml

You should look at the FeedAPI module (http://drupal.org/project/feedapi) as a way to query that feed.

The SONGTITLE and SONGURL elements in the XML can be mapped to CCK fields. Note that your encoder or radio station software needs to be configured to send the song/artist to the Shoutcast server, otherwise those elements are going to be empty.

lyricnz’s picture

While the tip about shoutcast is useful, you only need feedapi/cck if you intend to create a node with this information. Otherwise just load it into XML, parse it with SimpleXML, and put it into a short-lifetime cache.

lyricnz’s picture

I haven't looked at it, and it seems rather unmaintained, but see http://drupal.org/project/shoutcast

pbull’s picture

Good point... if you don't need to maintain playlists and are just looking to display the real-time data, then there's no need to create a node.

or’s picture

can you please tell me what should I learn in order to accomplish this?

I mean: "Otherwise just load it into XML, parse it with SimpleXML, and put it into a short-lifetime cache."

how do I make it?

lyricnz’s picture

You need to write a simple module, probably a dozen lines of code. The module would be configured with a shoutcast-server URL (say http://adminuser:adminpass@example.com:port/admin.cgi?mode=viewxml)

This module would also provide a block for your pages. In order to generate the block, the module would simple look in the Drupal cache, see if there was a recent copy (of the XML), and if so use it. If not, it would pull the XML from the backend and put it into the cache.

Either way, the result would then be formatted (via a theming function, with a default implementation in the module) to produce something presentable. If you talk nicely to me, and provide me with a shoutcast server to test, I might do this for you.

or’s picture

At the end iv'e putted this bit of PHP code in a block

$open = fsockopen("ipnumeber","port"); 
if ($open) { 
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n"); 
$read = fread($open,1000); 
$text = explode("content-type:text/html",$read); 
$text = explode(",",$text[1]); 
} else { $er="Connection Refused!"; } 
if ($text[1]==1) { $state = "Up";
echo "<font face=verdana size=1> 
 $text[6] playing now:
</font>"; } else { $state = "Down";
echo "<font face=verdana size=1>
server is not up</font>"; } 
if ($er) { echo $er; exit; } 

and it's work well!
so thank you, I very much appreciate your help!
so for now I talk to nice anyway :)
cheers

lyricnz’s picture

There are many optimizations you could/should make to this code. At the very least, cache your data (say, for 30 seconds), so every single web-user doesn't cause a hit to the shoutcast server. See http://www.lullabot.com/articles/a_beginners_guide_to_caching_data

codemodul’s picture

hey, i know this thread is old but i made a little module wich provides 3 blocks.

2 x "now playing" (one with a link to the radio page and one w/)
1 x "song history"

there are also some config options.

but it's my very first module i wrote for drupal and i'm very unsure if it's good enough to upload/share. there you go for screenshots. drop me a line if you're interested in using it. i'll use it on my own radio project soon.

http://img43.imageshack.us/i/radiostatsnowplaying.png/
http://img22.imageshack.us/i/radiostatshistory.png/
http://img43.imageshack.us/i/radiostatsconfig.png/

greetings

ps: i didn't figured out yet how to enable caching correctly on this. i'll learn i guess ;-)

l0c0luke’s picture

I did need the nodes, so I just changed the XML that shoucast provides to make it so the FeedAPI module CAN read it. A little auto block refresh, some views, and a fast acting cron gives your page a rather dynamic and live feel.

http://lukeollett.com/blog/2009/08/18/drupal-6-shoutcast-rss/