mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-03 02:09:28 +01:00
Initial changes to the default template to use the cache
This commit is contained in:
@@ -1,110 +1,65 @@
|
||||
function getArtistInfo(name,imgElem,size,artistID) {
|
||||
var apikey = "690e1ed3bc00bc91804cd8f7fe5ed6d4";
|
||||
function getThumb(imgElem,id,type) {
|
||||
|
||||
// Get Data by Artist ID
|
||||
$.ajax({
|
||||
url: "http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&mbid="+ artistID +"&api_key="+ apikey+"&format=json",
|
||||
dataType: "jsonp",
|
||||
cache: true,
|
||||
success: function(data){
|
||||
if ( data.artist !== undefined ) {
|
||||
var imageUrl = data.artist.image[size]['#text'];
|
||||
}
|
||||
if (data.error) {
|
||||
getArtistName();
|
||||
} else {
|
||||
if ( data.artist === undefined || imageUrl == "" || imageUrl == undefined ) {
|
||||
var imageLarge = "#";
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
} else {
|
||||
var artist = data.artist.mbid;
|
||||
var artistBio = data.artist.bio.summary;
|
||||
var imageLarge = data.artist.image[4]['#text'];
|
||||
var imageUrl = data.artist.image[size]['#text'];
|
||||
}
|
||||
var artistBio = artistBio;
|
||||
var image = imgElem;
|
||||
var bio = $('#artistBio');
|
||||
$(image).attr("src",imageUrl).removeAttr("width").removeAttr("height").hide().fadeIn();
|
||||
if ( bio.length > 0 ) $(bio).append(artistBio);
|
||||
$(image).wrap('<a href="'+ imageLarge +'" rel="dialog" title="' + name + '"></a>');
|
||||
}
|
||||
}
|
||||
});
|
||||
// If not found get by Name
|
||||
function getArtistName() {
|
||||
$.ajax({
|
||||
url: "http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist="+ name +"&api_key="+ apikey+"&format=json",
|
||||
dataType: "jsonp",
|
||||
success: function(data){
|
||||
if ( data.artist !== undefined ) {
|
||||
var imageUrl = data.artist.image[size]['#text'];
|
||||
}
|
||||
if ( data.artist === undefined || imageUrl == "" ) {
|
||||
var imageLarge = "#";
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
} else {
|
||||
var artist = data.artist.name;
|
||||
var artistBio = data.artist.bio.summary;
|
||||
var imageLarge = data.artist.image[4]['#text'];
|
||||
var imageUrl = data.artist.image[size]['#text'];
|
||||
}
|
||||
var artistBio = artistBio;
|
||||
var image = imgElem;
|
||||
var bio = $('#artistBio');
|
||||
$(image).attr("src",imageUrl).removeAttr("width").removeAttr("height").hide().fadeIn();
|
||||
if ( bio.length > 0 ) $(bio).append(artistBio);
|
||||
$(image).wrap('<a href="'+ imageLarge +'" rel="dialog" title="' + artist + '"></a>');
|
||||
}
|
||||
});
|
||||
if ( type == 'artist' ) {
|
||||
var thumbURL = "getThumb?ArtistID=" + id;
|
||||
} else {
|
||||
var thumbURL = "getThumb?AlbumID=" + id;
|
||||
}
|
||||
// Get Data from the cache by Artist ID
|
||||
$.ajax({
|
||||
url: thumbURL,
|
||||
success: function(data){
|
||||
if ( data == "" ) {
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
}
|
||||
else {
|
||||
var imageUrl = data;
|
||||
}
|
||||
$(imgElem).attr("src",imageUrl).removeAttr("width").removeAttr("height").hide().fadeIn();
|
||||
$(imgElem).wrap('<a href="'+ imageLarge +'" rel="dialog" title="' + name + '"></a>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getAlbumInfo(name, album, elem,size) {
|
||||
var apikey = "690e1ed3bc00bc91804cd8f7fe5ed6d4";
|
||||
var dimensions = getOriginalWidthOfImg(this);
|
||||
var cover = $(elem);
|
||||
function getArtwork(imgElem,id,type) {
|
||||
|
||||
if ( dimensions <= 1) {
|
||||
// Get Data
|
||||
$.ajax({
|
||||
url: "http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=" + apikey + "&artist="+ name +"&album="+ album +"&format=json&callback=?",
|
||||
dataType: "jsonp",
|
||||
success: function(data){
|
||||
if ( data.artist !== undefined ) {
|
||||
var imageUrl = data.artist.image[size]['#text'];
|
||||
}
|
||||
if (data.album === undefined || imageUrl == "") {
|
||||
if ( elem.width() == 50 ) {
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
} else {
|
||||
var imageUrl = "interfaces/default/images/no-cover-art.png";
|
||||
}
|
||||
} else {
|
||||
var imageUrl = data.album.image[size]['#text'];
|
||||
var imageLarge = data.album.image[3]['#text'];
|
||||
}
|
||||
$(cover).error(function(){
|
||||
if ( elem.width() == 50 ) {
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
} else {
|
||||
var imageUrl = "interfaces/default/images/no-cover-art.png";
|
||||
}
|
||||
$(elem).css("background", "url("+ imageUrl+") center top no-repeat");
|
||||
});
|
||||
if ( imageUrl == "") {
|
||||
if ( elem.width() == 50 ) {
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
} else {
|
||||
var imageUrl = "interfaces/default/images/no-cover-art.png";
|
||||
}
|
||||
$(elem).css("background", "url("+ imageUrl+") center top no-repeat");
|
||||
}
|
||||
$(elem).css("background", "url("+ imageUrl+") center top no-repeat");
|
||||
$(elem).wrap('<a href="'+ imageLarge +'" rel="dialog" title="' + name + '"></a>');
|
||||
}
|
||||
});
|
||||
if ( type == 'artist' ) {
|
||||
var artworkURL = "getArtwork?ArtistID=" + id;
|
||||
} else {
|
||||
var artworkURL = "getArtwork?AlbumID=" + id;
|
||||
}
|
||||
// Get Data from the cache by Artist ID
|
||||
$.ajax({
|
||||
url: artworkURL,
|
||||
success: function(data){
|
||||
if ( data == "" ) {
|
||||
var imageUrl = "interfaces/default/images/no-cover-artist.png";
|
||||
}
|
||||
else {
|
||||
var imageUrl = data;
|
||||
}
|
||||
$(imgElem).attr("src",imageUrl).removeAttr("width").removeAttr("height").hide().fadeIn();
|
||||
$(imgElem).wrap('<a href="'+ imageLarge +'" rel="dialog" title="' + name + '"></a>');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getInfo(elem,id,type) {
|
||||
|
||||
if ( type == 'artist' ) {
|
||||
var infoURL = "getInfo?ArtistID=" + id;
|
||||
} else {
|
||||
var infoURL = "getInfo?AlbumID=" + id;
|
||||
}
|
||||
// Get Data from the cache by Artist ID
|
||||
$.ajax({
|
||||
url: infoURL,
|
||||
data_type: "jsonp",
|
||||
success: function(data){
|
||||
var summary = data['Summary'];
|
||||
$(elem).append(summary);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getOriginalWidthOfImg(img_element) {
|
||||
|
||||
Reference in New Issue
Block a user