Pass audnexus to AuthorCandidates constructor directly

This commit is contained in:
mikiher 2023-11-08 16:19:24 +00:00
parent ba60fc7581
commit 819c524f51

View File

@ -233,15 +233,15 @@ class BookFinder {
} }
static AuthorCandidates = class { static AuthorCandidates = class {
constructor(bookFinder, cleanAuthor) { constructor(cleanAuthor, audnexus) {
this.bookFinder = bookFinder this.audnexus = audnexus
this.candidates = new Set() this.candidates = new Set()
this.cleanAuthor = cleanAuthor this.cleanAuthor = cleanAuthor
if (cleanAuthor) this.candidates.add(cleanAuthor) if (cleanAuthor) this.candidates.add(cleanAuthor)
} }
validateAuthor(name, region = '', maxLevenshtein = 2) { validateAuthor(name, region = '', maxLevenshtein = 2) {
return this.bookFinder.audnexus.authorASINsRequest(name, region).then((asins) => { return this.audnexus.authorASINsRequest(name, region).then((asins) => {
for (const [i, asin] of asins.entries()) { for (const [i, asin] of asins.entries()) {
if (i > 10) break if (i > 10) break
let cleanName = cleanAuthorForCompares(asin.name) let cleanName = cleanAuthorForCompares(asin.name)
@ -326,7 +326,7 @@ class BookFinder {
const cleanAuthor = cleanAuthorForCompares(author) const cleanAuthor = cleanAuthorForCompares(author)
// Now run up to maxFuzzySearches fuzzy searches // Now run up to maxFuzzySearches fuzzy searches
let authorCandidates = new BookFinder.AuthorCandidates(this, cleanAuthor) let authorCandidates = new BookFinder.AuthorCandidates(cleanAuthor, this.audnexus)
// Remove underscores and parentheses with their contents, and replace with a separator // Remove underscores and parentheses with their contents, and replace with a separator
const cleanTitle = title.replace(/\[.*?\]|\(.*?\)|{.*?}|_/g, " - ") const cleanTitle = title.replace(/\[.*?\]|\(.*?\)|{.*?}|_/g, " - ")