From 56222b799ac6c2d27901306fb70e1941ccf66b7f Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Thu, 29 Jan 2026 10:16:19 -0800 Subject: [PATCH] Fix ListenBrainz playlists not showing when tables don't exist yet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ListenBrainzManager opens its own raw sqlite3 connection, bypassing MusicDatabase initialization. If it runs before MusicDatabase creates the tables, all queries fail with "no such table: listenbrainz_playlists". Added _ensure_tables() to ListenBrainzManager init that runs CREATE TABLE IF NOT EXISTS for both ListenBrainz tables — a no-op when they already exist, but creates them if MusicDatabase hasn't run yet. --- core/listenbrainz_manager.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/core/listenbrainz_manager.py b/core/listenbrainz_manager.py index bdbd53ad..77fab7f3 100644 --- a/core/listenbrainz_manager.py +++ b/core/listenbrainz_manager.py @@ -21,6 +21,44 @@ class ListenBrainzManager: def __init__(self, db_path: str): self.db_path = db_path self.client = ListenBrainzClient() + self._ensure_tables() + + def _ensure_tables(self): + """Ensure ListenBrainz tables exist in the database""" + conn = sqlite3.connect(self.db_path) + cursor = conn.cursor() + cursor.execute(""" + CREATE TABLE IF NOT EXISTS listenbrainz_playlists ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + playlist_mbid TEXT NOT NULL UNIQUE, + title TEXT NOT NULL, + creator TEXT, + playlist_type TEXT NOT NULL, + track_count INTEGER DEFAULT 0, + annotation_data TEXT, + last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + cached_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """) + cursor.execute(""" + CREATE TABLE IF NOT EXISTS listenbrainz_tracks ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + playlist_id INTEGER NOT NULL, + position INTEGER NOT NULL, + track_name TEXT NOT NULL, + artist_name TEXT NOT NULL, + album_name TEXT NOT NULL, + duration_ms INTEGER DEFAULT 0, + recording_mbid TEXT, + release_mbid TEXT, + album_cover_url TEXT, + additional_metadata TEXT, + FOREIGN KEY (playlist_id) REFERENCES listenbrainz_playlists (id) ON DELETE CASCADE, + UNIQUE(playlist_id, position) + ) + """) + conn.commit() + conn.close() def _get_db_connection(self): """Get database connection"""