From 2c1d3d8165629144760ae4a260fccdf10b0b082b Mon Sep 17 00:00:00 2001 From: Amy Jeanes Date: Fri, 30 Oct 2026 00:02:40 +0000 Subject: [PATCH 1/4] fix(lyrics): treat KuGou's instrumental notice as no lyrics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KuGou answers instrumental tracks with a one-line lyric, "纯音乐,请欣赏" ("pure music, please enjoy"), which showed as a synced lyric line. Treat an answer made only of that notice as no lyrics, so the lookup moves on to the next provider or shows "Lyrics not available". Lyrics that merely contain the phrase are kept. Notices already in the lyrics cache stay until the cache is cleared in Settings; evicting them was left out to keep the fix to the provider. Assisted-by: Claude Code (Claude Opus 5.5) --- src/lib/lyrics/providers/kugou.ts | 9 ++++++++- src/lib/lyrics/providers/providers.test.ts | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/lyrics/providers/kugou.ts b/src/lib/lyrics/providers/kugou.ts index 528514c98..b7520e906 100644 --- a/src/lib/lyrics/providers/kugou.ts +++ b/src/lib/lyrics/providers/kugou.ts @@ -100,6 +100,12 @@ export function matchKuGou( }); } +// KuGou answers instrumentals with one line, "纯音乐,请欣赏" ("pure music, please enjoy"), not with no lyrics. +const INSTRUMENTAL_NOTICE = /^纯音乐[,,]?\s*请欣赏$/; + +export const isInstrumentalNotice = (entries: LyricsEntry[]): boolean => + entries.length > 0 && entries.every((entry) => INSTRUMENTAL_NOTICE.test(entry.text.trim())); + async function download(id: number, accesskey: string): Promise { const url = `${LYRIC_DOWNLOAD}?fmt=lrc&charset=utf8&client=pc&ver=1&id=${id}&accesskey=${enc(accesskey)}`; const res = await lyricsGetJson<{ content?: string }>(url); @@ -119,7 +125,8 @@ async function firstCandidate(url: string): Promise { async function fromCandidate(candidate: LyricCandidate | null): Promise { if (!candidate?.id || !candidate.accesskey) return []; const lrc = await download(candidate.id, candidate.accesskey); - return lrc ? parseLyrics(lrc) : []; + const entries = lrc ? parseLyrics(lrc) : []; + return isInstrumentalNotice(entries) ? [] : entries; } export const kugouProvider: LyricsProvider = { diff --git a/src/lib/lyrics/providers/providers.test.ts b/src/lib/lyrics/providers/providers.test.ts index b34788848..882ca3e8a 100644 --- a/src/lib/lyrics/providers/providers.test.ts +++ b/src/lib/lyrics/providers/providers.test.ts @@ -2,10 +2,11 @@ import { describe, expect, it } from "vitest"; import { convertLyricsPlus } from "./lyricsPlus"; import { pickSearchHit } from "./lrclib"; -import { matchKuGou, normalizeKuGouLrc } from "./kugou"; +import { isInstrumentalNotice, matchKuGou, normalizeKuGouLrc } from "./kugou"; import { matchAppleSongs, parseItunesSearch } from "./paxsenix"; import { isUncachedMiss } from "./betterLyrics"; import { lrcOffsetMs, parseOfflineLyrics } from "../offline"; +import { parseLyrics } from "../lyricsUtils"; describe("BetterLyrics", () => { it("reads an uncached 401 as a miss for this song only", () => { @@ -81,6 +82,14 @@ describe("KuGou", () => { const lrc = ["[00:00.00]Song - Singer", "[00:01.00]作词:Someone", "plain", "[00:10.00]First", "[00:20.00]Second"].join("\n"); expect(normalizeKuGouLrc(lrc)).toBe("[00:10.00]First\n[00:20.00]Second"); }); + + it("reads the instrumental notice as no lyrics, but not lyrics that contain it", () => { + const notice = ["[id:$00000000]", "[ar:arkady sevidov]", "[ti:June]", "[total:320317]", "[00:01.58]纯音乐,请欣赏"].join("\n"); + expect(isInstrumentalNotice(parseLyrics(normalizeKuGouLrc(notice)))).toBe(true); + expect(isInstrumentalNotice(parseLyrics("[00:01.58]纯音乐,请欣赏"))).toBe(true); + expect(isInstrumentalNotice(parseLyrics("[00:01.00]纯音乐,请欣赏\n[00:05.00]First"))).toBe(false); + expect(isInstrumentalNotice([])).toBe(false); + }); }); describe("Paxsenix", () => { From 9c698c348476b0cadbcec751f544d757c53db6a0 Mon Sep 17 00:00:00 2001 From: AE <98699388+A-EDev@users.noreply.github.com> Date: Thu, 5 Nov 2026 00:27:35 +0200 Subject: [PATCH 2/4] fix(lyrics): stop KuGou's search at the instrumental notice Co-authored-by: Amy Jeanes --- src/lib/lyrics/providers/kugou.test.ts | 61 ++++++++++++++++++++++ src/lib/lyrics/providers/kugou.ts | 9 ++-- src/lib/lyrics/providers/providers.test.ts | 2 +- 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 src/lib/lyrics/providers/kugou.test.ts diff --git a/src/lib/lyrics/providers/kugou.test.ts b/src/lib/lyrics/providers/kugou.test.ts new file mode 100644 index 000000000..d9b9f304d --- /dev/null +++ b/src/lib/lyrics/providers/kugou.test.ts @@ -0,0 +1,61 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const requests = vi.hoisted(() => ({ downloads: [] as number[] })); +const answers = vi.hoisted(() => ({ + songs: [] as Array<{ hash: string; songname: string; singername: string; duration: number }>, + keyword: [] as Array<{ id: number; accesskey: string; song: string; singer: string; duration: number }>, + lrc: new Map(), +})); + +vi.mock("../http", () => ({ + enc: encodeURIComponent, + lyricsGetJson: async (url: string) => { + if (url.includes("/search/song")) return { data: { info: answers.songs } }; + if (url.includes("/download")) { + const id = Number(new URL(url).searchParams.get("id")); + requests.downloads.push(id); + const bytes = new TextEncoder().encode(answers.lrc.get(id) ?? ""); + return { content: btoa(String.fromCharCode(...bytes)) }; + } + const hash = new URL(url).searchParams.get("hash"); + if (hash) return { candidates: [{ id: Number(hash), accesskey: "key" }] }; + return { candidates: answers.keyword }; + }, +})); + +import { kugouProvider } from "./kugou"; + +const NOTICE = "[00:01.58]纯音乐,请欣赏"; +const VOCALS = "[00:10.00]First\n[00:20.00]Second"; +const hit = (hash: number, duration: number) => ({ hash: String(hash), songname: "Song", singername: "Band", duration }); +const lookup = () => kugouProvider.getLyrics("id", "Song", "Band", 200, null); + +describe("KuGou lookup", () => { + beforeEach(() => { + requests.downloads.length = 0; + answers.songs = []; + answers.keyword = []; + answers.lrc = new Map([ + [1, NOTICE], + [2, VOCALS], + ]); + }); + + it("stops at the instrumental notice, so a vocal version of the song can't answer for it", async () => { + answers.songs = [hit(1, 200), hit(2, 180)]; + expect(await lookup()).toEqual([]); + expect(requests.downloads).toEqual([1]); + }); + + it("reads a notice from the keyword search as no lyrics too", async () => { + answers.keyword = [{ id: 1, accesskey: "key", song: "Song", singer: "Band", duration: 200_000 }]; + expect(await lookup()).toEqual([]); + }); + + it("still tries the next match when one has no lyrics at all", async () => { + answers.lrc.delete(1); + answers.songs = [hit(1, 200), hit(2, 180)]; + expect(await lookup()).toHaveLength(2); + expect(requests.downloads).toEqual([1, 2]); + }); +}); diff --git a/src/lib/lyrics/providers/kugou.ts b/src/lib/lyrics/providers/kugou.ts index b7520e906..0f1af9c66 100644 --- a/src/lib/lyrics/providers/kugou.ts +++ b/src/lib/lyrics/providers/kugou.ts @@ -125,8 +125,7 @@ async function firstCandidate(url: string): Promise { async function fromCandidate(candidate: LyricCandidate | null): Promise { if (!candidate?.id || !candidate.accesskey) return []; const lrc = await download(candidate.id, candidate.accesskey); - const entries = lrc ? parseLyrics(lrc) : []; - return isInstrumentalNotice(entries) ? [] : entries; + return lrc ? parseLyrics(lrc) : []; } export const kugouProvider: LyricsProvider = { @@ -149,7 +148,8 @@ export const kugouProvider: LyricsProvider = { const entries = await fromCandidate( await firstCandidate(`${LYRIC_SEARCH}?ver=1&man=yes&client=pc&hash=${enc(song.hash)}`), ); - if (entries.length > 0) return entries; + // The notice is KuGou's answer for this song; a later match could be a vocal version of it. + if (entries.length > 0) return isInstrumentalNotice(entries) ? [] : entries; } let url = `${LYRIC_SEARCH}?ver=1&man=yes&client=pc`; @@ -161,6 +161,7 @@ export const kugouProvider: LyricsProvider = { request, (c) => ({ title: stripTags(c.song), artist: stripTags(c.singer), durationSec: Math.round((c.duration ?? 0) / 1000) }), ); - return fromCandidate(candidates[0] ?? null); + const entries = await fromCandidate(candidates[0] ?? null); + return isInstrumentalNotice(entries) ? [] : entries; }, }; diff --git a/src/lib/lyrics/providers/providers.test.ts b/src/lib/lyrics/providers/providers.test.ts index 882ca3e8a..beb671cc0 100644 --- a/src/lib/lyrics/providers/providers.test.ts +++ b/src/lib/lyrics/providers/providers.test.ts @@ -84,7 +84,7 @@ describe("KuGou", () => { }); it("reads the instrumental notice as no lyrics, but not lyrics that contain it", () => { - const notice = ["[id:$00000000]", "[ar:arkady sevidov]", "[ti:June]", "[total:320317]", "[00:01.58]纯音乐,请欣赏"].join("\n"); + const notice = ["\uFEFF[id:$00000000]", "[ar:arkady sevidov]", "[ti:June]", "[total:320317]", "[00:01.58]纯音乐,请欣赏"].join("\n"); expect(isInstrumentalNotice(parseLyrics(normalizeKuGouLrc(notice)))).toBe(true); expect(isInstrumentalNotice(parseLyrics("[00:01.58]纯音乐,请欣赏"))).toBe(true); expect(isInstrumentalNotice(parseLyrics("[00:01.00]纯音乐,请欣赏\n[00:05.00]First"))).toBe(false); From 6431aa16f2bdae63b34bfcacf4372241583eb0f8 Mon Sep 17 00:00:00 2001 From: AE <98699388+A-EDev@users.noreply.github.com> Date: Thu, 5 Nov 2026 00:27:58 +0200 Subject: [PATCH 3/4] fix(lyrics): drop instrumental notices already in the lyrics cache Co-authored-by: Amy Jeanes --- src/lib/lyrics/lyricsHelper.test.ts | 27 ++++++++++++++++++++++ src/lib/lyrics/lyricsHelper.ts | 8 ++++--- src/lib/lyrics/lyricsUtils.ts | 6 +++++ src/lib/lyrics/providers/kugou.ts | 8 +------ src/lib/lyrics/providers/providers.test.ts | 4 ++-- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/lib/lyrics/lyricsHelper.test.ts b/src/lib/lyrics/lyricsHelper.test.ts index 2187224b4..cb7738957 100644 --- a/src/lib/lyrics/lyricsHelper.test.ts +++ b/src/lib/lyrics/lyricsHelper.test.ts @@ -10,6 +10,17 @@ vi.mock("./registry", () => ({ })); vi.mock("../../store/useAppSettingsStore", () => ({ getSettingValue: () => "" })); +const disk = vi.hoisted(() => new Map()); +vi.mock("../api/lyrics", () => ({ + getCachedLyrics: async (id: string) => disk.get(id) ?? null, + putCachedLyrics: async (id: string, entries: string) => { + disk.set(id, entries); + }, + evictCachedLyrics: async (id: string) => { + disk.delete(id); + }, +})); + const { getLyrics, forceRefresh } = await import("./lyricsHelper"); const { seedOfflineLyrics } = await import("./offline"); @@ -40,6 +51,7 @@ const request = () => ({ videoId: `video-${++id}`, title: "Song", artist: "Band" beforeEach(() => { providers.length = 0; + disk.clear(); localStorage.clear(); }); afterEach(() => { @@ -47,6 +59,21 @@ afterEach(() => { }); describe("lyrics helper", () => { + it("drops KuGou's instrumental notice saved in the disk cache", async () => { + const song = request(); + disk.set(song.videoId, JSON.stringify([{ time: 1580, text: "纯音乐,请欣赏" }])); + expect(await getLyrics(song)).toBeNull(); + expect(disk.has(song.videoId)).toBe(false); + }); + + it("still falls back to other line-synced lyrics from the disk cache", async () => { + const song = request(); + disk.set(song.videoId, JSON.stringify(lineSynced)); + const result = await getLyrics(song); + expect(result?.provider).toBe("DiskCache"); + expect(disk.has(song.videoId)).toBe(true); + }); + it("returns word sync at once without asking later providers", async () => { const later = provider("Later", async () => lineSynced); providers.push(provider("Words", async () => wordSynced), later); diff --git a/src/lib/lyrics/lyricsHelper.ts b/src/lib/lyrics/lyricsHelper.ts index 999028d76..1cabb781d 100644 --- a/src/lib/lyrics/lyricsHelper.ts +++ b/src/lib/lyrics/lyricsHelper.ts @@ -1,7 +1,7 @@ import type { LyricsEntry, LyricsProvider, LyricsResult } from "./types"; import type { SongItem } from "../../types/music"; import { getEnabledProviders, parseProviderEnabledStates } from "./registry"; -import { filterCreditLines, normalizeEntries, stripWordTimings } from "./lyricsUtils"; +import { filterCreditLines, isInstrumentalNotice, normalizeEntries, stripWordTimings } from "./lyricsUtils"; import { cleanArtist, cleanTitle } from "./matching"; import { entriesAreSynced, hasWordSync, hasReasonableTimestamps } from "./sync"; import * as cache from "./cache"; @@ -125,11 +125,13 @@ async function fetchLyrics(request: LyricsRequest, signal: AbortSignal): Promise const disk = await cache.getDisk(videoId); if (disk && disk.length > 0) { const norm = normalizeEntries(sorted(disk)); - if (hasWordSync(norm) && hasReasonableTimestamps(norm, durationSec)) { + // A notice saved before KuGou's was read as no lyrics would otherwise come back as the fallback. + const usable = !isInstrumentalNotice(norm) && hasReasonableTimestamps(norm, durationSec); + if (hasWordSync(norm) && usable) { cache.setMemory(videoId, norm); return { entries: norm, provider: "DiskCache" }; } - if (hasReasonableTimestamps(norm, durationSec)) { + if (usable) { cachedFallback = { entries: stripWordTimings(norm), provider: "DiskCache" }; } else { cache.evict(videoId); diff --git a/src/lib/lyrics/lyricsUtils.ts b/src/lib/lyrics/lyricsUtils.ts index 0fe69b061..ada32a80e 100644 --- a/src/lib/lyrics/lyricsUtils.ts +++ b/src/lib/lyrics/lyricsUtils.ts @@ -54,6 +54,12 @@ export function filterCreditLines(entries: LyricsEntry[]): LyricsEntry[] { }); } +// KuGou answers instrumentals with one line, "纯音乐,请欣赏" ("pure music, please enjoy"), not with no lyrics. +const INSTRUMENTAL_NOTICE = /^纯音乐[,,]?\s*请欣赏$/; + +export const isInstrumentalNotice = (entries: LyricsEntry[]): boolean => + entries.length > 0 && entries.every((entry) => INSTRUMENTAL_NOTICE.test(entry.text.trim())); + export function normalizeEntries(entries: LyricsEntry[]): LyricsEntry[] { return entries.map((e) => ({ ...e, diff --git a/src/lib/lyrics/providers/kugou.ts b/src/lib/lyrics/providers/kugou.ts index 0f1af9c66..de5faf9a3 100644 --- a/src/lib/lyrics/providers/kugou.ts +++ b/src/lib/lyrics/providers/kugou.ts @@ -1,6 +1,6 @@ import type { LyricsEntry, LyricsProvider } from "../types"; import { lyricsGetJson, enc } from "../http"; -import { parseLyrics } from "../lyricsUtils"; +import { isInstrumentalNotice, parseLyrics } from "../lyricsUtils"; import { ranked, type MatchSong } from "../matching"; const SONG_SEARCH = "https://mobileservice.kugou.com/api/v3/search/song"; @@ -100,12 +100,6 @@ export function matchKuGou( }); } -// KuGou answers instrumentals with one line, "纯音乐,请欣赏" ("pure music, please enjoy"), not with no lyrics. -const INSTRUMENTAL_NOTICE = /^纯音乐[,,]?\s*请欣赏$/; - -export const isInstrumentalNotice = (entries: LyricsEntry[]): boolean => - entries.length > 0 && entries.every((entry) => INSTRUMENTAL_NOTICE.test(entry.text.trim())); - async function download(id: number, accesskey: string): Promise { const url = `${LYRIC_DOWNLOAD}?fmt=lrc&charset=utf8&client=pc&ver=1&id=${id}&accesskey=${enc(accesskey)}`; const res = await lyricsGetJson<{ content?: string }>(url); diff --git a/src/lib/lyrics/providers/providers.test.ts b/src/lib/lyrics/providers/providers.test.ts index beb671cc0..a6c56a7b7 100644 --- a/src/lib/lyrics/providers/providers.test.ts +++ b/src/lib/lyrics/providers/providers.test.ts @@ -2,11 +2,11 @@ import { describe, expect, it } from "vitest"; import { convertLyricsPlus } from "./lyricsPlus"; import { pickSearchHit } from "./lrclib"; -import { isInstrumentalNotice, matchKuGou, normalizeKuGouLrc } from "./kugou"; +import { matchKuGou, normalizeKuGouLrc } from "./kugou"; import { matchAppleSongs, parseItunesSearch } from "./paxsenix"; import { isUncachedMiss } from "./betterLyrics"; import { lrcOffsetMs, parseOfflineLyrics } from "../offline"; -import { parseLyrics } from "../lyricsUtils"; +import { isInstrumentalNotice, parseLyrics } from "../lyricsUtils"; describe("BetterLyrics", () => { it("reads an uncached 401 as a miss for this song only", () => { From 0ef2cac6514ae710429d3d690ac1e78765d02da9 Mon Sep 17 00:00:00 2001 From: AE <98699388+A-EDev@users.noreply.github.com> Date: Thu, 5 Nov 2026 00:27:58 +0200 Subject: [PATCH 4/4] docs(changelog): note the instrumental fix Co-authored-by: Amy Jeanes --- changelog/v0.1.0-beta4.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog/v0.1.0-beta4.txt b/changelog/v0.1.0-beta4.txt index c6e41f1e5..1f63a0629 100644 --- a/changelog/v0.1.0-beta4.txt +++ b/changelog/v0.1.0-beta4.txt @@ -46,6 +46,7 @@ SYNC MUSIC - Autoplay radio no longer stops after about 20 songs. A station keeps adding songs while it has more to play. +- Instrumental songs no longer show KuGou's notice as their lyrics. - Clicking an empty part of the music bar now opens the full player. The buttons, the seek line and dragging up work as before. - Hiding or showing the Queue or Lyrics pane in the full player no longer stretches the title and controls, and the artwork moves with the text.