Skip to content
This repository was archived by the owner on Apr 27, 2024. It is now read-only.

Functionality to disable specific lyrics provider #54

Merged
merged 13 commits into from
Sep 15, 2022
9 changes: 9 additions & 0 deletions assets/config.json5
Original file line number Diff line number Diff line change
@@ -47,6 +47,15 @@
// Blacklist some apps (such as your browser) from ever showing in the Rich Presence.
blacklist: []
},
// Sunamu makes use of online and offline services to get lyrics.
// Their priority order is outlined here, top to bottom. You cannot modify the order.
// If you're having problems with some services, you can disable them here.
lyricsProvider: {
Musixmatch: true,
NetEase: true,
Genius: true,
Metadata: true
},
scenes: {
// The following is just an example! Leave it as is.
_example: {
21 changes: 13 additions & 8 deletions src/main/integrations/lyrics.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import { query as NetEase } from "../lyricproviders/netease";
import { query as Genius } from "../lyricproviders/genius";
import { query as MetadataQuery } from "../lyricproviders/metadata";
import type { Lyrics, Metadata } from "../../types";
import { getAll as getConfig } from "../config";

export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promise<Lyrics | undefined> {
if (!metadata.artist || !metadata.title) // there can't be lyrics without at least those two fields
@@ -21,17 +22,21 @@ export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promi
if (!cached) debug(`Cache miss for ${metadata.artist} - ${metadata.title}`);
else if (!cached?.synchronized) debug(`Cache hit but unsynced lyrics. Trying to fetch synchronized lyrics for ${metadata.artist} - ${metadata.title}`);

const providers = {
Musixmatch,
NetEase
};
const Config = getConfig();
let providers: any = {};
if(Config.lyricsProvider.Musixmatch)
providers.Musixmatch = Musixmatch;

if(Config.lyricsProvider.NetEase)
providers.NetEase = NetEase;

// if cached then we could assume it is unsync
if (!cached) {
Object.assign(providers, {
Genius,
MetadataQuery
});
if(Config.lyricsProvider.Genius)
providers.Genius = Genius;

if(Config.lyricsProvider.Metadata)
providers.Metadata = MetadataQuery;
}

for (const provider in providers) {
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ export type Config = {
mxmusertoken: string,
spotify: SpotifyConfig,
discordRpc: DiscordPresenceConfig,
lyricsProvider: LyricsProviderConfig,
targetLyricsCacheSize?: string,
scenes: {
[sceneName: string]: SceneConfig
@@ -75,6 +76,13 @@ export type SpotifyConfig = {
clientSecret: string
}

export type LyricsProviderConfig = {
Musixmatch: boolean,
NetEase: boolean,
Genius: boolean,
Metadata: boolean
}

export type DiscordPresenceConfig = {
enabled: boolean,
blacklist: string[]