0): date_default_timezone_set('America/Indianapolis'); function clean($item) { if (strtolower($item) == "unknown" || $item == 0) return ""; return $item; } if (urldecode($_GET['secret']) != SECRET) exit(); // The record passed to this file by the plugin is processed into this array $current = array(); // Since not everyone obsessively fills out all the fields like I do... $current['artist'] = isset($_GET['artist']) ? htmlentities($_GET['artist']) : ""; $current['title'] = isset($_GET['title']) ? htmlentities($_GET['title']) : ""; $current['album'] = isset($_GET['album']) ? htmlentities($_GET['album']) : ""; $current['genre'] = isset($_GET['genre']) ? htmlentities(clean($_GET['genre'])) : ""; $current['year'] = isset($_GET['year']) ? htmlentities(clean($_GET['year'])) : ""; $current['duration'] = isset($_GET['duration']) ? htmlentities($_GET['duration']) : ""; $current['time'] = date('D, M jS - g:ia'); // Convert the duration, currently in seconds, into a readable format. if (strlen($current['duration']) > 0) { $min = floor($current['duration'] / 60); $sec = $current['duration'] % 60; if ($sec < 10) $sec = '0' . $sec; $current['duration'] = $min . "m " . $sec . "s"; } // Encode the data for output. $current_json = json_encode($current); // Import the existing data, so we can pull out the most recently played song $old_json = file('rhythmbox.json'); // If we have at least one song, then ditch the penultimate one. if (count($old_json) > 1) array_pop($old_json); // Extract out the remaining record -- we're going to assume it's already JSON'd $last_json = array_pop($old_json); $fp = fopen('/home/elecmahm/pub/rhythmbox.json', 'w'); fwrite($fp, $current_json . "\n"); fwrite($fp, $last_json); fclose($fp); else: $tracks = file('/home/elecmahm/pub/rhythmbox.json'); foreach($tracks as $index => $track) $tracks[$index] = json_decode($track); ?>