From e40e77c8fe6ae546d543c73a154b4a1176f099ca Mon Sep 17 00:00:00 2001 From: kikootwo Date: Thu, 12 Feb 2026 11:13:06 -0500 Subject: [PATCH] Retry Audible search without series info Try the full Goodreads title first; if no ASIN is found, strip trailing parenthetical series info (e.g. "(Series, #2)"), retry the Audible search with the cleaned title, and add informative logs. This fixes failed Audible lookups caused by Goodreads titles that include series metadata. --- src/lib/services/goodreads-sync.service.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/lib/services/goodreads-sync.service.ts b/src/lib/services/goodreads-sync.service.ts index 1c90a5d..8653435 100644 --- a/src/lib/services/goodreads-sync.service.ts +++ b/src/lib/services/goodreads-sync.service.ts @@ -289,11 +289,23 @@ async function performAudibleLookup( const audibleService = getAudibleService(); try { - const searchQuery = `${book.title} ${book.author}`; - log.info(`Searching Audible for: "${searchQuery}"`); + // Try full Goodreads title first, then fall back to stripped title + // (Goodreads titles often include series info like "(Demonica, #2)" that return 0 Audible results) + const fullQuery = `${book.title} ${book.author}`; + log.info(`Searching Audible for: "${fullQuery}"`); - const searchResult = await audibleService.search(searchQuery); - const firstResult = searchResult.results[0]; + let searchResult = await audibleService.search(fullQuery); + let firstResult = searchResult.results[0]; + + if (!firstResult?.asin) { + const cleanTitle = book.title.replace(/\s*\(.*\)\s*$/, '').trim(); + if (cleanTitle !== book.title) { + const cleanQuery = `${cleanTitle} ${book.author}`; + log.info(`No results with full title, retrying without series info: "${cleanQuery}"`); + searchResult = await audibleService.search(cleanQuery); + firstResult = searchResult.results[0]; + } + } if (firstResult?.asin) { log.info(`Audible match: "${book.title}" → ASIN ${firstResult.asin} ("${firstResult.title}" by ${firstResult.author})`);