Skip to content

Commit

Permalink
feat: add last.fm tags first and fetch from artists only after
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Feb 17, 2024
1 parent e2aa0b5 commit 5e5c3fe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type * as ReactTypes from "react";
import type { CustomWindow } from "./window";
declare let window: CustomWindow;

const LOG_PREFIX = "[better-spotify-genres]";

function initializeSpotifyGenres(): void {
// Make sure everything is loaded.
if (!(Spicetify.CosmosAsync && Spicetify.Platform && Spicetify.URI && Spicetify.Player.data)) {
Expand Down Expand Up @@ -213,10 +215,19 @@ function initializeSpotifyGenres(): void {
}

async function injectGenre() {
let allArtistURI = getAllArtistsURIFromCurrentTrack();
let allGenres = await getAllArtistsGenres(allArtistURI);
let allGenres = [...lastFmTags];

// Get genres from artists if Last.FM tags are not available.
if (allGenres.length === 0) {
console.warn(LOG_PREFIX, "No Last.FM tags found for the current track. Fetching genres from artists...");
let allArtistURI = getAllArtistsURIFromCurrentTrack();
allGenres = await getAllArtistsGenres(allArtistURI);
}

console.info(LOG_PREFIX, "All genres of the current track: ", allGenres);

if (!allGenres) {
console.warn(LOG_PREFIX, "No genres found for the current track. Removing...");
allGenresForPopupModal = []
removeGenresFromUI()
return;
Expand Down Expand Up @@ -519,12 +530,13 @@ function initializeSpotifyGenres(): void {

async function updateGenres(): Promise<void> {
if (!CONFIG.state || Spicetify.Player.data.item.metadata.is_local || Spicetify.URI.fromString(Spicetify.Player.data.item.uri).type !== "track") {
console.warn(LOG_PREFIX, "State is disabled or the current track is local. Removing...");
removeGenresFromUI();
return;
}

injectGenre();
updateLastFmTags();
await updateLastFmTags();
await injectGenre();
}

function artistPageGenreOnClick(dataValue: string): void {
Expand Down

0 comments on commit 5e5c3fe

Please sign in to comment.