0.10.2-9 Layout
This commit is contained in:
@@ -131,6 +131,45 @@ function normalizeAudnexChapter(entry, index) {
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeNameList(items) {
|
||||
if (!Array.isArray(items) || items.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const names = items
|
||||
.map((item) => String(item?.name || '').trim())
|
||||
.filter(Boolean);
|
||||
return names.length > 0 ? names.join(', ') : null;
|
||||
}
|
||||
|
||||
async function fetchBookByAsin(asin, region = 'de') {
|
||||
const normalizedAsin = normalizeAsin(asin);
|
||||
if (!normalizedAsin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const url = new URL(`${AUDNEX_BASE_URL}/books/${normalizedAsin}`);
|
||||
url.searchParams.set('region', String(region || 'de').trim() || 'de');
|
||||
logger.info('book:fetch:start', { asin: normalizedAsin, url: url.toString() });
|
||||
|
||||
const payload = await audnexFetch(url.toString());
|
||||
if (!payload || typeof payload !== 'object') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const narrator = normalizeNameList(payload.narrators);
|
||||
const author = normalizeNameList(payload.authors);
|
||||
const title = String(payload.title || '').trim() || null;
|
||||
const series = String(payload.seriesName || payload.series || '').trim() || null;
|
||||
const part = String(payload.seriesPart || payload.part || '').trim() || null;
|
||||
const description = String(payload.summary || payload.description || '').trim() || null;
|
||||
const year = payload.releaseDate
|
||||
? String(payload.releaseDate).slice(0, 4)
|
||||
: null;
|
||||
|
||||
logger.info('book:fetch:done', { asin: normalizedAsin, narrator, author, title });
|
||||
return { narrator, author, title, series, part, description, year };
|
||||
}
|
||||
|
||||
async function fetchChaptersByAsin(asin, region = 'de') {
|
||||
const normalizedAsin = normalizeAsin(asin);
|
||||
if (!normalizedAsin) {
|
||||
@@ -152,5 +191,6 @@ async function fetchChaptersByAsin(asin, region = 'de') {
|
||||
|
||||
module.exports = {
|
||||
extractAsinFromAaxFile,
|
||||
fetchBookByAsin,
|
||||
fetchChaptersByAsin
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user