@@ -274,15 +274,18 @@ export class LidarrClient {
274274 async getArtistByForeignId ( foreignArtistId : string ) : Promise < LidarrArtist | null > {
275275 // First try: check if artist is already in the library
276276 const existingArtist = await this . getExistingArtistByForeignId ( foreignArtistId ) ;
277+ console . log ( "[lidarr] getArtistByForeignId - existing artist:" , existingArtist ? { id : existingArtist . id , name : existingArtist . artistName , imagesCount : existingArtist . images ?. length } : null ) ;
277278 if ( existingArtist ) return existingArtist ;
278279
279280 // Second try: search by term using the foreignArtistId
280281 const encoded = encodeURIComponent ( foreignArtistId ) ;
281282 const searchResults = await this . tryRequest < LidarrArtist [ ] > ( `/api/v1/artist/lookup?term=${ encoded } ` ) ;
283+ console . log ( "[lidarr] getArtistByForeignId - search results:" , searchResults ?. length ?? 0 , "artists" ) ;
282284
283285 // Filter results to find matching artist by foreignArtistId
284286 if ( searchResults && searchResults . length > 0 ) {
285287 const match = searchResults . find ( ( a ) => a . foreignArtistId === foreignArtistId ) ;
288+ console . log ( "[lidarr] getArtistByForeignId - matched artist:" , match ? { name : match . artistName , imagesCount : match . images ?. length } : null ) ;
286289 if ( match ) return match ;
287290 // Return first result if no exact match
288291 return searchResults [ 0 ] ;
@@ -295,24 +298,35 @@ export class LidarrClient {
295298 // First try: search by term
296299 const encoded = encodeURIComponent ( foreignArtistId ) ;
297300 let albums = await this . tryRequest < LidarrArtistAlbum [ ] > ( `/api/v1/album/lookup?term=${ encoded } ` ) ;
301+ console . log ( "[lidarr] getAlbumsByArtistForeignId - search results:" , albums ?. length ?? 0 , "albums" ) ;
298302
299303 // Filter to only albums matching the foreignArtistId
300304 if ( albums && albums . length > 0 ) {
301305 const matching = albums . filter ( ( a ) => a . foreignArtistId === foreignArtistId ) ;
306+ console . log ( "[lidarr] getAlbumsByArtistForeignId - filtered by foreignArtistId:" , matching . length , "albums" ) ;
302307 if ( matching . length > 0 ) return matching ;
303308 }
304309
305310 if ( ! albums || albums . length === 0 ) {
311+ console . log ( "[lidarr] getAlbumsByArtistForeignId - no albums from search, trying fallback" ) ;
306312 // Fallback: search by artist name in existing albums
307313 const artist = await this . getArtistByForeignId ( foreignArtistId ) ;
308- if ( ! artist ) return [ ] ;
314+ if ( ! artist ) {
315+ console . log ( "[lidarr] getAlbumsByArtistForeignId - no artist found for fallback" ) ;
316+ return [ ] ;
317+ }
309318
319+ console . log ( "[lidarr] getAlbumsByArtistForeignId - fallback artist:" , artist . artistName ) ;
310320 const allAlbums = await this . tryRequest < LidarrArtistAlbum [ ] > ( "/api/v1/album" ) ;
321+ console . log ( "[lidarr] getAlbumsByArtistForeignId - all albums in library:" , allAlbums ?. length ?? 0 ) ;
322+
311323 if ( ! allAlbums ) return [ ] ;
312324
313- return allAlbums . filter (
325+ const filtered = allAlbums . filter (
314326 ( album ) => album . artistName ?. toLowerCase ( ) === artist . artistName . toLowerCase ( )
315327 ) ;
328+ console . log ( "[lidarr] getAlbumsByArtistForeignId - fallback filtered:" , filtered . length , "albums" ) ;
329+ return filtered ;
316330 }
317331
318332 return albums ;
0 commit comments