Skip to content

Instantly share code, notes, and snippets.

@ViralTaco
Forked from dewey/lastfm.php
Last active March 15, 2019 05:39
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 ViralTaco/5dc04877aedceb7fd30912519e1cca6e to your computer and use it in GitHub Desktop.
Save ViralTaco/5dc04877aedceb7fd30912519e1cca6e to your computer and use it in GitHub Desktop.
Last.fm "now playing" script for Textual.Installation: Copy this script to ~/Library/Application Scripts/com.codeux.irc.textual/lastfm.php Usage:/lastfm
#!/usr/bin/php
<?
# get api key here: https://www.last.fm/api/account/create
$api_key = "API_KEY_HERE";
$user = "HANDLE_HERE"; # case sensitive
$method = "method=user.getrecenttracks&user=";
$path = "http://ws.audioscrobbler.com/2.0/?";
$key = "&api_key=".$api_key;
$doc = new DOMDocument;
$doc->load($path.$method.$user.$key);
$node = $doc->getElementsByTagName('track')[0];
$track = [
'artist' => $node->getElementsByTagName('artist')[0]->nodeValue
, 'name' => $node->getElementsByTagName('name')[0]->nodeValue
];
echo "/me is listening to '"
.$track['name']."' by '"
.$track['artist']."'."
;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment