From ec51b270f2682b024ea14681dffeae0df1bf422d Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 03:01:50 +0530 Subject: [PATCH 01/13] add option to disable individual lyrics providers --- assets/config.json5 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/config.json5 b/assets/config.json5 index 71ca8af..ff7b625 100644 --- a/assets/config.json5 +++ b/assets/config.json5 @@ -26,6 +26,12 @@ // Specify your Musixmatch User Token. // Sunamu will automatically generate it if you don't have your own. mxmusertoken: "", + lyrics_provider: { + genius:true, + musixmatch:true, + netease:true, + metadata:true + }, // Specify the target lyrics cache folder size. // Less frequently shown lyrics will be purged to maintain the cache folder inside the target size. // Note that the operation only occurs once when Sunamu starts up, so it is possible for the cache folder to grow up in size From dc560f3ce0e87d6bdabd0a85b0d211f0b987016e Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 03:04:01 +0530 Subject: [PATCH 02/13] better help --- assets/config.json5 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assets/config.json5 b/assets/config.json5 index ff7b625..141b6c2 100644 --- a/assets/config.json5 +++ b/assets/config.json5 @@ -26,6 +26,8 @@ // Specify your Musixmatch User Token. // Sunamu will automatically generate it if you don't have your own. mxmusertoken: "", + // Specifically change the lyrics provider. + // Can be useful if you are having issue with speicific lyrics providers. (consistently providing unreliable lyrics or other reasons) lyrics_provider: { genius:true, musixmatch:true, From 9327c8a4b70f87e970ca277f928de87f52a14962 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 03:04:51 +0530 Subject: [PATCH 03/13] add functionality to choose specific lyrics provider --- src/main/integrations/lyrics.ts | 24 +++++++++++++++--------- src/types.ts | 8 ++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 20e7b36..6e21e3c 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -6,11 +6,13 @@ 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 get_config} from "../config.js"; export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promise { if (!metadata.artist || !metadata.title) // there can't be lyrics without at least those two fields return { unavailable: true }; + const Config = get_config(); let lyrics: Lyrics | undefined; const id = computeLyricsID(metadata); @@ -21,17 +23,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 - }; - + let providers ={} + if(Config.lyrics_provider.musixmatch){ + Object.assign(providers, Musixmatch) + } + if(Config.lyrics_provider.netease){ + Object.assign(providers, NetEase) + } // if cached then we could assume it is unsync if (!cached) { - Object.assign(providers, { - Genius, - MetadataQuery - }); + if(Config.lyrics_provider.genius){ + Object.assign(providers, Genius) + } + if(Config.lyrics_provider.metadata){ + Object.assign(providers, MetadataQuery) + } } for (const provider in providers) { diff --git a/src/types.ts b/src/types.ts index d807d80..e851ad2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,6 +64,7 @@ export type Config = { mxmusertoken: string, spotify: SpotifyConfig, discordRpc: DiscordPresenceConfig, + lyrics_provider: LyricsProviderConfig, targetLyricsCacheSize?: string, scenes: { [sceneName: string]: SceneConfig @@ -75,6 +76,13 @@ export type SpotifyConfig = { clientSecret: string } +export type LyricsProviderConfig = { + genius:boolean, + musixmatch:boolean, + netease:boolean, + metadata:boolean +} + export type DiscordPresenceConfig = { enabled: boolean, blacklist: string[] From a5520699fbed3cdc1c44912e6f9256fd80d51c4e Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 03:06:41 +0530 Subject: [PATCH 04/13] add missing semicolon --- src/main/integrations/lyrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 6e21e3c..24acf8f 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -23,7 +23,7 @@ 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}`); - let providers ={} + let providers ={}; if(Config.lyrics_provider.musixmatch){ Object.assign(providers, Musixmatch) } From 5c6cb34605b0c864c95afdacd51316715a900f0c Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:09:52 +0530 Subject: [PATCH 05/13] account for naming scheme, linting --- assets/config.json5 | 10 +++++----- src/main/integrations/lyrics.ts | 25 ++++++++++++------------- src/types.ts | 10 +++++----- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/assets/config.json5 b/assets/config.json5 index 141b6c2..966dfe7 100644 --- a/assets/config.json5 +++ b/assets/config.json5 @@ -28,11 +28,11 @@ mxmusertoken: "", // Specifically change the lyrics provider. // Can be useful if you are having issue with speicific lyrics providers. (consistently providing unreliable lyrics or other reasons) - lyrics_provider: { - genius:true, - musixmatch:true, - netease:true, - metadata:true + lyricsProvider: { + genius: true, + musixmatch: true, + netease: true, + metadata: true }, // Specify the target lyrics cache folder size. // Less frequently shown lyrics will be purged to maintain the cache folder inside the target size. diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 24acf8f..edbf629 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -23,21 +23,20 @@ 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}`); - let providers ={}; - if(Config.lyrics_provider.musixmatch){ - Object.assign(providers, Musixmatch) - } - if(Config.lyrics_provider.netease){ - Object.assign(providers, NetEase) - } + 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) { - if(Config.lyrics_provider.genius){ - Object.assign(providers, Genius) - } - if(Config.lyrics_provider.metadata){ - Object.assign(providers, MetadataQuery) - } + if(Config.lyricsProvider.genius) + providers.Genius = Genius; + + if(Config.lyricsProvider.metadata) + providers.Metadata = MetadataQuery; } for (const provider in providers) { diff --git a/src/types.ts b/src/types.ts index e851ad2..6d7b50a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -64,7 +64,7 @@ export type Config = { mxmusertoken: string, spotify: SpotifyConfig, discordRpc: DiscordPresenceConfig, - lyrics_provider: LyricsProviderConfig, + lyricsProvider: LyricsProviderConfig, targetLyricsCacheSize?: string, scenes: { [sceneName: string]: SceneConfig @@ -77,10 +77,10 @@ export type SpotifyConfig = { } export type LyricsProviderConfig = { - genius:boolean, - musixmatch:boolean, - netease:boolean, - metadata:boolean + genius: boolean, + musixmatch: boolean, + netease: boolean, + metadata: boolean } export type DiscordPresenceConfig = { From 91018ed2994d77fefd5316c271acc83e96b92e1c Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:13:46 +0530 Subject: [PATCH 06/13] better help --- assets/config.json5 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/config.json5 b/assets/config.json5 index 966dfe7..a89978b 100644 --- a/assets/config.json5 +++ b/assets/config.json5 @@ -26,8 +26,7 @@ // Specify your Musixmatch User Token. // Sunamu will automatically generate it if you don't have your own. mxmusertoken: "", - // Specifically change the lyrics provider. - // Can be useful if you are having issue with speicific lyrics providers. (consistently providing unreliable lyrics or other reasons) + // Are you not liking lyrics from a specific source? You can disable it here. lyricsProvider: { genius: true, musixmatch: true, From 5c041e29b44686a7efe64c0cc3870f0a393288c8 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:14:55 +0530 Subject: [PATCH 07/13] don't provide file extenion on importing --- src/main/integrations/lyrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index edbf629..696a362 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -6,7 +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 get_config} from "../config.js"; +import {getAll as get_config} from "../config"; export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promise { if (!metadata.artist || !metadata.title) // there can't be lyrics without at least those two fields From 1a95d4e29a093465d8d2daf6f3cd9c10fcc76cf8 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:20:13 +0530 Subject: [PATCH 08/13] only fetch config where its needed --- src/main/integrations/lyrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 696a362..296f0bd 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -12,7 +12,6 @@ export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promi if (!metadata.artist || !metadata.title) // there can't be lyrics without at least those two fields return { unavailable: true }; - const Config = get_config(); let lyrics: Lyrics | undefined; const id = computeLyricsID(metadata); @@ -23,6 +22,7 @@ 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 Config = get_config(); let providers: any = {}; if(Config.lyricsProvider.musixmatch) providers.Musixmatch = Musixmatch; From dc7a22d1931912df526886d43b0b6495a95a4ca3 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:48:25 +0530 Subject: [PATCH 09/13] add missing spaces --- src/main/integrations/lyrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 296f0bd..0382e4c 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -6,7 +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 get_config} from "../config"; +import { getAll as get_config } from "../config"; export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promise { if (!metadata.artist || !metadata.title) // there can't be lyrics without at least those two fields From 921d4fece9e250859ddcf800c7f275756f7f50e8 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:51:49 +0530 Subject: [PATCH 10/13] change order of providers --- assets/config.json5 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/assets/config.json5 b/assets/config.json5 index a89978b..9a39783 100644 --- a/assets/config.json5 +++ b/assets/config.json5 @@ -26,13 +26,6 @@ // Specify your Musixmatch User Token. // Sunamu will automatically generate it if you don't have your own. mxmusertoken: "", - // Are you not liking lyrics from a specific source? You can disable it here. - lyricsProvider: { - genius: true, - musixmatch: true, - netease: true, - metadata: true - }, // Specify the target lyrics cache folder size. // Less frequently shown lyrics will be purged to maintain the cache folder inside the target size. // Note that the operation only occurs once when Sunamu starts up, so it is possible for the cache folder to grow up in size @@ -54,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: { From ba549e3a266631a01f01b273b4f905dd4783d2f9 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:52:14 +0530 Subject: [PATCH 11/13] change order --- src/types.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/types.ts b/src/types.ts index 6d7b50a..de7b6cf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -77,10 +77,10 @@ export type SpotifyConfig = { } export type LyricsProviderConfig = { - genius: boolean, - musixmatch: boolean, - netease: boolean, - metadata: boolean + Musixmatch: boolean, + NetEase: boolean, + Genius: boolean, + Metadata: boolean } export type DiscordPresenceConfig = { From d6136555d6d099aab2f0e4a2023c60a354caea3e Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 16:59:30 +0530 Subject: [PATCH 12/13] change the name of variables --- src/main/integrations/lyrics.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 0382e4c..3075059 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -24,18 +24,18 @@ export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promi const Config = get_config(); let providers: any = {}; - if(Config.lyricsProvider.musixmatch) + if(Config.lyricsProvider.Musixmatch) providers.Musixmatch = Musixmatch; - if(Config.lyricsProvider.netease) + if(Config.lyricsProvider.NetEase) providers.NetEase = NetEase; // if cached then we could assume it is unsync if (!cached) { - if(Config.lyricsProvider.genius) + if(Config.lyricsProvider.Genius) providers.Genius = Genius; - if(Config.lyricsProvider.metadata) + if(Config.lyricsProvider.Metadata) providers.Metadata = MetadataQuery; } From d8cef9a54b6fed1331d0aee8628bbcc646d7eb19 Mon Sep 17 00:00:00 2001 From: AG4lyf Date: Thu, 15 Sep 2022 17:27:07 +0530 Subject: [PATCH 13/13] this dumb brain --- src/main/integrations/lyrics.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/integrations/lyrics.ts b/src/main/integrations/lyrics.ts index 3075059..b7c37bb 100644 --- a/src/main/integrations/lyrics.ts +++ b/src/main/integrations/lyrics.ts @@ -6,7 +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 get_config } from "../config"; +import { getAll as getConfig } from "../config"; export async function queryLyrics(metadata: Metadata, spotifyId?: string): Promise { if (!metadata.artist || !metadata.title) // there can't be lyrics without at least those two fields @@ -22,7 +22,7 @@ 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 Config = get_config(); + const Config = getConfig(); let providers: any = {}; if(Config.lyricsProvider.Musixmatch) providers.Musixmatch = Musixmatch;