mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 04:40:09 +00:00
Better searching when using ASIN from folder names.
This commit is contained in:
@@ -160,31 +160,27 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// If the scanner extracted an ASIN directly from the folder name,
|
// If the scanner extracted an ASIN directly from the folder name,
|
||||||
// try an exact ASIN lookup first — faster and more accurate than
|
// use a direct ASIN lookup (Audnexus API) — more reliable than a
|
||||||
// a text search. Fall back to text search if it fails or returns
|
// keyword text search. Fall back to text search if the lookup fails.
|
||||||
// no result.
|
|
||||||
let searchResult: Awaited<ReturnType<typeof audibleService.search>> | null = null;
|
|
||||||
|
|
||||||
if (book.extractedAsin) {
|
if (book.extractedAsin) {
|
||||||
try {
|
try {
|
||||||
const asinResult = await audibleService.search(book.extractedAsin);
|
const asinResult = await audibleService.getAudiobookDetails(book.extractedAsin);
|
||||||
if (
|
if (asinResult) {
|
||||||
asinResult.results.length > 0 &&
|
match = asinResult;
|
||||||
asinResult.results[0].asin === book.extractedAsin
|
|
||||||
) {
|
|
||||||
searchResult = asinResult;
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
/* ASIN lookup failed — fall through to text search */
|
/* ASIN lookup failed — fall through to text search */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!searchResult) {
|
if (!match) {
|
||||||
searchResult = await audibleService.search(book.searchTerm);
|
const searchResult = await audibleService.search(book.searchTerm);
|
||||||
|
if (searchResult.results.length > 0) {
|
||||||
|
match = searchResult.results[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchResult.results.length > 0) {
|
if (match) {
|
||||||
match = searchResult.results[0];
|
|
||||||
|
|
||||||
// Check library availability
|
// Check library availability
|
||||||
const plexMatch = await findPlexMatch({
|
const plexMatch = await findPlexMatch({
|
||||||
|
|||||||
Reference in New Issue
Block a user