mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-22 11:49: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) : []
|
||||
const tagsFiltered = genres ? genres.filter((g) => g.type == 'tag').map((g) => g.name) : []
|
||||
let genresCleaned = null
|
||||
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 {
|
||||
title,
|
||||
|
|
@ -71,8 +76,8 @@ class Audible {
|
|||
cover: image,
|
||||
asin,
|
||||
isbn,
|
||||
genres: genresFiltered.length ? genresFiltered : null,
|
||||
tags: tagsFiltered.length ? tagsFiltered.join(', ') : null,
|
||||
genres: genresCleaned.length ? genresCleaned : null,
|
||||
tags: tagsCleaned.length ? tagsCleaned : null,
|
||||
series: series.length ? series : null,
|
||||
language: language ? language.charAt(0).toUpperCase() + language.slice(1) : null,
|
||||
duration: runtimeLengthMin && !isNaN(runtimeLengthMin) ? Number(runtimeLengthMin) : 0,
|
||||
|
|
|
|||
|
|
@ -89,6 +89,27 @@ class CustomProviderAdapter {
|
|||
})
|
||||
.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
|
||||
return matches.map((match) => {
|
||||
|
|
@ -105,8 +126,8 @@ class CustomProviderAdapter {
|
|||
cover: toStringOrUndefined(cover),
|
||||
isbn: toStringOrUndefined(isbn),
|
||||
asin: toStringOrUndefined(asin),
|
||||
genres: Array.isArray(genres) && genres.every((g) => typeof g === 'string') ? genres : undefined,
|
||||
tags: toStringOrUndefined(tags),
|
||||
genres: validateTagsGenresArray(genres),
|
||||
tags: validateTagsGenresArray(tags),
|
||||
series: validateSeriesArray(series),
|
||||
language: toStringOrUndefined(language),
|
||||
duration: !isNaN(duration) && duration !== null ? Number(duration) : undefined
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue