Show annotations in lyrics

This commit is contained in:
iamdoubz committed 2026-07-30 15:12:02 -05:00
1 parent 09bf468fcf
commit 62ed95b3ca
1 file changed
+35
+35
View File
@@ -0,0 +1,35 @@
<?php
/**
* api/annotation.php
* -------------------
* Fetches one Genius annotation's body text via a dumb instance — dumb
* exposes annotations as JSON (unlike its HTML-only search/lyrics pages),
* see dumb_extract_annotations()/dumb_song() in _bootstrap.php. Only
* available when USE_DUMB is configured. Returns:
*
* { "found": true|false, "text": "plain text" }
*
* `path` must be exactly one of the paths api/lyrics.php returned in its
* `annotations[].path` (e.g. "/29595058/Kid-cudi-lord-i-know/The-world-is-
* steady.../annotations") — validated against a strict pattern before use
* so this endpoint can't become an open path-relative proxy for whatever
* host DUMB_URL points at.
*/
require_once __DIR__ . '/_bootstrap.php';
$empty = ['found' => false, 'text' => ''];
if (!cfg('dumb.enabled')) json_out($empty);
$path = (string) ($_POST['path'] ?? $_GET['path'] ?? '');
if (!preg_match('#^/\d+/[^/]+/[^/]+/annotations$#', $path)) json_out($empty);
$raw = http_get(cfg('dumb.url') . $path, 5);
if ($raw === null) json_out($empty);
$body = (string) dot_get(json_decode($raw, true), 'body.html', '');
if ($body === '') json_out($empty);
$text = trim(container_to_text($body));
json_out(['found' => $text !== '', 'text' => $text]);