Skip to content

Commit

Permalink
fix(lyrics-plus): disable genius for 1.2.31 and higher (#2859)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri authored Feb 27, 2024
1 parent 5f77de5 commit 5213509
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CustomApps/lyrics-plus/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ const SyncedExpandedLyricsPage = react.memo(({ lyrics, provider, copyright, isKa
const pageRef = useRef(null);

useTrackPosition(() => {
if (!Player.data.is_paused) {
if (!Spicetify.Player.data.is_paused) {
setPosition(Spicetify.Player.getProgress() + CONFIG.visual["global-delay"] + CONFIG.visual.delay);
}
});
Expand Down
10 changes: 5 additions & 5 deletions CustomApps/lyrics-plus/ProviderGenius.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const ProviderGenius = (() => {
}

async function getNote(id) {
const body = await CosmosAsync.get(`https://genius.com/api/annotations/${id}`);
const body = await Spicetify.CosmosAsync.get(`https://genius.com/api/annotations/${id}`);
const response = body.response;
let note = "";

// Authors annotations
if (response.referent && response.referent.classification === "verified") {
const referentsBody = await CosmosAsync.get(`https://genius.com/api/referents/${id}`);
const referentsBody = await Spicetify.CosmosAsync.get(`https://genius.com/api/referents/${id}`);
const referents = referentsBody.response;
for (const ref of referents.referent.annotations) {
note += getChildDeep(ref.body.dom);
Expand Down Expand Up @@ -100,14 +100,14 @@ const ProviderGenius = (() => {
titles.add(titleNoExtra);
titles.add(Utils.removeSongFeat(info.title));
titles.add(Utils.removeSongFeat(titleNoExtra));
console.log(titles);

let lyrics;
let hits;
for (const title of titles) {
const url = `https://genius.com/api/search/song?per_page=20&q=${encodeURIComponent(title)}%20${encodeURIComponent(info.artist)}`;
const query = new URLSearchParams({ per_page: 20, q: encodeURIComponent(`${title} ${info.artist}`) });
const url = `https://genius.com/api/search/song?${query.toString()}`;

const geniusSearch = await CosmosAsync.get(url);
const geniusSearch = await Spicetify.CosmosAsync.get(url);

hits = geniusSearch.response.sections[0].hits.map(item => ({
title: item.result.full_title,
Expand Down
6 changes: 3 additions & 3 deletions CustomApps/lyrics-plus/ProviderMusixmatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ProviderMusixmatch = (() => {
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join("&");

let body = await CosmosAsync.get(finalURL, null, headers);
let body = await Spicetify.CosmosAsync.get(finalURL, null, headers);

body = body.message.body.macro_calls;

Expand Down Expand Up @@ -72,7 +72,7 @@ const ProviderMusixmatch = (() => {
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join("&");

let result = await CosmosAsync.get(finalURL, null, headers);
let result = await Spicetify.CosmosAsync.get(finalURL, null, headers);

if (result.message.header.status_code !== 200) {
return null;
Expand Down Expand Up @@ -176,7 +176,7 @@ const ProviderMusixmatch = (() => {
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join("&");

let result = await CosmosAsync.get(finalURL, null, headers);
let result = await Spicetify.CosmosAsync.get(finalURL, null, headers);

if (result.message.header.status_code !== 200) return null;

Expand Down
2 changes: 1 addition & 1 deletion CustomApps/lyrics-plus/ProviderNetease.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ProviderNetease = (() => {
const cleanTitle = Utils.removeExtraInfo(Utils.removeSongFeat(Utils.normalize(info.title)));
const finalURL = searchURL + encodeURIComponent(`${cleanTitle} ${info.artist}`);

const searchResults = await CosmosAsync.get(finalURL, null, requestHeader);
const searchResults = await Spicetify.CosmosAsync.get(finalURL, null, requestHeader);
const items = searchResults.result.songs;
if (!items?.length) {
throw "Cannot find track";
Expand Down
1 change: 1 addition & 0 deletions CustomApps/lyrics-plus/TabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const TabBar = react.memo(({ links, activeLink, lockLink, switchCallback, lockCa
const [availableSpace, setAvailableSpace] = useState(0);
const [droplistItem, setDroplistItems] = useState([]);

if (Spicetify.Platform.version >= "1.2.31") links = links.filter(key => key !== "genius");
const options = links.map(key => {
let value = key.replace(/./, c => c.toUpperCase());
if (key === lockLink) {
Expand Down
16 changes: 5 additions & 11 deletions CustomApps/lyrics-plus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ const { useState, useEffect, useCallback, useMemo, useRef } = react;
/** @type {import("react").ReactDOM} */
const reactDOM = Spicetify.ReactDOM;

const {
URI,
Platform: { History },
Player,
CosmosAsync
} = Spicetify;

// Define a function called "render" to specify app entry point
// This function will be used to mount app to main view.
function render() {
Expand Down Expand Up @@ -80,7 +73,7 @@ const CONFIG = {
},
genius: {
on: getConfig("lyrics-plus:provider:genius:on"),
desc: "Provide unsynced lyrics with insights from artists themselves.",
desc: "Provide unsynced lyrics with insights from artists themselves. Genius is disabled and cannot be used as a provider on <code>1.2.31</code> and higher.",
modes: [GENIUS]
},
local: {
Expand Down Expand Up @@ -205,7 +198,7 @@ class LyricsContainer extends react.Component {
const { hex } = data.trackUnion.albumOfTrack.coverArt.extractedColors.colorDark;
vibrant = parseInt(hex.replace("#", ""), 16);
} catch {
const colors = await CosmosAsync.get(`wg://colorextractor/v1/extract-presets?uri=${uri}&format=json`);
const colors = await Spicetify.CosmosAsync.get(`wg://colorextractor/v1/extract-presets?uri=${uri}&format=json`);
vibrant = colors.entries[0].color_swatches.find(color => color.preset === "VIBRANT_NON_ALARMING").color;
}
} catch {
Expand Down Expand Up @@ -244,6 +237,7 @@ class LyricsContainer extends react.Component {
let finalData = { ...emptyState, uri: trackInfo.uri };
for (const id of CONFIG.providersOrder) {
const service = CONFIG.providers[id];
if (id === "genius" && Spicetify.Platform.version >= "1.2.31") continue;
if (!service.on) continue;
if (mode !== -1 && !service.modes.includes(mode)) continue;

Expand Down Expand Up @@ -892,7 +886,7 @@ class LyricsContainer extends react.Component {
const mode = CONFIG.modes.findIndex(a => a === label);
if (mode !== this.state.mode) {
this.setState({ explicitMode: mode });
this.state.provider !== "local" && this.fetchLyrics(Player.data.item, mode);
this.state.provider !== "local" && this.fetchLyrics(Spicetify.Player.data.item, mode);
}
},
lockCallback: label => {
Expand All @@ -901,7 +895,7 @@ class LyricsContainer extends react.Component {
mode = -1;
}
this.setState({ explicitMode: mode, lockMode: mode });
this.fetchLyrics(Player.data.item, mode);
this.fetchLyrics(Spicetify.Player.data.item, mode);
CONFIG.locked = mode;
localStorage.setItem("lyrics-plus:lock-mode", mode);
}
Expand Down

0 comments on commit 5213509

Please sign in to comment.