Use Navidrome supplied MBIDs
- Extract musicBrainzId from Navidrome Subsonic response in NavidromeTrack constructor - Store musicbrainz_recording_id in insert_or_update_media_track for both INSERT and UPDATE - Previously, only the API lookup worker could populate this field for Navidrome tracks
This commit is contained in:
parent
b3d3c017ed
commit
13e32041f5
2 changed files with 10 additions and 6 deletions
|
|
@ -120,6 +120,7 @@ class NavidromeTrack:
|
||||||
|
|
||||||
self._album_id = navidrome_data.get('albumId', '')
|
self._album_id = navidrome_data.get('albumId', '')
|
||||||
self._artist_id = navidrome_data.get('artistId', '')
|
self._artist_id = navidrome_data.get('artistId', '')
|
||||||
|
self.musicBrainzId = navidrome_data.get('musicBrainzId')
|
||||||
|
|
||||||
def _parse_date(self, date_str: Optional[str]) -> Optional[datetime]:
|
def _parse_date(self, date_str: Optional[str]) -> Optional[datetime]:
|
||||||
if not date_str:
|
if not date_str:
|
||||||
|
|
|
||||||
|
|
@ -4599,6 +4599,9 @@ class MusicDatabase:
|
||||||
if file_path is None and hasattr(track_obj, 'suffix') and track_obj.suffix:
|
if file_path is None and hasattr(track_obj, 'suffix') and track_obj.suffix:
|
||||||
file_path = f"{track_obj.title}.{track_obj.suffix}"
|
file_path = f"{track_obj.title}.{track_obj.suffix}"
|
||||||
|
|
||||||
|
# Extract MusicBrainz recording ID from track object (set by Navidrome client)
|
||||||
|
musicbrainz_recording_id = getattr(track_obj, 'musicBrainzId', None)
|
||||||
|
|
||||||
# Check if track already exists — UPDATE to preserve enrichment columns,
|
# Check if track already exists — UPDATE to preserve enrichment columns,
|
||||||
# INSERT only for genuinely new tracks
|
# INSERT only for genuinely new tracks
|
||||||
cursor.execute("SELECT 1 FROM tracks WHERE id = ? LIMIT 1", (track_id,))
|
cursor.execute("SELECT 1 FROM tracks WHERE id = ? LIMIT 1", (track_id,))
|
||||||
|
|
@ -4607,19 +4610,19 @@ class MusicDatabase:
|
||||||
if is_new_track:
|
if is_new_track:
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT INTO tracks
|
INSERT INTO tracks
|
||||||
(id, album_id, artist_id, title, track_number, duration, file_path, bitrate, server_source, updated_at)
|
(id, album_id, artist_id, title, track_number, duration, file_path, bitrate, musicbrainz_recording_id, server_source, updated_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
||||||
""", (track_id, album_id, artist_id, title, track_number, duration, file_path, bitrate, server_source))
|
""", (track_id, album_id, artist_id, title, track_number, duration, file_path, bitrate, musicbrainz_recording_id, server_source))
|
||||||
else:
|
else:
|
||||||
# Update server-provided fields only — preserves spotify_track_id, deezer_id,
|
# Update server-provided fields only — preserves spotify_track_id, deezer_id,
|
||||||
# isrc, bpm, musicbrainz IDs, and all other enrichment data
|
# isrc, bpm, musicbrainz IDs, and all other enrichment data
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
UPDATE tracks
|
UPDATE tracks
|
||||||
SET album_id = ?, artist_id = ?, title = ?, track_number = ?,
|
SET album_id = ?, artist_id = ?, title = ?, track_number = ?,
|
||||||
duration = ?, file_path = ?, bitrate = ?, server_source = ?,
|
duration = ?, file_path = ?, bitrate = ?, musicbrainz_recording_id = ?, server_source = ?,
|
||||||
updated_at = CURRENT_TIMESTAMP
|
updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""", (album_id, artist_id, title, track_number, duration, file_path, bitrate, server_source, track_id))
|
""", (album_id, artist_id, title, track_number, duration, file_path, bitrate, musicbrainz_recording_id, server_source, track_id))
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue