epg/sites/orangetv.orange.es/orangetv.orange.es.config.js
Toha 3dbece7ff0
Update orangetv.orange.es guide.
Test:

```sh
npm test --- orangetv.orange.es

> test
> run-script-os orangetv.orange.es

> test:win32
> SET "TZ=Pacific/Nauru" && npx jest --runInBand orangetv.orange.es

 PASS  sites/orangetv.orange.es/orangetv.orange.es.test.js
  √ can generate valid url (6 ms)
  √ can parse response (6 ms)
  √ can handle empty guide (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        0.701 s, estimated 1 s
Ran all test suites matching /orangetv.orange.es/i.
```

Grab:

```sh
pm run grab --- --site=orangetv.orange.es

> grab
> npx tsx scripts/commands/epg/grab.ts --site=orangetv.orange.es

starting...
config:
  output: guide.xml
  maxConnections: 1
  gzip: false
  site: orangetv.orange.es
loading channels...
  found 2 channel(s)
run #1:
  [1/2] orangetv.orange.es (es) - La1.es - Jan 12, 2025 (18 programs)
  [2/2] orangetv.orange.es (es) - La2.es - Jan 12, 2025 (39 programs)
  saving to "guide.xml"...
  done in 00h 00m 18s
```

Signed-off-by: Toha <tohenk@yahoo.com>
2025-01-12 14:14:28 +07:00

99 lines
2.7 KiB
JavaScript

const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const doFetch = require('@ntlab/sfetch')
const debug = require('debug')('site:orangetv.orange.es')
dayjs.extend(utc)
doFetch.setDebugger(debug)
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_IMAGE_ENDPOINT = 'https://pc.orangetv.orange.es/pc/api/rtv/v1/images'
module.exports = {
site: 'orangetv.orange.es',
days: 2,
request: {
cache: {
ttl: 24 * 60 * 60 * 1000 // 1 day
}
},
url({ date, segment = 1 }) {
return `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_${segment}.json`
},
async parser({ content, channel, date }) {
const programs = []
const items = parseItems(content, channel)
if (items.length) {
const queues = [
module.exports.url({ date, segment: 2 }),
module.exports.url({ date, segment: 3 })
]
await doFetch(queues, (url, res) => {
items.push(...parseItems(res, channel))
})
programs.push(
...items.map(item => {
return {
title: item.name,
sub_title: item.seriesName,
description: item.description,
category: parseGenres(item),
season: item.seriesSeason ? parseInt(item.seriesSeason) : null,
episode: item.episodeId ? parseInt(item.episodeId) : null,
icon: parseIcon(item),
start: dayjs.utc(item.startDate),
stop: dayjs.utc(item.endDate)
}
})
)
}
return programs
},
async channels() {
const axios = require('axios')
const data = await axios
.get(API_CHANNEL_ENDPOINT)
.then(r => r.data)
.catch(console.error)
return data.response.map(item => {
return {
lang: 'es',
name: item.name,
site_id: item.externalChannelId
}
})
}
}
function parseIcon(item) {
if (item.attachments.length) {
const cover = item.attachments.find(i => i.name.match(/cover/i))
if (cover) {
return `${API_IMAGE_ENDPOINT}${cover.value}`
}
}
}
function parseGenres(item) {
return item.genres.map(i => i.name)
}
function parseItems(content, channel) {
const result = []
const json =
typeof content === 'string' ? JSON.parse(content) : Array.isArray(content) ? content : []
if (Array.isArray(json)) {
json
.filter(i => i.channelExternalId === channel.site_id)
.forEach(i => {
result.push(...i.programs)
})
}
return result
}