@@ -179,7 +179,8 @@ const normalizeSong = (raw: unknown): LidarrSongSearchResult | null => {
179179export class LidarrClient {
180180 constructor (
181181 private readonly baseUrl : string ,
182- private readonly apiKey : string
182+ private readonly apiKey : string ,
183+ private readonly debug : boolean = false
183184 ) { }
184185
185186 private async request < T > ( path : string , init ?: RequestInit ) : Promise < T > {
@@ -274,18 +275,18 @@ export class LidarrClient {
274275 async getArtistByForeignId ( foreignArtistId : string ) : Promise < LidarrArtist | null > {
275276 // First try: check if artist is already in the library
276277 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 ) ;
278+ if ( this . debug ) console . log ( "[lidarr] getArtistByForeignId - existing artist:" , existingArtist ? { id : existingArtist . id , name : existingArtist . artistName , imagesCount : existingArtist . images ?. length } : null ) ;
278279 if ( existingArtist ) return existingArtist ;
279280
280281 // Second try: search by term using the foreignArtistId
281282 const encoded = encodeURIComponent ( foreignArtistId ) ;
282283 const searchResults = await this . tryRequest < LidarrArtist [ ] > ( `/api/v1/artist/lookup?term=${ encoded } ` ) ;
283- console . log ( "[lidarr] getArtistByForeignId - search results:" , searchResults ?. length ?? 0 , "artists" ) ;
284+ if ( this . debug ) console . log ( "[lidarr] getArtistByForeignId - search results:" , searchResults ?. length ?? 0 , "artists" ) ;
284285
285286 // Filter results to find matching artist by foreignArtistId
286287 if ( searchResults && searchResults . length > 0 ) {
287288 const match = searchResults . find ( ( a ) => a . foreignArtistId === foreignArtistId ) ;
288- console . log ( "[lidarr] getArtistByForeignId - matched artist:" , match ? { name : match . artistName , imagesCount : match . images ?. length } : null ) ;
289+ if ( this . debug ) console . log ( "[lidarr] getArtistByForeignId - matched artist:" , match ? { name : match . artistName , imagesCount : match . images ?. length } : null ) ;
289290 if ( match ) return match ;
290291 // Return first result if no exact match
291292 return searchResults [ 0 ] ;
@@ -298,34 +299,34 @@ export class LidarrClient {
298299 // First try: search by term
299300 const encoded = encodeURIComponent ( foreignArtistId ) ;
300301 let albums = await this . tryRequest < LidarrArtistAlbum [ ] > ( `/api/v1/album/lookup?term=${ encoded } ` ) ;
301- console . log ( "[lidarr] getAlbumsByArtistForeignId - search results:" , albums ?. length ?? 0 , "albums" ) ;
302+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - search results:" , albums ?. length ?? 0 , "albums" ) ;
302303
303304 // Filter to only albums matching the foreignArtistId
304305 if ( albums && albums . length > 0 ) {
305306 const matching = albums . filter ( ( a ) => a . foreignArtistId === foreignArtistId ) ;
306- console . log ( "[lidarr] getAlbumsByArtistForeignId - filtered by foreignArtistId:" , matching . length , "albums" ) ;
307+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - filtered by foreignArtistId:" , matching . length , "albums" ) ;
307308 if ( matching . length > 0 ) return matching ;
308309 }
309310
310311 if ( ! albums || albums . length === 0 ) {
311- console . log ( "[lidarr] getAlbumsByArtistForeignId - no albums from search, trying fallback" ) ;
312+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - no albums from search, trying fallback" ) ;
312313 // Fallback: search by artist name in existing albums
313314 const artist = await this . getArtistByForeignId ( foreignArtistId ) ;
314315 if ( ! artist ) {
315- console . log ( "[lidarr] getAlbumsByArtistForeignId - no artist found for fallback" ) ;
316+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - no artist found for fallback" ) ;
316317 return [ ] ;
317318 }
318319
319- console . log ( "[lidarr] getAlbumsByArtistForeignId - fallback artist:" , artist . artistName ) ;
320+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - fallback artist:" , artist . artistName ) ;
320321 const allAlbums = await this . tryRequest < LidarrArtistAlbum [ ] > ( "/api/v1/album" ) ;
321- console . log ( "[lidarr] getAlbumsByArtistForeignId - all albums in library:" , allAlbums ?. length ?? 0 ) ;
322+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - all albums in library:" , allAlbums ?. length ?? 0 ) ;
322323
323324 if ( ! allAlbums ) return [ ] ;
324325
325326 const filtered = allAlbums . filter (
326327 ( album ) => album . artistName ?. toLowerCase ( ) === artist . artistName . toLowerCase ( )
327328 ) ;
328- console . log ( "[lidarr] getAlbumsByArtistForeignId - fallback filtered:" , filtered . length , "albums" ) ;
329+ if ( this . debug ) console . log ( "[lidarr] getAlbumsByArtistForeignId - fallback filtered:" , filtered . length , "albums" ) ;
329330 return filtered ;
330331 }
331332
0 commit comments