mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-02 20:30:10 +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();
|
const audibleService = getAudibleService();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const searchQuery = `${book.title} ${book.author}`;
|
// Try full Goodreads title first, then fall back to stripped title
|
||||||
log.info(`Searching Audible for: "${searchQuery}"`);
|
// (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);
|
let searchResult = await audibleService.search(fullQuery);
|
||||||
const firstResult = searchResult.results[0];
|
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) {
|
if (firstResult?.asin) {
|
||||||
log.info(`Audible match: "${book.title}" → ASIN ${firstResult.asin} ("${firstResult.title}" by ${firstResult.author})`);
|
log.info(`Audible match: "${book.title}" → ASIN ${firstResult.asin} ("${firstResult.title}" by ${firstResult.author})`);
|
||||||
|
|||||||
Reference in New Issue
Block a user