mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,138 +1,138 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
const API_STATIC_ENDPOINT = 'https://static.spark.telenet.tv/eng/web/epg-service-lite/be'
|
||||
const API_PROD_ENDPOINT = 'https://spark-prod-be.gnp.cloud.telenet.tv/eng/web/linear-service/v2'
|
||||
const API_IMAGE_ENDPOINT = 'https://staticqbr-prod-be.gnp.cloud.telenet.tv/image-service'
|
||||
|
||||
module.exports = {
|
||||
site: 'telenet.tv',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({ date, channel }) {
|
||||
return `${API_STATIC_ENDPOINT}/${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 promises = [
|
||||
axios.get(
|
||||
`${API_STATIC_ENDPOINT}/${channel.lang}/events/segments/${date
|
||||
.add(6, 'h')
|
||||
.format('YYYYMMDDHHmmss')}`,
|
||||
{
|
||||
responseType: 'arraybuffer'
|
||||
}
|
||||
),
|
||||
axios.get(
|
||||
`${API_STATIC_ENDPOINT}/${channel.lang}/events/segments/${date
|
||||
.add(12, 'h')
|
||||
.format('YYYYMMDDHHmmss')}`,
|
||||
{
|
||||
responseType: 'arraybuffer'
|
||||
}
|
||||
),
|
||||
axios.get(
|
||||
`${API_STATIC_ENDPOINT}/${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') {
|
||||
const parsed = parseItems(r.value.data, channel)
|
||||
|
||||
items = items.concat(parsed)
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(console.error)
|
||||
|
||||
for (let item of items) {
|
||||
const detail = await loadProgramDetails(item, channel)
|
||||
programs.push({
|
||||
title: item.title,
|
||||
icon: parseIcon(item),
|
||||
description: detail.longDescription,
|
||||
category: detail.genres,
|
||||
actors: detail.actors,
|
||||
season: parseSeason(detail),
|
||||
episode: parseEpisode(detail),
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get(`${API_PROD_ENDPOINT}/channels?cityId=28001&language=en&productClass=Orion-DASH`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.map(item => {
|
||||
return {
|
||||
lang: 'nl',
|
||||
site_id: item.id,
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProgramDetails(item, channel) {
|
||||
if (!item.id) return {}
|
||||
const url = `${API_PROD_ENDPOINT}/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.unix(item.startTime)
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs.unix(item.endTime)
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
if (!content) return []
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.entries)) return []
|
||||
const channelData = data.entries.find(e => e.channelId === channel.site_id)
|
||||
if (!channelData) return []
|
||||
|
||||
return Array.isArray(channelData.events) ? channelData.events : []
|
||||
}
|
||||
|
||||
function parseSeason(detail) {
|
||||
if (!detail.seasonNumber) return null
|
||||
if (String(detail.seasonNumber).length > 2) return null
|
||||
return detail.seasonNumber
|
||||
}
|
||||
|
||||
function parseEpisode(detail) {
|
||||
if (!detail.episodeNumber) return null
|
||||
if (String(detail.episodeNumber).length > 3) return null
|
||||
return detail.episodeNumber
|
||||
}
|
||||
|
||||
function parseIcon(item) {
|
||||
return `${API_IMAGE_ENDPOINT}/intent/${item.id}/posterTile`
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
const API_STATIC_ENDPOINT = 'https://static.spark.telenet.tv/eng/web/epg-service-lite/be'
|
||||
const API_PROD_ENDPOINT = 'https://spark-prod-be.gnp.cloud.telenet.tv/eng/web/linear-service/v2'
|
||||
const API_IMAGE_ENDPOINT = 'https://staticqbr-prod-be.gnp.cloud.telenet.tv/image-service'
|
||||
|
||||
module.exports = {
|
||||
site: 'telenet.tv',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({ date, channel }) {
|
||||
return `${API_STATIC_ENDPOINT}/${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 promises = [
|
||||
axios.get(
|
||||
`${API_STATIC_ENDPOINT}/${channel.lang}/events/segments/${date
|
||||
.add(6, 'h')
|
||||
.format('YYYYMMDDHHmmss')}`,
|
||||
{
|
||||
responseType: 'arraybuffer'
|
||||
}
|
||||
),
|
||||
axios.get(
|
||||
`${API_STATIC_ENDPOINT}/${channel.lang}/events/segments/${date
|
||||
.add(12, 'h')
|
||||
.format('YYYYMMDDHHmmss')}`,
|
||||
{
|
||||
responseType: 'arraybuffer'
|
||||
}
|
||||
),
|
||||
axios.get(
|
||||
`${API_STATIC_ENDPOINT}/${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') {
|
||||
const parsed = parseItems(r.value.data, channel)
|
||||
|
||||
items = items.concat(parsed)
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch(console.error)
|
||||
|
||||
for (let item of items) {
|
||||
const detail = await loadProgramDetails(item, channel)
|
||||
programs.push({
|
||||
title: item.title,
|
||||
icon: parseIcon(item),
|
||||
description: detail.longDescription,
|
||||
category: detail.genres,
|
||||
actors: detail.actors,
|
||||
season: parseSeason(detail),
|
||||
episode: parseEpisode(detail),
|
||||
start: parseStart(item),
|
||||
stop: parseStop(item)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get(`${API_PROD_ENDPOINT}/channels?cityId=28001&language=en&productClass=Orion-DASH`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.map(item => {
|
||||
return {
|
||||
lang: 'nl',
|
||||
site_id: item.id,
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProgramDetails(item, channel) {
|
||||
if (!item.id) return {}
|
||||
const url = `${API_PROD_ENDPOINT}/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.unix(item.startTime)
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs.unix(item.endTime)
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
if (!content) return []
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.entries)) return []
|
||||
const channelData = data.entries.find(e => e.channelId === channel.site_id)
|
||||
if (!channelData) return []
|
||||
|
||||
return Array.isArray(channelData.events) ? channelData.events : []
|
||||
}
|
||||
|
||||
function parseSeason(detail) {
|
||||
if (!detail.seasonNumber) return null
|
||||
if (String(detail.seasonNumber).length > 2) return null
|
||||
return detail.seasonNumber
|
||||
}
|
||||
|
||||
function parseEpisode(detail) {
|
||||
if (!detail.episodeNumber) return null
|
||||
if (String(detail.episodeNumber).length > 3) return null
|
||||
return detail.episodeNumber
|
||||
}
|
||||
|
||||
function parseIcon(item) {
|
||||
return `${API_IMAGE_ENDPOINT}/intent/${item.id}/posterTile`
|
||||
}
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
const { parser, url } = require('./telenet.tv.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const API_STATIC_ENDPOINT = 'https://static.spark.telenet.tv/eng/web/epg-service-lite/be'
|
||||
const API_PROD_ENDPOINT = 'https://spark-prod-be.gnp.cloud.telenet.tv/eng/web/linear-service/v2'
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-30', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'outtv',
|
||||
xmltv_id: 'OutTV.nl',
|
||||
lang: 'nl'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(`${API_STATIC_ENDPOINT}/nl/events/segments/20221030000000`)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_0000.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_STATIC_ENDPOINT}/nl/events/segments/20221030060000`) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_0600.json'))
|
||||
})
|
||||
} else if (url === `${API_STATIC_ENDPOINT}/nl/events/segments/20221030120000`) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_1200.json'))
|
||||
})
|
||||
} else if (url === `${API_STATIC_ENDPOINT}/nl/events/segments/20221030180000`) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_1800.json'))
|
||||
})
|
||||
} else if (
|
||||
url ===
|
||||
`${API_PROD_ENDPOINT}/replayEvent/crid:~~2F~~2Fgn.tv~~2F2459095~~2FEP036477800004,imi:0a2f4207b03c16c70b7fb3be8e07881aafe44106?returnLinearContent=true&language=nl`
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
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[0]).toMatchObject({
|
||||
start: '2022-10-29T23:56:00.000Z',
|
||||
stop: '2022-10-30T01:44:00.000Z',
|
||||
title: 'Queer as Folk USA',
|
||||
icon: 'https://staticqbr-prod-be.gnp.cloud.telenet.tv/image-service/intent/crid:~~2F~~2Fgn.tv~~2F2459095~~2FEP036477800004,imi:0a2f4207b03c16c70b7fb3be8e07881aafe44106/posterTile',
|
||||
description:
|
||||
"Justin belandt in de gevangenis, Brian en Brandon banen zich een weg door de lijst, Ben treurt, Melanie en Lindsay proberen een interne scheiding en Emmett's stalker onthult zichzelf.",
|
||||
category: ['Dramaserie', 'LHBTI'],
|
||||
actors: [
|
||||
'Gale Harold',
|
||||
'Hal Sparks',
|
||||
'Randy Harrison',
|
||||
'Peter Paige',
|
||||
'Scott Lowell',
|
||||
'Thea Gill',
|
||||
'Michelle Clunie',
|
||||
'Sharon Gless'
|
||||
],
|
||||
season: 5,
|
||||
episode: 8
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
let results = await parser({ content: '', channel, date })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./telenet.tv.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const API_STATIC_ENDPOINT = 'https://static.spark.telenet.tv/eng/web/epg-service-lite/be'
|
||||
const API_PROD_ENDPOINT = 'https://spark-prod-be.gnp.cloud.telenet.tv/eng/web/linear-service/v2'
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-30', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'outtv',
|
||||
xmltv_id: 'OutTV.nl',
|
||||
lang: 'nl'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(`${API_STATIC_ENDPOINT}/nl/events/segments/20221030000000`)
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_0000.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_STATIC_ENDPOINT}/nl/events/segments/20221030060000`) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_0600.json'))
|
||||
})
|
||||
} else if (url === `${API_STATIC_ENDPOINT}/nl/events/segments/20221030120000`) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_1200.json'))
|
||||
})
|
||||
} else if (url === `${API_STATIC_ENDPOINT}/nl/events/segments/20221030180000`) {
|
||||
return Promise.resolve({
|
||||
data: fs.readFileSync(path.resolve(__dirname, '__data__/content_1800.json'))
|
||||
})
|
||||
} else if (
|
||||
url ===
|
||||
`${API_PROD_ENDPOINT}/replayEvent/crid:~~2F~~2Fgn.tv~~2F2459095~~2FEP036477800004,imi:0a2f4207b03c16c70b7fb3be8e07881aafe44106?returnLinearContent=true&language=nl`
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
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[0]).toMatchObject({
|
||||
start: '2022-10-29T23:56:00.000Z',
|
||||
stop: '2022-10-30T01:44:00.000Z',
|
||||
title: 'Queer as Folk USA',
|
||||
icon: 'https://staticqbr-prod-be.gnp.cloud.telenet.tv/image-service/intent/crid:~~2F~~2Fgn.tv~~2F2459095~~2FEP036477800004,imi:0a2f4207b03c16c70b7fb3be8e07881aafe44106/posterTile',
|
||||
description:
|
||||
"Justin belandt in de gevangenis, Brian en Brandon banen zich een weg door de lijst, Ben treurt, Melanie en Lindsay proberen een interne scheiding en Emmett's stalker onthult zichzelf.",
|
||||
category: ['Dramaserie', 'LHBTI'],
|
||||
actors: [
|
||||
'Gale Harold',
|
||||
'Hal Sparks',
|
||||
'Randy Harrison',
|
||||
'Peter Paige',
|
||||
'Scott Lowell',
|
||||
'Thea Gill',
|
||||
'Michelle Clunie',
|
||||
'Sharon Gless'
|
||||
],
|
||||
season: 5,
|
||||
episode: 8
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
let results = await parser({ content: '', channel, date })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user