From 426148edea2e93e5856e6422f71092f5b010b24c Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 28 Oct 2022 21:55:00 +0300 Subject: [PATCH] Update ziggogo.tv.config.js --- sites/ziggogo.tv/ziggogo.tv.config.js | 128 ++++++++++++++------------ 1 file changed, 70 insertions(+), 58 deletions(-) diff --git a/sites/ziggogo.tv/ziggogo.tv.config.js b/sites/ziggogo.tv/ziggogo.tv.config.js index d3b56f47..d216820d 100644 --- a/sites/ziggogo.tv/ziggogo.tv.config.js +++ b/sites/ziggogo.tv/ziggogo.tv.config.js @@ -1,108 +1,120 @@ const axios = require('axios') const dayjs = require('dayjs') -const API_ENDPOINT = `https://obo-prod.oesp.ziggogo.tv/oesp/v4/NL/nld/web` +const API_ENDPOINT = `https://static.spark.ziggogo.tv/eng/web/epg-service-lite` module.exports = { site: 'ziggogo.tv', - url: function ({ date }) { - return `${API_ENDPOINT}/programschedules/${date.format('YYYYMMDD')}/1` + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + url: function ({ date, channel }) { + return `${API_ENDPOINT}/nl/${channel.lang}/events/segments/${date.format('YYYYMMDDHHmmss')}` }, async parser({ content, channel, date }) { let programs = [] let items = parseItems(content, channel) if (!items.length) return programs - const d = date.format('YYYYMMDD') const promises = [ - axios.get(`${API_ENDPOINT}/programschedules/${d}/2`), - axios.get(`${API_ENDPOINT}/programschedules/${d}/3`), - axios.get(`${API_ENDPOINT}/programschedules/${d}/4`) + axios.get( + `${API_ENDPOINT}/nl/${channel.lang}/events/segments/${date + .add(6, 'h') + .format('YYYYMMDDHHmmss')}`, + { + responseType: 'arraybuffer' + } + ), + axios.get( + `${API_ENDPOINT}/nl/${channel.lang}/events/segments/${date + .add(12, 'h') + .format('YYYYMMDDHHmmss')}`, + { + responseType: 'arraybuffer' + } + ), + axios.get( + `${API_ENDPOINT}/nl/${channel.lang}/events/segments/${date + .add(18, 'h') + .format('YYYYMMDDHHmmss')}`, + { + responseType: 'arraybuffer' + } + ) ] + await Promise.allSettled(promises) .then(results => { results.forEach(r => { if (r.status === 'fulfilled') { - items = items.concat(parseItems(r.value.data, channel)) + const parsed = parseItems(r.value.data, channel) + + items = items.concat(parsed) } }) }) .catch(console.error) - // items.forEach(item => { + for (let item of items) { - const detail = await loadProgramDetails(item) - programs.push({ - title: item.t, - description: parseDescription(detail), - category: parseCategory(detail), - season: parseSeason(detail), - episode: parseEpisode(detail), - start: parseStart(item), - stop: parseStop(item) - }) + const detail = await loadProgramDetails(item, channel) + programs.push({ + title: item.title, + description: detail.longDescription, + category: detail.genres, + actors: detail.actors, + season: detail.seasonNumber, + episode: detail.episodeNumber, + start: parseStart(item), + stop: parseStop(item) + }) } - //) return programs }, async channels() { const data = await axios - .get(`${API_ENDPOINT}/channels`) + .get( + `https://prod.spark.ziggogo.tv/eng/web/linear-service/v2/channels?cityId=65535&language=en&productClass=Orion-DASH` + ) .then(r => r.data) .catch(console.log) return data.channels.map(item => { return { lang: 'be', - site_id: item.id.replace('lgi-nl-prod-master:65535-', ''), - name: item.title + site_id: item.id, + name: item.name } }) } } -async function loadProgramDetails(item) { - if (!item.i) return {} - const url = `${API_ENDPOINT}/listings/${item.i}` - const data = await axios - .get(url) - .then(r => r.data) - .catch(console.log) - return data || {} - } +async function loadProgramDetails(item, channel) { + if (!item.id) return {} + const url = `https://prod.spark.ziggogo.tv/eng/web/linear-service/v2/replayEvent/${item.id}?returnLinearContent=true&language=${channel.lang}` + const data = await axios + .get(url) + .then(r => r.data) + .catch(console.log) + + return data || {} +} function parseStart(item) { - return dayjs(item.s) + return dayjs.unix(item.startTime) } function parseStop(item) { - return dayjs(item.e) + return dayjs.unix(item.endTime) } function parseItems(content, channel) { - const data = typeof content === 'string' ? JSON.parse(content) : content + if (!content) return [] + const data = JSON.parse(content) if (!data || !Array.isArray(data.entries)) return [] - const entity = data.entries.find(e => e.o === `lgi-nl-prod-master:${channel.site_id}`) + const channelData = data.entries.find(e => e.channelId === channel.site_id) + if (!channelData) return [] - return entity ? entity.l : [] + return Array.isArray(channelData.events) ? channelData.events : [] } - -function parseDescription(detail){ - return detail.program.longDescription || null -} - -function parseCategory(detail) { - let categories = [] - detail.program.categories.forEach(category => { - categories.push(category.title) - }); - return categories - } - - function parseSeason(detail) { - return detail.program.seriesNumber || null - } - - function parseEpisode(detail) { - return detail.program.seriesEpisodeNumber || null - } -