Skip to content

Instantly share code, notes, and snippets.

@dgw
Forked from dewey/lastfm.php
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgw/de9a364ac50dd109bcae to your computer and use it in GitHub Desktop.
Save dgw/de9a364ac50dd109bcae to your computer and use it in GitHub Desktop.
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