@ -337,8 +337,32 @@ class DeezerWorker:
except Exception as e2 :
logger . error ( f " Error updating item status: { e2 } " )
def _get_existing_id ( self , entity_type : str , entity_id : int ) - > Optional [ str ] :
""" Check if an entity already has a deezer_id (e.g. from manual match). """
table_map = { ' artist ' : ' artists ' , ' album ' : ' albums ' , ' track ' : ' tracks ' }
table = table_map . get ( entity_type )
if not table :
return None
conn = None
try :
conn = self . db . _get_connection ( )
cursor = conn . cursor ( )
cursor . execute ( f " SELECT deezer_id FROM { table } WHERE id = ? " , ( entity_id , ) )
row = cursor . fetchone ( )
return row [ 0 ] if row and row [ 0 ] else None
except Exception :
return None
finally :
if conn :
conn . close ( )
def _process_artist ( self , artist_id : int , artist_name : str ) :
""" Process an artist: search Deezer, verify, store metadata """
existing_id = self . _get_existing_id ( ' artist ' , artist_id )
if existing_id :
logger . debug ( f " Preserving existing Deezer ID for artist ' { artist_name } ' : { existing_id } " )
return
result = self . client . search_artist ( artist_name )
if result :
result_name = result . get ( ' name ' , ' ' )
@ -357,6 +381,11 @@ class DeezerWorker:
def _process_album ( self , album_id : int , album_name : str , artist_name : str , item : Dict [ str , Any ] ) :
""" Process an album: search Deezer, verify, fetch full details, store metadata """
existing_id = self . _get_existing_id ( ' album ' , album_id )
if existing_id :
logger . debug ( f " Preserving existing Deezer ID for album ' { album_name } ' : { existing_id } " )
return
result = self . client . search_album ( artist_name , album_name )
if result :
result_name = result . get ( ' title ' , ' ' )
@ -397,6 +426,11 @@ class DeezerWorker:
def _process_track ( self , track_id : int , track_name : str , artist_name : str , item : Dict [ str , Any ] ) :
""" Process a track: search Deezer, verify, fetch full details for BPM, store metadata """
existing_id = self . _get_existing_id ( ' track ' , track_id )
if existing_id :
logger . debug ( f " Preserving existing Deezer ID for track ' { track_name } ' : { existing_id } " )
return
result = self . client . search_track ( artist_name , track_name )
if result :
result_name = result . get ( ' title ' , ' ' )