From 0e72cce51fbddd06ea15041f5204b9668c2bd705 Mon Sep 17 00:00:00 2001 From: David Claeys Date: Mon, 2 Dec 2024 14:05:42 +0100 Subject: [PATCH] update orangetv.es custom fix --- fixes/orangetv.es/orangetv.es.config.js | 32 ++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/fixes/orangetv.es/orangetv.es.config.js b/fixes/orangetv.es/orangetv.es.config.js index a1717ae..9371507 100644 --- a/fixes/orangetv.es/orangetv.es.config.js +++ b/fixes/orangetv.es/orangetv.es.config.js @@ -3,6 +3,7 @@ // for now the source code can be found at https://github.com/davidclaeysquinones/epg/tree/orangetv.orange.es const dayjs = require('dayjs') +const axios = require('axios') const API_PROGRAM_ENDPOINT = 'https://epg.orangetv.orange.es/epg/Smartphone_Android/1_PRO' const API_CHANNEL_ENDPOINT = 'https://pc.orangetv.orange.es/pc/api/rtv/v1/GetChannelList?bouquet_id=1&model_external_id=PC&filter_unsupported_channels=false&client=json' @@ -21,9 +22,34 @@ module.exports = { url({ date }) { return `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_1.json` }, - parser: function ({ content, channel }) { + async parser({ content, channel, date }) { + let items = [] + + const promises = [ + axios.get( + `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_1.json`, + ), + axios.get( + `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_2.json`, + ), + axios.get( + `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_3.json`, + ), + ] + + await Promise.all(promises) + .then(results => { + results.forEach(r => { + const responseContent = r.data + items = items.concat(parseItems(responseContent, channel)) + }) + }) + .catch(console.error) + + // remove duplicates + items = items.filter((item, index) => items.findIndex(oi => oi.id === item.id) === index); + let programs = [] - const items = parseItems(content, channel) items.forEach(item => { programs.push({ title: item.name, @@ -69,7 +95,7 @@ function parseIcon(item){ } function parseItems(content, channel) { - const json = typeof content === 'string' ? JSON.parse(content) : content + const json = typeof content === 'string' ? JSON.parse(content) : typeof content === 'object' ? content : [] const channelData = json.find(i => i.channelExternalId == channel.site_id);