mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Create opto.sic.pt.config.js
This commit is contained in:
parent
cb1921d008
commit
f2311ca484
1 changed files with 53 additions and 0 deletions
53
sites/opto.sic.pt/opto.sic.pt.config.js
Normal file
53
sites/opto.sic.pt/opto.sic.pt.config.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'opto.sic.pt',
|
||||
days: 2,
|
||||
url({ date, channel }) {
|
||||
const startDate = date.unix()
|
||||
const endDate = date.add(1, 'd').unix()
|
||||
|
||||
return `https://opto.sic.pt/api/v1/content/epg?startDate=${startDate}&endDate=${endDate}&channels=${channel.site_id}`
|
||||
},
|
||||
parser({ content }) {
|
||||
let programs = []
|
||||
let items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
episode: item.episode_number || null,
|
||||
season: item.season_number || null,
|
||||
start: dayjs.unix(item.start_time),
|
||||
stop: dayjs.unix(item.end_time)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://opto.sic.pt/api/v1/content/channel')
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data.map(channel => {
|
||||
return {
|
||||
lang: 'pt',
|
||||
site_id: channel.id,
|
||||
name: channel.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
if (!Array.isArray(data)) return []
|
||||
|
||||
return data
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue