From d59f68b9f1e1163d5a7506cde96c77df4698eb5c Mon Sep 17 00:00:00 2001 From: Toha Date: Sat, 28 Dec 2024 20:13:53 +0700 Subject: [PATCH] Return first item of program date and icon. Signed-off-by: Toha --- sites/i.mjh.nz/i.mjh.nz.config.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/sites/i.mjh.nz/i.mjh.nz.config.js b/sites/i.mjh.nz/i.mjh.nz.config.js index c7e44c4d..f0a12a69 100644 --- a/sites/i.mjh.nz/i.mjh.nz.config.js +++ b/sites/i.mjh.nz/i.mjh.nz.config.js @@ -18,15 +18,15 @@ module.exports = { }, maxContentLength: 100 * 1024 * 1024 // 100Mb }, - url: function ({ channel }) { + url({ channel }) { const [path] = channel.site_id.split('#') return `${API_ENDPOINT}/${path}.xml` }, - parser: function ({ content, channel, date }) { + parser({ content, channel, date }) { const items = parseItems(content, channel, date) - let programs = items.map(item => { + const programs = items.map(item => { return { ...item, title: getTitle(item), @@ -36,9 +36,7 @@ module.exports = { } }) - programs = mergeMovieParts(programs) - - return programs + return mergeMovieParts(programs) }, async channels({ provider }) { const providers = { @@ -105,14 +103,14 @@ module.exports = { nz: [{ path: 'nz/epg', lang: 'en' }] } - let channels = [] + const channels = [] const providerOptions = providers[provider] for (const option of providerOptions) { const xml = await axios .get(`${API_ENDPOINT}/${option.path}.xml`) .then(r => r.data) - .catch(console.log) + .catch(console.error) const data = parser.parse(xml) data.channels.forEach(item => { @@ -129,7 +127,7 @@ module.exports = { } function mergeMovieParts(programs) { - let output = [] + const output = [] programs.forEach(prog => { let prev = output[output.length - 1] @@ -162,7 +160,7 @@ function getCategories(item) { } function getIcon(item) { - return item.icon && item.icon.length ? item.icon[0].src : null + return item.icon && item.icon.length ? item.icon[0] : null } function parseItems(content, channel, date) { @@ -173,10 +171,14 @@ function parseItems(content, channel, date) { const data = parser.parse(content) if (!data || !Array.isArray(data.programs)) return [] - return data.programs.filter( - p => - p.channel === site_id && dayjs(p.start, 'YYYYMMDDHHmmss ZZ').isBetween(curr_day, next_day) - ) + return data.programs + .filter(p => p.channel === site_id && dayjs(p.start, 'YYYYMMDDHHmmss ZZ').isBetween(curr_day, next_day)) + .map(p => { + if (Array.isArray(p.date) && p.date.length) { + p.date = p.date[0] + } + return p + }) } catch (error) { return [] }