fix: OG scrape fills missing artist even when JSON-LD found track name

JSON-LD could set track_name but return empty byArtist, making the OG
block (guarded by `if not track_name`) never run — leaving artist blank.
Now OG runs whenever either name or artist is missing, and only fills
fields that are still empty so JSON-LD name isn't overwritten.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-23 21:46:50 +02:00
1 parent c052d6e913
commit 4da1fb25e2
1 file changed
+9 -7
+9 -7
View File
@@ -111,19 +111,21 @@ def resolve(sp_type, sp_id):
except Exception as e:
eprint(f'[spotapi] JSON-LD parse failed: {e}')
# 2) OG tags — artist is desc_parts[0], then type ("Song"), then year
if not track_name:
# 2) OG tags — fill in any fields still missing after JSON-LD
# Real format: "Artist · Song · Year" — artist is index 0
if not track_name or not artist_name:
og = {}
for m in re.finditer(r'<meta\s+(?:property|name)=["\']og:([^"\']+)["\']\s+content=["\']([^"\']*)["\']', page):
og[m.group(1)] = _html.unescape(m.group(2))
for m in re.finditer(r'<meta\s+content=["\']([^"\']*)["\'][^>]+(?:property|name)=["\']og:([^"\']+)["\']', page):
og[m.group(2)] = _html.unescape(m.group(1))
desc_parts = [p.strip() for p in og.get('description', '').split('·')]
track_name = og.get('title', '')
# Real format: "Artist · Song · Year · N songs." — artist is index 0
artist_name = desc_parts[0] if desc_parts else ''
album_name = ''
art_url = og.get('image', '')
if not track_name:
track_name = og.get('title', '')
if not artist_name:
artist_name = desc_parts[0] if desc_parts else ''
if not art_url:
art_url = og.get('image', '')
eprint(f'[spotapi] OG scrape: name={track_name!r} artist={artist_name!r}')
if track_name: