Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lioncat6 committed Feb 12, 2025
1 parent 5829ca2 commit cada8d5
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions scripts/artist.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,46 @@ async function fetchSpotifyArtist(artist) {
}

async function downloadSpotifyAlbums(artist) {
var albumCount = 0;
var currentOffset = 0;
var albumCount = 0;
var currentOffset = 0;

var fsatoken = localStorage.getItem("spfAccessToken");
const response = await fetch(`${apiUrl}/v1/artists/${artist}/albums?limit=50`, {
headers: {
Authorization: `Bearer ${fsatoken}`,
},
});

const data = await response.json();
console.log(data);
if (!data["error"]) {
albumCount = data["total"];
for (let album in data["items"]) {
spotifyAlbumList.push(data["items"][album]);
document.getElementById("loadingText").innerHTML = `Loading albums from spotify... (${album}/${albumCount})`;
}
} else {
if (data["error"]["status"] == 404) {
dispErr("Spotify artist not found!");
} else if (data["error"]["status"] == 400) {
dispErr("Invalid artist id!");
} else {
fsatoken = localStorage.getItem("spfAccessToken");
console.log(fsatoken);
if (!fsatoken) {
fsatoken = "";
}
if (fsatoken && fsatoken.length > 10) {
dispErr("Spotify Timeout | Please reload");
//location.reload()
}
}
}
while (currentOffset + 50 < albumCount) {
currentOffset += 50;
await new Promise((r) => setTimeout(r, 250));
var fsatoken = localStorage.getItem("spfAccessToken");
const response = await fetch(`${apiUrl}/v1/artists/${artist}/albums?limit=50`, {
const response = await fetch(`${apiUrl}/v1/artists/${artist}/albums?limit=50&offset=${currentOffset}`, {
headers: {
Authorization: `Bearer ${fsatoken}`,
},
Expand All @@ -168,10 +203,9 @@ async function downloadSpotifyAlbums(artist) {
const data = await response.json();
console.log(data);
if (!data["error"]) {
albumCount = data["total"];
for (let album in data["items"]) {
spotifyAlbumList.push(data["items"][album]);
document.getElementById("loadingText").innerHTML = `Loading albums from spotify... (${album}/${albumCount})`;
document.getElementById("loadingText").innerHTML = `Loading albums from spotify... (${Number(Number(album) + Number(currentOffset))}/${albumCount})`;
}
} else {
if (data["error"]["status"] == 404) {
Expand All @@ -190,44 +224,10 @@ async function downloadSpotifyAlbums(artist) {
}
}
}
while (currentOffset + 50 < albumCount) {
currentOffset += 50;
await new Promise((r) => setTimeout(r, 250));
var fsatoken = localStorage.getItem("spfAccessToken");
const response = await fetch(`${apiUrl}/v1/artists/${artist}/albums?limit=50&offset=${currentOffset}`, {
headers: {
Authorization: `Bearer ${fsatoken}`,
},
});

const data = await response.json();
console.log(data);
if (!data["error"]) {
for (let album in data["items"]) {
spotifyAlbumList.push(data["items"][album]);
document.getElementById("loadingText").innerHTML = `Loading albums from spotify... (${Number(Number(album) + Number(currentOffset))}/${albumCount})`;
}
} else {
if (data["error"]["status"] == 404) {
dispErr("Spotify artist not found!");
} else if (data["error"]["status"] == 400) {
dispErr("Invalid artist id!");
} else {
fsatoken = localStorage.getItem("spfAccessToken");
console.log(fsatoken);
if (!fsatoken) {
fsatoken = "";
}
if (fsatoken && fsatoken.length > 10) {
dispErr("Spotify Timeout | Please reload");
//location.reload()
}
}
}
}
if (!multiple) {
downloadMusicBrainzAlbums();
}
}
if (!multiple) {
downloadMusicBrainzAlbums();
}
}

async function downloadMusicBrainzAlbums() {
Expand Down Expand Up @@ -337,7 +337,7 @@ function normalizeText(text) {
if (textRemovedChars == "") {
textRemovedChars = normalizedText;
}
return textRemovedChars
return textRemovedChars;
}

var green = 0;
Expand Down Expand Up @@ -434,14 +434,14 @@ function processAlbums() {
if (finalTrackCount != spotifyTrackCount) {
iconsHtml += `<div class="numDiff" title="This release has a differing track count! [SP: ${spotifyTrackCount} MB: ${finalTrackCount}]">#</div>`;
}
if (finalReleaseDate == "" || finalReleaseDate == undefined || !finalReleaseDate){
if (finalReleaseDate == "" || finalReleaseDate == undefined || !finalReleaseDate) {
const spotifyYear = spotifyReleaseDate.split("-")[0];
const spotifyMonth = spotifyReleaseDate.split("-")[1];
const spotifyDay = spotifyReleaseDate.split("-")[2];
const editNote = encodeURIComponent(`Added release date from Spotify using SAMBL: ${spotifyUrl}`);
iconsHtml += `<a class="dateDiff" href="https://musicbrainz.org/release/${finalMBID}/edit?events.0.date.year=${spotifyYear}&events.0.date.month=${spotifyMonth}&events.0.date.day=${spotifyDay}&edit_note=${editNote}" title="This release is missing a release date!\n[Click to Fix] - Requires MB Release Edit Seeding Helper" target="_blank" rel="nooperner">🗓</a>`
iconsHtml += `<a class="dateDiff" href="https://musicbrainz.org/release/${finalMBID}/edit?events.0.date.year=${spotifyYear}&events.0.date.month=${spotifyMonth}&events.0.date.day=${spotifyDay}&edit_note=${editNote}" title="This release is missing a release date!\n[Click to Fix] - Requires MB Release Edit Seeding Helper" target="_blank" rel="nooperner">🗓</a>`;
} else if (finalReleaseDate != spotifyReleaseDate) {
iconsHtml += `<div class="dateDiff" title="This release has a differing release date! [SP: ${spotifyReleaseDate} MB: ${finalReleaseDate}]\n(This may indicate that you have to split a release.)">🗓</div>`
iconsHtml += `<div class="dateDiff" title="This release has a differing release date! [SP: ${spotifyReleaseDate} MB: ${finalReleaseDate}]\n(This may indicate that you have to split a release.)">🗓</div>`;
}
}
const htmlToAppend = `
Expand Down

0 comments on commit cada8d5

Please sign in to comment.