mopidy-musicbox-webclient/mopidy_musicbox_webclient/static/js/lastfm.js
woutervanwijk d4975abd02 small updates and fixes.
covers work better
filtered out unplayable tracks
mopidy-websettings/musicbox setting enabled
cleanup
2014-09-19 23:36:38 +02:00

50 lines
1.5 KiB
JavaScript

/**
* @author Wouter van Wijk
*/
API_KEY= 'b6d34c3af91d62ab0ae00ab1b6fa8733';
API_SECRET = '2c631802c2285d5d5d1502462fe42a2b';
var fmcache;
var lastfm;
$(window).load(function() {
// create a Cache object
fmcache = new LastFMCache();
// create a LastFM object
lastfm = new LastFM({
apiKey : API_KEY,
apiSecret : API_SECRET,
cache : fmcache
});
});
function getCover(nwartist, nwalbum, image, size) {
var defUrl = 'images/default_cover.png';
lastfm.album.getInfo({artist: nwartist, album: nwalbum}, {success: function(data){
for (var i = 0; i < data.album.image.length; i++) {
if ( data.album.image[i]['size'] == size) {
$(image).attr('src', data.album.image[i]['#text'] || defUrl);
}
}
}, error: function(code, message){
$(image).attr('src', defUrl);
// console.log('Error #'+code+': '+message);
}});
}
function getArtistImage(nwartist, image, size) {
var defUrl = 'images/user_24x32.png';
lastfm.artist.getInfo({artist: nwartist}, {success: function(data){
for (var i = 0; i < data.artist.image.length; i++) {
if ( data.artist.image[i]['size'] == size) {
$(image).attr('src', data.artist.image[i]['#text'] || defUrl);
}
}
}, error: function(code, message){
$(image).attr('src', defUrl);
// console.log('Error #'+code+': '+message);
}});
}