/dev/null 2>&1
//
// Then you can type [ESC] and then ":wq" to exit and save and install your crontab (assuming the editor is vi(m))
// and assuming you have the right path to audioscrobbler.cron, the script should begin executing every 30 seconds.
// Be sure to change the value in AUDIOSCROBBLER_RDF below to whatever path and filename the cached audioscrobbler.xml
// file is saved under.
//
// Right now the cron script is dependent on the wget program, there are plenty of other
// ways of doing this, such as using curl/lynx/links or using php or perl. Also note that
// I haven't actually tested any of this, so please let me know if something is wrong :)
//
// Define the URL/path to user's Audioscrobbler XML/RDF feed
// ******************************************************** ENTER YOUR USERNAME BELOW
define('AUDIOSCROBBLER_RDF', 'http://ws.audioscrobbler.com/rdf/history/USERNAME');
// Truncate (shorten) song titles?
define('TRUNCATE', FALSE);
define('TRUNCATE_LENGTH', 32);
// Try to open Audioscrobbler feed
if (!($fp = fopen(AUDIOSCROBBLER_RDF, "r"))) { die("could not open Audioscrobbler feed"); }
while ($data = fread($fp, 4096)) { $rdf_content .= $data; }
fclose($fp);
// Begin parsing through
preg_match_all("'(.*?)'si", $rdf_content, $songs); $songs = $songs[1];
preg_match_all("'(.*?)'si", $rdf_content, $links); $links = $links[1];
// Print out last 10 songs
for ($i = 1; $i < count($songs); $i++) {
list($artist, $title) = explode(' - ', $songs[$i]);
if (TRUNCATE) {
$truncated_song = substr($title, 0, TRUNCATE_LENGTH);
if (strlen($title) != strlen($truncated_song)) $truncated_song .= '...';
echo "$truncated_song \n";
} else {
echo "$artist - $title \n";
}
}
?>