If ASIN lookup fails, use the folder name instead of the tag.

This commit is contained in:
Mattias Carlsson
2026-04-19 22:09:46 +02:00
parent 7b01cda955
commit c9392c49c9
+15 -1
View File
@@ -174,7 +174,21 @@ export async function POST(request: NextRequest) {
}
if (!match) {
const searchResult = await audibleService.search(book.searchTerm);
// When an ASIN was extracted from the folder name but the direct
// lookup failed, prefer the folder name as the text search term
// over book.searchTerm. book.searchTerm may come from a single
// tagged file whose album tag is unreliable (e.g. a series name
// or intro track), whereas the folder name is the human-assigned
// title and is more likely to be accurate.
const textSearchTerm = book.extractedAsin
? book.folderName
.replace(/[\[\(][A-Z0-9]{10}[\]\)]/g, '') // strip ASIN
.replace(/[\[\(]\d{4}[\]\)]/g, '') // strip year
.replace(/[_]/g, ' ')
.replace(/\s+/g, ' ')
.trim()
: book.searchTerm;
const searchResult = await audibleService.search(textSearchTerm);
if (searchResult.results.length > 0) {
match = searchResult.results[0];
}