Skip to content

Commit

Permalink
fix(helper): 🐛 some region author pages could get redirected
Browse files Browse the repository at this point in the history
avoid this by using redirectOverride options; also improve getName function; fix buildUrl params option
  • Loading branch information
djdembeck committed Mar 6, 2023
1 parent ea338fa commit ddf2d22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/helpers/authors/audible/ScrapeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class ScrapeHelper {
const baseDomain = 'https://www.audible'
const regionTLD = regions[region].tld
const baseUrl = 'author'
this.reqUrl = this.helper.buildUrl(asin, baseDomain, regionTLD, baseUrl)
// We need to override the base country to get the correct author page
const params = 'ipRedirectOverride=true&overrideBaseCountry=true'
this.reqUrl = this.helper.buildUrl(asin, baseDomain, regionTLD, baseUrl, params)
}

/**
Expand Down Expand Up @@ -59,13 +61,15 @@ class ScrapeHelper {
}

getName(dom: cheerio.CheerioAPI): string {
let nameText: Text
let name: string
// First try to get valid author text
try {
const html = dom('h1.bc-text-bold')[0].children[0]
nameText = html as unknown as Text
name = nameText.data.trim()
const html = dom(
'h1.bc-heading.bc-color-base.bc-size-extra-large.bc-text-secondary.bc-text-bold'
)
.first()
.text()
name = html
} catch (error) {
throw new Error(ErrorMessageNotFound(this.asin, 'author name'))
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class SharedHelper {
params?: string
): string {
const FQDN = `${baseDomain}.${regionTLD}`
const argArr = [FQDN, baseUrl, ASIN, params]
const reqUrl = argArr.join('/')
const argArr = [FQDN, baseUrl, ASIN]
const reqUrl = argArr.join('/') + (params ? `?${params}` : '')
return reqUrl
}

Expand Down

0 comments on commit ddf2d22

Please sign in to comment.