Better dumb search

This commit is contained in:
iamdoubz committed 2026-07-30 16:02:59 -05:00
1 parent 389b11e349
commit a7775a6b87
3 files changed
+105 -21

No files matched your search

+15 -2
View File
@@ -85,11 +85,24 @@ function genius_artwork($artist, $title) {
if ($token === '') return null;
$headers = ['Authorization: Bearer ' . $token];
$query = rawurlencode(trim($artist . ' - ' . $title, ' -'));
$query = rawurlencode(trim($artist . ' - ' . strip_feature_credit($title), ' -'));
$search = http_get('https://api.genius.com/search?q=' . $query, 5, $headers);
if ($search === null) return null;
$hit = dot_get(json_decode($search, true), 'response.hits.0.result', null);
$hits = dot_get(json_decode($search, true), 'response.hits', []);
if (!is_array($hits) || count($hits) === 0) return null;
// Same artist-attribution scan as api/lyrics.php — skip translation-page
// hits filed under a pseudo-artist account, falling back to the raw top
// hit if nothing in the first 5 matches.
$hit = null;
$checked = 0;
foreach ($hits as $h) {
if ($checked++ >= 5) break;
$r = dot_get($h, 'result', null);
if ($r && artist_loosely_matches((string) ($r['artist_names'] ?? ''), $artist)) { $hit = $r; break; }
}
if ($hit === null) $hit = dot_get($hits, '0.result', null);
if (!$hit) return null;
$out = [