mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Return first item of program date and icon.
Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
parent
e1cda12de3
commit
d59f68b9f1
1 changed files with 16 additions and 14 deletions
|
@ -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 []
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue