I was getting pretty excited about what work on a nowplaying.module (http://groups.drupal.org/node/3104) but haven't heard anything lately. I'm building a new station site and need something like this to build the station's catalog and display recently played tracks from uploaded HTML files generated by the station's automation software.
As it turns out, I probably won't be able to rely on getting data out of the station's automation software in XML format. Since I'm stuck with HTML, I'd like to reproduce what Bram outlined but against remote HTML track lists.
I've written the following to parse a remote recent track list and save an include file. Now I'd like to convert this to a Drupal module.
I have an idea of the module settings to create (URL, HTML element around tracks, number of tracks to display, etc.). I'll need to efficiently handle db inserts, block display of recent tracks (1-10), extended playlist node (today's playlist or past N hours), and add a cron hook to keep everything up-to-date.
Basically I'm looking for a little guidance and perhaps coordination with any similar efforts.
Thanks!
<?php
error_reporting(E_ERROR);
/**
* nowplaying.php
<em>
* This is a temporary formatting script for a station's short playlist
* Eventually this script be converted to a proper Drupal module
*/
$ch = curl_init('http://radiostation.com/NowPlaying.htm');
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$includefile = '/home/user/drupal5/sites/radiostation.com/files/NowPlaying.inc';
$delim = '-';
$blocktitle = '<h2>recently played</h2>';
$trackformat = '<span class="%s">%s</span> ';
$timeformat = 'h:i';
$dataorder = array('time', 'artist', 'song');
$trackcount = 7;
// If there weren't any errors getting the file
if ($content = curl_exec($ch)) {
preg_match_all("/<li>(.</em>?)<\/li>/i", $content, $matches);
foreach ($matches[0] as $k => $v) {
$nowplaying[] = explode('-', strip_tags($v));
}
$content = build_list($nowplaying, $dataorder, $trackformat, $trackcount, $blocktitle);
write_file($includefile, $content);
}
curl_close($ch);
//Build an HTML unordered list to display tracks
function build_list($song, $order, $format, $count, $title) {
$list = "$title\n<ul>\n";
for ($i=0; $i<$count; $i++) {
$list .= '<li>';
for ($n=0; $n<count($order); $n++) {
if ($order[$n] == 'time') {
$song[$i][$n] = format_time($song[$i][$n]);
}
$list .= sprintf($format, $order[$n], $song[$i][$n]);
}
$list .= "</li>\n";
}
$list .= "</ul>";
return $list;
}
function format_time($time) {
global $timeformat;
$parts = explode(':', $time);
$time = date($timeformat, mktime($parts[0], $parts[1], $parts[2]));
return $time;
}
//Save the parsed playlist as a local HTML include file
function write_file($file, $content) {
$fh = fopen($file, 'w');
if (fwrite($fh, $content)) {
fclose($fh);
return true;
} else {
fclose($fh);
return false;
}
}
?>
Comments
-
-
RE: Now Playing, and a my own question
Hey, Thumb.
I know this isn't what you were asking about, but: we ended up doing a manual override with Javascript. You can see the results at http://wkze.com/static/wkze/playlist.html - it allows DJs to log in based on their Drupal user settings and manually enter "now playing" tracks, which are then appended to Station in place of the auto-generated tracks.
Now, I have a question for you or anyone: How can I keep the » listen to previous | subscribe to podcast message (e.g. https://secure.wkze.com/node/129) from displaying, since we don't use those features?
Thanks for any help you can provide,
Bram
--
Bram Moreinis, Principal
Beyond The Box Web Solutions
http://www.beyondboxweb.com
(w) 845-750-6204
u
http://gamefacewebdesign.com
Use CSS to hide those links
I imagine that the links or the HTML container tag around the links can be styled with the CSS display property. Well, actually, it's not that easy. The class around those links is .links, which is used for a lot of different things in Drupal (taxonomy links, etc.). There doesn't appear to be any station.module specific CSS to target just .links on station nodes.
You'll need to do a bit of theming to target just station nodes--either strip the links block altogether, or insert a custom CSS class that you can style.
RE: Targetting .links on station nodes
Yea, thumb, I'd noticed that there wasn't any specific CSS - else I'd have put the puppy to bed in a heartbeat.
Is there some Station Module page template somewhere I can strip the links block from, or insert a CSS class into? I have no idea how to get to it, if so.
-Bram
--
Bram Moreinis, Principal
Beyond The Box Web Solutions
http://www.beyondboxweb.com
(w) 845-750-6204
http://gamefacewebdesign.com
i'd replied to your query
i'd replied to your query via google chat but the easy way is to just disable the audio_archive module.
oh, yeah, duh... that'll
oh, yeah, duh... that'll work too :-)
station, not audio
that should have read station_archive module...
Theme Override
There should be a way to override the function used to display the tags in your theme. http://drupal.org/node/55126
RE: Station, not audio"
Drewish, we didn't have station_archive module installed, either. just station, station live, and station schedule.
Any other ideas?
-Bram
--
Bram Moreinis, Principal
Beyond The Box Web Solutions
http://www.beyondboxweb.com
(w) 845-750-6204
http://gamefacewebdesign.com