Skip to content

Instantly share code, notes, and snippets.

@dedenf
Last active January 16, 2017 04:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dedenf/5097395 to your computer and use it in GitHub Desktop.
php script to fetch your last listened track on lastfm, an you can add this to your hooks or commit message $(lasfm)
#!/usr/bin/php
<?php
$url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=USERNAME&api_key=YOU_API_KEY&format=json&limit=1";
// Initializing curl
$ch = curl_init($url);
$options = array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array('Content-type: application/json')
);
curl_setopt_array( $ch, $options );
$result = curl_exec($ch);
$decode = json_decode($result, true);
$track = $decode['recenttracks']['track'];
echo "commiting the code while listening to ".($track['artist']['#text'] ." - ". $track['name'] );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment