Skip to content

Instantly share code, notes, and snippets.

@ormanya
Forked from dewey/lastfm.php
Last active August 30, 2018 23:20
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 ormanya/d0f21880ec015a807b9187c48e6715b8 to your computer and use it in GitHub Desktop.
Save ormanya/d0f21880ec015a807b9187c48e6715b8 to your computer and use it in GitHub Desktop.
Last.fm "now playing" script for Textual. Installation: Replace 'ormanya' with your Last.fm username and 'apikey' with your last.fm api key. Copy this script to ~/Library/Application Scripts/com.codeux.apps.textual/lastfm.php Usage:/lastfm
#!/usr/bin/php
<?php
$doc = new DOMDocument();
$doc->load("http://ws.audioscrobbler.com/2.0/?api_key=apikey0&method=user.getRecentTracks&limit=1&user=ormanya&limit=1&format=xml");
$arrFeeds = array();
foreach ($doc->getElementsByTagName('track') as $node) {
$itemRSS = array (
'artist' => $node->getElementsByTagName('artist')->item(0)->nodeValue,
'name' => $node->getElementsByTagName('name')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
}
echo ("/me is listening 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