Files

93 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2026-04-09 00:02:18 +02:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
2026-04-15 10:52:28 +02:00
const customParseFormat = require('dayjs/plugin/customParseFormat')
2026-04-09 00:02:18 +02:00
const timezone = require('dayjs/plugin/timezone')
2026-04-15 10:52:28 +02:00
dayjs.extend(customParseFormat)
2026-04-09 00:02:18 +02:00
dayjs.extend(utc)
dayjs.extend(timezone)
2025-09-28 17:55:05 +03:00
module.exports = {
site: 'tivu.tv',
days: 2,
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
2026-04-15 10:52:28 +02:00
url({ channel, date }) {
date = date.startOf('day')
return `https://services.tivulaguida.it/api/epg/channels/${channel.site_id}/date/${date.format('YYYY-MM-DD')}`
2025-09-28 17:55:05 +03:00
},
2026-04-15 10:52:28 +02:00
parser: async function ({ content, channel, date }) {
const axios = require('axios')
2025-09-28 17:55:05 +03:00
let programs = []
2026-04-15 10:52:28 +02:00
const items = JSON.parse(content)
if (!items || !Array.isArray(items.events)) return programs
const previousDay = date.subtract(1, 'day')
let urlDayBefore
try {
const response = await axios.get(
`https://services.tivulaguida.it/api/epg/channels/${channel.site_id}/date/${previousDay.format('YYYY-MM-DD')}`
)
urlDayBefore = response?.data
} catch (error) {
console.log(error)
}
const allEvents = [
...(urlDayBefore?.events || []),
...items.events
]
const midnight = dayjs.tz(date.format('YYYY-MM-DD 00:00'), 'YYYY-MM-DD HH:mm', 'Europe/Rome')
const nextMidnight = midnight.add(1, 'day')
const seen = new Set()
allEvents.forEach(item => {
if (!item.program) return
const start = dayjs.tz(item.date_start, 'DD-MM-YYYY HH:mm', 'Europe/Rome')
const stop = dayjs.tz(item.date_end, 'DD-MM-YYYY HH:mm', 'Europe/Rome')
if (start.isBefore(midnight) || !start.isBefore(nextMidnight)) return
const key = `${start.format()}|${stop.format()}`
if (seen.has(key)) return
seen.add(key)
2025-09-28 17:55:05 +03:00
programs.push({
2026-04-15 10:52:28 +02:00
title: item.program.title,
2025-09-28 17:55:05 +03:00
start,
2026-04-15 10:52:28 +02:00
stop,
description: item.program.description,
icon: item.program.url_poster
2025-09-28 17:55:05 +03:00
})
})
return programs
},
async channels() {
const axios = require('axios')
const html = await axios
2026-04-15 10:52:28 +02:00
.get('https://services.tivulaguida.it/api/epg/channels.json')
2025-09-28 17:55:05 +03:00
.then(r => r.data)
.catch(console.log)
let channels = []
2026-04-15 10:52:28 +02:00
if (html && html.channels) {
html.channels.forEach(channel => {
channels.push({
lang: 'it',
site_id: channel.id,
name: channel.name,
logo: 'https://services.tivulaguida.it/' + channel.icon
})
2025-09-28 17:55:05 +03:00
})
2026-04-15 10:52:28 +02:00
}
2025-09-28 17:55:05 +03:00
return channels
}
}