mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-22 19:59:37 +00:00
Book tags genres dedupe (#4927)
* Update Audible provider dedupe genres/tags and return tags as array * Update custom metadata provider to dedupe tags/genres and return tags as array
This commit is contained in:
parent
088353ae26
commit
7b37c98e88
2 changed files with 32 additions and 6 deletions
|
|
@ -57,8 +57,13 @@ class Audible {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const genresFiltered = genres ? genres.filter((g) => g.type == 'genre').map((g) => g.name) : []
|
let genresCleaned = null
|
||||||
const tagsFiltered = genres ? genres.filter((g) => g.type == 'tag').map((g) => g.name) : []
|
let tagsCleaned = null
|
||||||
|
|
||||||
|
if (genres && Array.isArray(genres)) {
|
||||||
|
genresCleaned = [...new Set(genres.filter((g) => g.type == 'genre').map((g) => g.name))]
|
||||||
|
tagsCleaned = [...new Set(genres.filter((g) => g.type == 'tag').map((g) => g.name))]
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
|
|
@ -71,8 +76,8 @@ class Audible {
|
||||||
cover: image,
|
cover: image,
|
||||||
asin,
|
asin,
|
||||||
isbn,
|
isbn,
|
||||||
genres: genresFiltered.length ? genresFiltered : null,
|
genres: genresCleaned.length ? genresCleaned : null,
|
||||||
tags: tagsFiltered.length ? tagsFiltered.join(', ') : null,
|
tags: tagsCleaned.length ? tagsCleaned : null,
|
||||||
series: series.length ? series : null,
|
series: series.length ? series : null,
|
||||||
language: language ? language.charAt(0).toUpperCase() + language.slice(1) : null,
|
language: language ? language.charAt(0).toUpperCase() + language.slice(1) : null,
|
||||||
duration: runtimeLengthMin && !isNaN(runtimeLengthMin) ? Number(runtimeLengthMin) : 0,
|
duration: runtimeLengthMin && !isNaN(runtimeLengthMin) ? Number(runtimeLengthMin) : 0,
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,27 @@ class CustomProviderAdapter {
|
||||||
})
|
})
|
||||||
.filter((s) => s !== undefined)
|
.filter((s) => s !== undefined)
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Validates and dedupes tags/genres array
|
||||||
|
* Can be comma separated string or array of strings
|
||||||
|
* @param {string|string[]} tagsGenres
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
const validateTagsGenresArray = (tagsGenres) => {
|
||||||
|
if (!tagsGenres || (typeof tagsGenres !== 'string' && !Array.isArray(tagsGenres))) return undefined
|
||||||
|
|
||||||
|
// If string, split by comma and trim each item
|
||||||
|
if (typeof tagsGenres === 'string') tagsGenres = tagsGenres.split(',')
|
||||||
|
// If array, ensure all items are strings
|
||||||
|
else if (!tagsGenres.every((t) => typeof t === 'string')) return undefined
|
||||||
|
|
||||||
|
// Trim and filter out empty strings
|
||||||
|
tagsGenres = tagsGenres.map((t) => t.trim()).filter(Boolean)
|
||||||
|
if (!tagsGenres.length) return undefined
|
||||||
|
|
||||||
|
// Dedup
|
||||||
|
return [...new Set(tagsGenres)]
|
||||||
|
}
|
||||||
|
|
||||||
// re-map keys to throw out
|
// re-map keys to throw out
|
||||||
return matches.map((match) => {
|
return matches.map((match) => {
|
||||||
|
|
@ -105,8 +126,8 @@ class CustomProviderAdapter {
|
||||||
cover: toStringOrUndefined(cover),
|
cover: toStringOrUndefined(cover),
|
||||||
isbn: toStringOrUndefined(isbn),
|
isbn: toStringOrUndefined(isbn),
|
||||||
asin: toStringOrUndefined(asin),
|
asin: toStringOrUndefined(asin),
|
||||||
genres: Array.isArray(genres) && genres.every((g) => typeof g === 'string') ? genres : undefined,
|
genres: validateTagsGenresArray(genres),
|
||||||
tags: toStringOrUndefined(tags),
|
tags: validateTagsGenresArray(tags),
|
||||||
series: validateSeriesArray(series),
|
series: validateSeriesArray(series),
|
||||||
language: toStringOrUndefined(language),
|
language: toStringOrUndefined(language),
|
||||||
duration: !isNaN(duration) && duration !== null ? Number(duration) : undefined
|
duration: !isNaN(duration) && duration !== null ? Number(duration) : undefined
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue