Skip to content

Commit bca2cdc

Browse files
oxon1umclaude
andcommitted
Add debug logging to trace artist images and albums
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6b042cd commit bca2cdc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app/api/search/artist/[artistId]/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ arti
2929

3030
// Get albums (from lookup or from existing library)
3131
const albums = await lidarr.getAlbumsByArtistForeignId(artistId);
32+
console.log("[artist-detail] Albums result:", JSON.stringify(albums, null, 2));
3233
const existingAlbums = await lidarr.getExistingArtistAlbums(artistId);
34+
console.log("[artist-detail] Existing albums:", JSON.stringify(existingAlbums, null, 2));
3335

3436
// Mark which albums are already in the library
3537
const existingAlbumIds = new Set(existingAlbums.map((a) => a.foreignAlbumId));

lib/lidarr/client.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)