Update horizon.tv.config.js

This commit is contained in:
Aleksandr Statciuk 2022-10-30 01:31:35 +03:00
parent 87de28d0a3
commit c479457aea

View file

@ -1,22 +1,25 @@
const axios = require('axios') const axios = require('axios')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const API_ENDPOINT = `https://legacy-static.oesp.horizon.tv/oesp/v4/DE/deu/web/programschedules` const API_ENDPOINT = `https://legacy-static.oesp.horizon.tv/oesp/v4`
module.exports = { module.exports = {
site: 'horizon.tv', site: 'horizon.tv',
url: function ({ date }) { url: function ({ date, channel }) {
return `${API_ENDPOINT}/${date.format('YYYYMMDD')}/1` const [country, lang] = channel.site_id.split('#')
return `${API_ENDPOINT}/${country}/${lang}/web/programschedules/${date.format('YYYYMMDD')}/1`
}, },
async parser({ content, channel, date }) { async parser({ content, channel, date }) {
const [country, lang] = channel.site_id.split('#')
let programs = [] let programs = []
let items = parseItems(content, channel) let items = parseItems(content, channel)
if (!items.length) return programs if (!items.length) return programs
const d = date.format('YYYYMMDD') const d = date.format('YYYYMMDD')
const promises = [ const promises = [
axios.get(`${API_ENDPOINT}/${d}/2`), axios.get(`${API_ENDPOINT}/${country}/${lang}/web/programschedules/${d}/2`),
axios.get(`${API_ENDPOINT}/${d}/3`), axios.get(`${API_ENDPOINT}/${country}/${lang}/web/programschedules/${d}/3`),
axios.get(`${API_ENDPOINT}/${d}/4`) axios.get(`${API_ENDPOINT}/${country}/${lang}/web/programschedules/${d}/4`)
] ]
await Promise.allSettled(promises) await Promise.allSettled(promises)
.then(results => { .then(results => {
@ -37,16 +40,17 @@ module.exports = {
return programs return programs
}, },
async channels() { async channels({ country, lang }) {
const langs = { deu: 'de', slk: 'sk' }
const data = await axios const data = await axios
.get(`https://legacy-dynamic.oesp.horizon.tv/oesp/v4/DE/deu/web/channels`) .get(`https://legacy-dynamic.oesp.horizon.tv/oesp/v4/${country}/${lang}/web/channels`)
.then(r => r.data) .then(r => r.data)
.catch(console.log) .catch(console.log)
return data.channels.map(item => { return data.channels.map(item => {
return { return {
lang: 'de', lang: langs[lang],
site_id: item.id.replace('lgi-obolite-de-prod-master:65535-', ''), site_id: `${country}#${lang}#${item.stationSchedules[0].station.id}`,
name: item.title name: item.title
} }
}) })
@ -62,9 +66,10 @@ function parseStop(item) {
} }
function parseItems(content, channel) { function parseItems(content, channel) {
const [_, __, channelId] = channel.site_id.split('#')
const data = typeof content === 'string' ? JSON.parse(content) : content const data = typeof content === 'string' ? JSON.parse(content) : content
if (!data || !Array.isArray(data.entries)) return [] if (!data || !Array.isArray(data.entries)) return []
const entity = data.entries.find(e => e.o === `lgi-obolite-de-prod-master:${channel.site_id}`) const entity = data.entries.find(e => e.o === channelId)
return entity ? entity.l : [] return entity ? entity.l : []
} }