Skip to content

Instantly share code, notes, and snippets.

@dedenf

dedenf/lastfm

Last active Jan 16, 2017
Embed
What would you like to do?
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