From 5649bc6f4f3328e75851863a548568918dcabd6a Mon Sep 17 00:00:00 2001 From: atomaka Date: Fri, 14 Oct 2011 05:17:04 -0400 Subject: [PATCH] Correctly process Lastfm songs that are currently playing and display that information to the page. --- cronjobs/index_data.php | 6 +++++- public_html/index.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cronjobs/index_data.php b/cronjobs/index_data.php index ab64a96..2927b82 100644 --- a/cronjobs/index_data.php +++ b/cronjobs/index_data.php @@ -101,11 +101,15 @@ function lastfm() { $cover = (is_array($latestSong->image)) ? 'img/lastfm/blank_album64.png' : (string)$latestSong->image[1]; + $time = (isset($latestSong->attributes()->nowplaying) && (bool)$latestSong->attributes()->nowplaying) ? + 0 : strtotime($latestSong->date . ' UTC'); + + print_r($time); return array( 'song' => (string)$latestSong->name, 'artist' => (string)$latestSong->artist, - 'time' => strtotime($latestSong->date . ' UTC'), + 'time' => $time, 'url' => (string)$latestSong->url, 'cover' => $cover, ); diff --git a/public_html/index.php b/public_html/index.php index 52fb43e..b0cfff6 100644 --- a/public_html/index.php +++ b/public_html/index.php @@ -98,7 +98,7 @@ while($link = $links->fetch_object()) { Andrew Tomaka's Last.fm lastfm->song ?>
by lastfm->artist ?>

- lastfm->time) ?> ago
+ lastfm->time == 0) ? 'currently playing' : time_since($data->lastfm->time) . 'ago' ?>