From f72c659246b43eb15e6fe88bb620d86945885739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 25 Sep 2025 16:13:45 +0000 Subject: [PATCH] add config --- sites/vodafone.pt/vodafone.pt.config.js | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/sites/vodafone.pt/vodafone.pt.config.js b/sites/vodafone.pt/vodafone.pt.config.js index e69de29b..2726cb94 100644 --- a/sites/vodafone.pt/vodafone.pt.config.js +++ b/sites/vodafone.pt/vodafone.pt.config.js @@ -0,0 +1,78 @@ +const { DateTime } = require('luxon') +const axios = require('axios') + +const API_ENDPOINT = 'https://cdn.pt.vtv.vodafone.com/epg' + +module.exports = { + site: 'vodafone.pt', + days: 2, + headers: { + Origin: 'https://www.vodafone.pt', + Referer: 'https://www.vodafone.pt/', + 'User-Agent': 'Mozilla/5.0 (compatible; tv_grab_pt_vodafone)', + Accept: 'application/json, text/javascript, */*; q=0.01', + 'Accept-Language': 'pt-PT,pt;q=0.9,en;q=0.8' + }, + url: function ({ channel, date }) { + const datetime = DateTime.fromJSDate(date.toDate()).setZone('Europe/Lisbon') + const month = datetime.month + const formattedMonth = month < 10 ? `0${month}` : month + const formattedDay = datetime.day < 10 ? `0${datetime.day}` : datetime.day + return `${API_ENDPOINT}/${channel.site_id}/${date.year()}/${formattedMonth}/${formattedDay}/00-06` + }, + async parser({ content, date, channel }) { + let programs = [] + let items = parseItems(content) + if (!items.length) return programs + const datetime = DateTime.fromJSDate(date.toDate()).setZone('Europe/Lisbon') + const month = datetime.month + const formattedMonth = month < 10 ? `0${month}` : month + const formattedDay = datetime.day < 10 ? `0${datetime.day}` : datetime.day + // map all periods of time to promises in order to get a full schedule in one row + const promises = [ + axios.get(`${API_ENDPOINT}${channel.site_id}/${date.year()}/${formattedMonth}/${formattedDay}/06-12`, { headers: this.headers }), + axios.get(`${API_ENDPOINT}${channel.site_id}/${date.year()}/${formattedMonth}/${formattedDay}/12-18`, { headers: this.headers }), + axios.get(`${API_ENDPOINT}${channel.site_id}/${date.year()}/${formattedMonth}/${formattedDay}/18-24`, { headers: this.headers }) + ] + await Promise.allSettled(promises).then(results => { + results.forEach(r => { + if (r.status === 'fulfilled') { + items = items.concat(parseItems(r.value.data)) + } + }) + }) + for (let item of items) { + if (!item.startDate || !item.endDate) return + let start = DateTime.fromSeconds(item.startDate, { zone: 'UTC' }).toUTC() + let stop = DateTime.fromSeconds(item.endDate, { zone: 'UTC' }).toUTC() + if (stop < start) { + stop = stop.plus({ days: 1 }) + } + const prog = { + title: item.name || 'Sem título', + start, + stop + } + if (item.description) prog.description = item.description + if (item.metas?.year?.value) prog.year = item.metas.year.value + if (item.tags?.genre?.objects) { + prog.category = item.tags.genre.objects.map(g => g.value) + } + programs.push(prog) + } + return programs + } +} + +function parseItems(content) { + let json + try { + json = typeof content === 'string' ? JSON.parse(content) : content + } catch { + return [] + } + if (!json || !json.result) return [] + const { result } = json + if (!Array.isArray(result.objects)) return [] + return result.objects +} \ No newline at end of file