Advertisement
NickG

LastFmCtrl

May 25th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function LastFmCtrl($scope, $http, $timeout) {
  2.     $scope.tracks = [];
  3.     !function tick() {
  4.         $http({method: 'GET', url: 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=nickelpro&api_key=ffd9e00b1647c0824ce7cb0a0aa44ce1&format=json'}).
  5.         success(function(data, status, headers, config) {
  6.             $scope.tracks = [];
  7.             for(var i=0;i<data.recenttracks.track.length;i++) {
  8.                 var track = data.recenttracks.track[i];
  9.                 if (typeof track.date != 'undefined') {
  10.                     track.time = moment.unix(track.date.uts).fromNow();
  11.                 } else {
  12.                     track.time = 'Now Playing';
  13.                 }
  14.                 track.artist_url = track.url.substring(0, track.url.lastIndexOf('/')-2);
  15.             }
  16.             $scope.tracks = data.recenttracks.track;
  17.             $timeout(tick, 5000);
  18.         }).
  19.         error(function(data, status, headers, config) {
  20.             $timeout(tick, 5000);
  21.         });
  22.     }();
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement