Skip to content

Instantly share code, notes, and snippets.

@nicoknoll
Created February 20, 2013 16:37
Show Gist options
  • Save nicoknoll/4996898 to your computer and use it in GitHub Desktop.
Save nicoknoll/4996898 to your computer and use it in GitHub Desktop.
<?php
function getTracks() {
$data = json_decode(file_get_contents('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=derstadtpirat&api_key=LASTFMAPIKEY&format=json&limit=70&nowplaying=true'), true);
$tracks = array();
foreach($data['recenttracks']['track'] as $track) {
if($track['image'][0]['#text'] != '') {
$tracks[] = array(
'name' => trim($track['name']),
'album' => trim($track['album']['#text']),
'artist' => trim($track['artist']['#text']),
'url' => trim($track['url']),
'image' => array(
'small' => $track['image'][0]['#text'],
'large' => $track['image'][3]['#text'],
)
);
}
}
return array_slice($tracks, 0, 45);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment