update orangetv.orange.es

This commit is contained in:
David Claeys 2025-01-13 11:00:37 +01:00
parent 075ac41e2a
commit 8736114213

View File

@ -1,11 +1,15 @@
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const axios = require('axios') const doFetch = require('@ntlab/sfetch')
const debug = require('debug')('site:orangetv.orange.es')
dayjs.extend(utc) dayjs.extend(utc)
doFetch.setDebugger(debug)
const API_PROGRAM_ENDPOINT = 'https://epg.orangetv.orange.es/epg/Smartphone_Android/1_PRO' 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' 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'
const API_IMAGE_ENDPOINT = 'https://pc.orangetv.orange.es/pc/api/rtv/v1/images' const API_IMAGE_ENDPOINT = 'https://pc.orangetv.orange.es/pc/api/rtv/v1/images'
module.exports = { module.exports = {
@ -13,53 +17,39 @@ module.exports = {
days: 2, days: 2,
request: { request: {
cache: { cache: {
ttl: 60 * 60 * 1000 // 1 hour ttl: 24 * 60 * 60 * 1000 // 1 day
} }
}, },
url({ date }) { url({ date, segment = 1 }) {
return `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_1.json` return `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_${segment}.json`
}, },
async parser({ content, channel, date }) { async parser({ content, channel, date }) {
let programs = [] const programs = []
let items = parseItems(content, channel) const items = parseItems(content, channel)
if (!items.length) return programs if (items.length) {
const queues = [
const promises = [ module.exports.url({ date, segment: 2 }),
axios.get( module.exports.url({ date, segment: 3 })
`${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_1.json`, ]
), await doFetch(queues, (url, res) => {
axios.get( items.push(...parseItems(res, channel))
`${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_2.json`, })
), programs.push(
axios.get( ...items.map(item => {
`${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_3.json`, return {
), title: item.name,
] sub_title: item.seriesName,
description: item.description,
await Promise.allSettled(promises) category: parseGenres(item),
.then(results => { season: item.seriesSeason ? parseInt(item.seriesSeason) : null,
results.forEach(r => { episode: item.episodeId ? parseInt(item.episodeId) : null,
if (r.status === 'fulfilled') { icon: parseIcon(item),
const parsed = parseItems(r.value.data, channel) start: dayjs.utc(item.startDate),
stop: dayjs.utc(item.endDate)
items = items.filter((item, index) => items.findIndex(oi => oi.id === item.id) === index).concat(parsed)
} }
}) })
}) )
.catch(console.error) }
items.forEach(item => {
programs.push({
title: item.name,
description: item.description,
category: parseGenres(item),
season: item.seriesSeason || null,
episode: item.episodeId || null,
icon: parseIcon(item),
start: dayjs.utc(item.startDate) || null,
stop: dayjs.utc(item.endDate) || null,
})
})
return programs return programs
}, },
@ -68,46 +58,42 @@ module.exports = {
const data = await axios const data = await axios
.get(API_CHANNEL_ENDPOINT) .get(API_CHANNEL_ENDPOINT)
.then(r => r.data) .then(r => r.data)
.catch(console.log) .catch(console.error)
return data.response.map(item => { return data.response.map(item => {
return { return {
lang: 'es', lang: 'es',
name: item.name, name: item.name,
site_id: item.externalChannelId site_id: item.externalChannelId
} }
}) })
} }
} }
function parseIcon(item){ function parseIcon(item) {
if (item.attachments.length) {
if(item.attachments.length > 0){ const cover = item.attachments.find(i => i.name.match(/cover/i))
const cover = item.attachments.find(i => i.name === "COVER" || i.name === "cover") if (cover) {
return `${API_IMAGE_ENDPOINT}${cover.value}`
if(cover)
{
return `${API_IMAGE_ENDPOINT}${cover.value}`;
} }
} }
return ''
} }
function parseGenres(item){ function parseGenres(item) {
return item.genres.map(i => i.name); return item.genres.map(i => i.name)
} }
function parseItems(content, channel) { function parseItems(content, channel) {
const json = typeof content === 'string' ? JSON.parse(content) : Array.isArray(content) ? content : [] const result = []
const json =
if (!Array.isArray(json)) { typeof content === 'string' ? JSON.parse(content) : Array.isArray(content) ? content : []
return []; if (Array.isArray(json)) {
json
.filter(i => i.channelExternalId === channel.site_id)
.forEach(i => {
result.push(...i.programs)
})
} }
const channelData = json.find(i => i.channelExternalId == channel.site_id); return result
if(!channelData)
return [];
return channelData.programs;
} }