-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial checkin of the last.fm scrobbler service. * Added the conversion of the data. * Fixed conversion issue: now it is converted in the service. Added the call to the voice command. Updated the translations. (this has to be fixed for other languages. * Some updates: - Show on the bottom left - No voice command - Dealing with error cases
- Loading branch information
Showing
5 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(function(annyang) { | ||
'use strict'; | ||
|
||
function ScrobblerService($http, $q) { | ||
var service = {}; | ||
|
||
service.getCurrentTrack = function () { | ||
var deferred = $q.defer(); | ||
if (config.lastfm.user && config.lastfm.key) { | ||
var url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user="+config.lastfm.user+"&api_key="+config.lastfm.key+"&limit=1&format=json"; | ||
|
||
$http.get(url).then(function(response) { | ||
if (response.data.error){ | ||
// If there is an error with the request (excluding network errors) | ||
console.log("Scrobbler Error: ", response.data.message); | ||
deferred.reject(response); | ||
} else if (typeof response.data.recenttracks.track[0]["@attr"] == "object"){ | ||
// If there is a track currently playing | ||
var track = response.data.recenttracks.track[0]; | ||
deferred.resolve({ | ||
title: track.name, | ||
artist: track.artist["#text"] || "Unknown", | ||
album: track.album["#text"] || "", | ||
cover: track.image[1]["#text"], | ||
}); | ||
} else { | ||
// Either there was a network error or there is no song currently playing | ||
deferred.reject(response); | ||
} | ||
}); | ||
} | ||
return deferred.promise; | ||
} | ||
|
||
return service; | ||
} | ||
|
||
angular.module('SmartMirror') | ||
.factory('ScrobblerService', ScrobblerService); | ||
}(window.annyang)); |