Skip to content

Instantly share code, notes, and snippets.

@dgw dgw/lastfm.php forked from dewey/lastfm.php
Last active Aug 29, 2015

Embed
What would you like to do?
Forked from dewey and changed to display "last listened to" if the latest track in the feed is not currently playing.
#!/usr/bin/php
<?php
$doc = new DOMDocument();
$doc->load("http://ws.audioscrobbler.com/2.0/user/voyagerfan5761/recenttracks.xml?limit=1");
$arrFeeds = array();
foreach ($doc->getElementsByTagName('track') as $node) {
$itemRSS = array (
'artist' => $node->getElementsByTagName('artist')->item(0)->nodeValue,
'name' => $node->getElementsByTagName('name')->item(0)->nodeValue,
'nowplaying' => ($node->attributes->getNamedItem('nowplaying')) ? true : false
);
array_push($arrFeeds, $itemRSS);
}
$nowplaying = ($arrFeeds[0]['nowplaying']) ? 'is listening' : 'last listened';
echo "/me $nowplaying to {$arrFeeds[0]['name']} by {$arrFeeds[0]['artist']}.";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.