mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update i.mjh.nz.config.js
This commit is contained in:
parent
72f0ab12e6
commit
4b95ac16f8
1 changed files with 16 additions and 53 deletions
|
@ -7,78 +7,41 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(isBetween)
|
dayjs.extend(isBetween)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
const API_ENDPOINT = 'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'i.mjh.nz',
|
site: 'i.mjh.nz',
|
||||||
request: {
|
request: {
|
||||||
cache: {
|
cache: {
|
||||||
ttl: 6 * 60 * 60 * 1000 // 6h
|
ttl: 3 * 60 * 60 * 1000 // 3h
|
||||||
},
|
},
|
||||||
maxContentLength: 20 * 1024 * 1024 // 20Mb
|
maxContentLength: 30 * 1024 * 1024 // 30Mb
|
||||||
},
|
},
|
||||||
url: function ({ channel }) {
|
url: function ({ channel }) {
|
||||||
const [source] = channel.site_id.split('#')
|
const [path] = channel.site_id.split('#')
|
||||||
|
|
||||||
return `https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/${source}.xml`
|
return `${API_ENDPOINT}/${path}.xml`
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel, date, cached }) {
|
parser: function ({ content, channel, date, cached }) {
|
||||||
let programs = []
|
return parseItems(content, channel, date)
|
||||||
const items = parseItems(content, channel, date)
|
|
||||||
items.forEach(item => {
|
|
||||||
programs.push({
|
|
||||||
title: parseTitle(item, channel),
|
|
||||||
description: parseDescription(item, channel),
|
|
||||||
category: parseCategory(item, channel),
|
|
||||||
start: parseStart(item),
|
|
||||||
stop: parseStop(item)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
return programs
|
|
||||||
},
|
},
|
||||||
async channels({ path, lang = 'en' }) {
|
async channels({ path, lang = 'en' }) {
|
||||||
const [service] = path.split('/')
|
let xml = await axios
|
||||||
let data = await axios
|
.get(`${API_ENDPOINT}/${path}.xml`)
|
||||||
.get(`https://i.mjh.nz/${service}/app.json`)
|
|
||||||
.then(r => r.data)
|
.then(r => r.data)
|
||||||
.catch(console.log)
|
.catch(console.log)
|
||||||
|
let data = parser.parse(xml)
|
||||||
|
|
||||||
const channels = []
|
return data.channels.map(channel => {
|
||||||
const items = data.channels || data
|
return {
|
||||||
for (let id in items) {
|
|
||||||
const channel = items[id]
|
|
||||||
channels.push({
|
|
||||||
lang,
|
lang,
|
||||||
site_id: `${path}#${id}`,
|
site_id: `${path}#${channel.id}`,
|
||||||
name: channel.name
|
name: channel.name[0].value
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
return channels
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item, channel) {
|
|
||||||
return item.title.length ? item.title[0].value : null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseDescription(item, channel) {
|
|
||||||
return item.desc.length ? item.desc[0].value : null
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCategory(item, channel) {
|
|
||||||
const category = item.category.length ? item.category[0].value : ''
|
|
||||||
|
|
||||||
return category.split(/\s\&\;\s/g).filter(c => c)
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStart(item) {
|
|
||||||
return dayjs(item.start, 'YYYYMMDDHHmmss ZZ')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStop(item) {
|
|
||||||
return dayjs(item.stop, 'YYYYMMDDHHmmss ZZ')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(content, channel, date) {
|
function parseItems(content, channel, date) {
|
||||||
try {
|
try {
|
||||||
const curr_day = date
|
const curr_day = date
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue