JSFiddle - React, Tailwind, and code Playground
by D S
JavaScript
var artNme = "Adele";
var tckNme = "Hello"
var currentCoverURL = "";
getArtwork(tckNme, artNme)
function getArtwork(tckNme, artNme) {
var url = "https://itunes.apple.com/search?term=" + tckNme + "&limit=10&media=music&entity=musicTrack";
$.getJSON(url, function(data) {
$(data.results).each(function() {
if (this.artistName == artNme) {
currentCoverURL = this.artworkUrl30;
currentCoverURL = changeImageSizeTo200(currentCoverURL);
console.log(currentCoverURL);
}
});
}).fail(function() {
console.log("Data could not be loaded: A valid iTunes track ID is not provided! ");
});;
}
function changeImageSizeTo200(url) {
let splitArray = url.split("/");
splitArray[splitArray.length - 1] = splitArray[splitArray.length - 1].replace("30x30", "250x250");
return splitArray.join("/");
}