mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Fix linter issues in sites/
This commit is contained in:
parent
d6d20b6413
commit
5df982bb7c
129 changed files with 3316 additions and 3226 deletions
|
@ -1,113 +1,108 @@
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const axios = require('axios')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
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: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
return `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_1.json`
|
||||
},
|
||||
async parser({ content, channel, date }) {
|
||||
let programs = []
|
||||
let items = parseItems(content, channel)
|
||||
if (!items.length) return programs
|
||||
|
||||
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.allSettled(promises)
|
||||
.then(results => {
|
||||
results.forEach(r => {
|
||||
if (r.status === 'fulfilled') {
|
||||
const parsed = parseItems(r.value.data, channel)
|
||||
|
||||
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
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const data = await axios
|
||||
.get(API_CHANNEL_ENDPOINT)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
return data.response.map(item => {
|
||||
return {
|
||||
lang: 'es',
|
||||
name: item.name,
|
||||
site_id: item.externalChannelId
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon(item){
|
||||
|
||||
if(item.attachments.length > 0){
|
||||
const cover = item.attachments.find(i => i.name === "COVER" || i.name === "cover")
|
||||
|
||||
if(cover)
|
||||
{
|
||||
return `${API_IMAGE_ENDPOINT}${cover.value}`;
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
function parseGenres(item){
|
||||
return item.genres.map(i => i.name);
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const json = typeof content === 'string' ? JSON.parse(content) : Array.isArray(content) ? content : []
|
||||
|
||||
if (!Array.isArray(json)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const channelData = json.find(i => i.channelExternalId == channel.site_id);
|
||||
|
||||
if(!channelData)
|
||||
return [];
|
||||
|
||||
return channelData.programs;
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const axios = require('axios')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
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: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ date }) {
|
||||
return `${API_PROGRAM_ENDPOINT}/${date.format('YYYYMMDD')}_8h_1.json`
|
||||
},
|
||||
async parser({ content, channel, date }) {
|
||||
let programs = []
|
||||
let items = parseItems(content, channel)
|
||||
if (!items.length) return programs
|
||||
|
||||
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.allSettled(promises)
|
||||
.then(results => {
|
||||
results.forEach(r => {
|
||||
if (r.status === 'fulfilled') {
|
||||
const parsed = parseItems(r.value.data, channel)
|
||||
|
||||
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
|
||||
},
|
||||
async channels() {
|
||||
const axios = require('axios')
|
||||
const data = await axios
|
||||
.get(API_CHANNEL_ENDPOINT)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
return data.response.map(item => {
|
||||
return {
|
||||
lang: 'es',
|
||||
name: item.name,
|
||||
site_id: item.externalChannelId
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon(item) {
|
||||
if (item.attachments.length > 0) {
|
||||
const cover = item.attachments.find(i => i.name === 'COVER' || i.name === 'cover')
|
||||
|
||||
if (cover) {
|
||||
return `${API_IMAGE_ENDPOINT}${cover.value}`
|
||||
}
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
function parseGenres(item) {
|
||||
return item.genres.map(i => i.name)
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const json =
|
||||
typeof content === 'string' ? JSON.parse(content) : Array.isArray(content) ? content : []
|
||||
|
||||
if (!Array.isArray(json)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const channelData = json.find(i => i.channelExternalId == channel.site_id)
|
||||
|
||||
if (!channelData) return []
|
||||
|
||||
return channelData.programs
|
||||
}
|
||||
|
|
|
@ -1,49 +1,54 @@
|
|||
const { parser, url } = require('./orangetv.orange.es.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const date = dayjs.utc('2024-12-01', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1010',
|
||||
xmltv_id: 'La1.es'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date })).toBe(`https://epg.orangetv.orange.es/epg/Smartphone_Android/1_PRO/${date.format('YYYYMMDD')}_8h_1.json`)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/data.json')).toString()
|
||||
let results = await parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(4)
|
||||
|
||||
var sampleResult = results[0];
|
||||
|
||||
expect(sampleResult).toMatchObject({
|
||||
start: '2024-11-30T22:36:51.000Z',
|
||||
stop: '2024-11-30T23:57:25.000Z',
|
||||
category: ['Cine', 'Romance', 'Comedia', 'Comedia Romántica'],
|
||||
description: 'Charlie trabaja como director en una escuela de primaria y goza de una placentera existencia junto a sus amigos. A pesar de ello, no es feliz porque cada vez que se enamora pierde la cordura.',
|
||||
title: 'Loco de amor'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: '{}'
|
||||
})
|
||||
expect(result).toMatchObject({})
|
||||
})
|
||||
const { parser, url } = require('./orangetv.orange.es.config.js')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const date = dayjs.utc('2024-12-01', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1010',
|
||||
xmltv_id: 'La1.es'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date })).toBe(
|
||||
`https://epg.orangetv.orange.es/epg/Smartphone_Android/1_PRO/${date.format(
|
||||
'YYYYMMDD'
|
||||
)}_8h_1.json`
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/data.json')).toString()
|
||||
let results = await parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(4)
|
||||
|
||||
var sampleResult = results[0]
|
||||
|
||||
expect(sampleResult).toMatchObject({
|
||||
start: '2024-11-30T22:36:51.000Z',
|
||||
stop: '2024-11-30T23:57:25.000Z',
|
||||
category: ['Cine', 'Romance', 'Comedia', 'Comedia Romántica'],
|
||||
description:
|
||||
'Charlie trabaja como director en una escuela de primaria y goza de una placentera existencia junto a sus amigos. A pesar de ello, no es feliz porque cada vez que se enamora pierde la cordura.',
|
||||
title: 'Loco de amor'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: '{}'
|
||||
})
|
||||
expect(result).toMatchObject({})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue