mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-04-20 01:17:45 +02:00
Update:Clean series sequence response from audible provider #2380
- Removes Book prefix - Splits on spaces and takes first, removes trailing comma
This commit is contained in:
parent
34156af403
commit
b5e255a384
@ -18,6 +18,27 @@ class Audible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Audible will sometimes send sequences with "Book 1" or "2, Dramatized Adaptation"
|
||||||
|
* @see https://github.com/advplyr/audiobookshelf/issues/2380
|
||||||
|
* @see https://github.com/advplyr/audiobookshelf/issues/1339
|
||||||
|
*
|
||||||
|
* @param {string} seriesName
|
||||||
|
* @param {string} sequence
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
cleanSeriesSequence(seriesName, sequence) {
|
||||||
|
if (!sequence) return ''
|
||||||
|
let updatedSequence = sequence.replace(/Book /, '').trim()
|
||||||
|
if (updatedSequence.includes(' ')) {
|
||||||
|
updatedSequence = updatedSequence.split(' ').shift().replace(/,$/, '')
|
||||||
|
}
|
||||||
|
if (sequence !== updatedSequence) {
|
||||||
|
Logger.debug(`[Audible] Series "${seriesName}" sequence was cleaned from "${sequence}" to "${updatedSequence}"`)
|
||||||
|
}
|
||||||
|
return updatedSequence
|
||||||
|
}
|
||||||
|
|
||||||
cleanResult(item) {
|
cleanResult(item) {
|
||||||
const { title, subtitle, asin, authors, narrators, publisherName, summary, releaseDate, image, genres, seriesPrimary, seriesSecondary, language, runtimeLengthMin, formatType } = item
|
const { title, subtitle, asin, authors, narrators, publisherName, summary, releaseDate, image, genres, seriesPrimary, seriesSecondary, language, runtimeLengthMin, formatType } = item
|
||||||
|
|
||||||
@ -25,13 +46,13 @@ class Audible {
|
|||||||
if (seriesPrimary) {
|
if (seriesPrimary) {
|
||||||
series.push({
|
series.push({
|
||||||
series: seriesPrimary.name,
|
series: seriesPrimary.name,
|
||||||
sequence: (seriesPrimary.position || '').replace(/Book /, '') // Can be badly formatted see #1339
|
sequence: this.cleanSeriesSequence(seriesPrimary.name, seriesPrimary.position || '')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (seriesSecondary) {
|
if (seriesSecondary) {
|
||||||
series.push({
|
series.push({
|
||||||
series: seriesSecondary.name,
|
series: seriesSecondary.name,
|
||||||
sequence: (seriesSecondary.position || '').replace(/Book /, '')
|
sequence: this.cleanSeriesSequence(seriesSecondary.name, seriesSecondary.position || '')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +85,7 @@ class Audible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
asinSearch(asin, region) {
|
asinSearch(asin, region) {
|
||||||
asin = encodeURIComponent(asin);
|
asin = encodeURIComponent(asin)
|
||||||
var regionQuery = region ? `?region=${region}` : ''
|
var regionQuery = region ? `?region=${region}` : ''
|
||||||
var url = `https://api.audnex.us/books/${asin}${regionQuery}`
|
var url = `https://api.audnex.us/books/${asin}${regionQuery}`
|
||||||
Logger.debug(`[Audible] ASIN url: ${url}`)
|
Logger.debug(`[Audible] ASIN url: ${url}`)
|
||||||
|
Loading…
Reference in New Issue
Block a user