Show lyric source and link

This commit is contained in:
iamdoubz committed 2026-07-30 14:49:31 -05:00
1 parent da525948ce
commit e02752ab30
4 files changed
+29 -8

No files matched your search

+10 -8
View File
@@ -11,14 +11,16 @@
* "found": true|false,
* "lyrics": "plain text\nwith newlines",
* "synced": [{ "time": 12.34, "text": "…" }, …], // [] when unavailable
* "url": "…"
* "url": "…",
* "source": "lrclib" | "dumb" | "genius"
* }
*
* Lyrics are returned as plain text (tags/timestamps stripped) so the
* front-end can render them with textContent — no HTML injection from a
* third-party page. `synced` (line-level LRC timestamps, seconds) is only
* populated when LRCLIB has synced lyrics; the Genius fallback has no timing
* data so it's always [] there.
* data so it's always [] there. `url` is '' for LRCLIB (the front-end only
* shows a "source" link for dumb/genius).
*
* Note: the Genius fallback scrapes HTML, which can change at any time. If
* Genius restructures their page the extraction may need updating.
@@ -79,7 +81,7 @@ function lrclib_lyrics($artist, $title, $timeout) {
$lrc = lrclib_lyrics($artist, $title, $timeout);
if ($lrc !== null) {
json_out(['found' => true, 'lyrics' => $lrc['lyrics'], 'synced' => $lrc['synced'], 'url' => '']);
json_out(['found' => true, 'lyrics' => $lrc['lyrics'], 'synced' => $lrc['synced'], 'url' => '', 'source' => 'lrclib']);
}
/* -- dumb (Genius-API-free fallback) ----------------------------------------- */
@@ -89,9 +91,9 @@ if (cfg('dumb.enabled')) {
$song = dumb_song($path, $timeout);
$url = cfg('dumb.url') . $path;
if ($song === null || $song['lyrics'] === '') {
json_out(['found' => false, 'lyrics' => '', 'synced' => [], 'url' => $url]);
json_out(['found' => false, 'lyrics' => '', 'synced' => [], 'url' => $url, 'source' => 'dumb']);
}
json_out(['found' => true, 'lyrics' => $song['lyrics'], 'synced' => [], 'url' => $url]);
json_out(['found' => true, 'lyrics' => $song['lyrics'], 'synced' => [], 'url' => $url, 'source' => 'dumb']);
}
/* -- Genius (fallback) ------------------------------------------------------- */
@@ -131,7 +133,7 @@ if ($pageUrl === '') json_out($empty);
/* -- Scrape the lyric containers ------------------------------------------- */
$page = http_get($pageUrl, $timeout);
if ($page === null) {
json_out(['found' => false, 'lyrics' => '', 'synced' => [], 'url' => $pageUrl]);
json_out(['found' => false, 'lyrics' => '', 'synced' => [], 'url' => $pageUrl, 'source' => 'genius']);
}
$marker = 'data-lyrics-container="true"';
@@ -153,7 +155,7 @@ $lyrics = implode("\n", array_map('trim', explode("\n", $lyrics)));
$lyrics = preg_replace("/\n{3,}/", "\n\n", $lyrics);
if ($lyrics === '') {
json_out(['found' => false, 'lyrics' => '', 'synced' => [], 'url' => $pageUrl]);
json_out(['found' => false, 'lyrics' => '', 'synced' => [], 'url' => $pageUrl, 'source' => 'genius']);
}
json_out(['found' => true, 'lyrics' => $lyrics, 'synced' => [], 'url' => $pageUrl]);
json_out(['found' => true, 'lyrics' => $lyrics, 'synced' => [], 'url' => $pageUrl, 'source' => 'genius']);