mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 12:50:09 +00:00
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.
This commit is contained in:
@@ -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})`);
|
||||
|
||||
Reference in New Issue
Block a user