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,75 +1,75 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
const API_KEY = 'e899f715940a209148f834702fc7f340b6b0496b62120b3ed9c9b3ec4d7dca00'
|
||||
|
||||
module.exports = {
|
||||
site: 'teleboy.ch',
|
||||
url({ channel, date }) {
|
||||
const begin = date.format('YYYY-MM-DD HH:mm:ss')
|
||||
const end = date.add(1, 'd').format('YYYY-MM-DD HH:mm:ss')
|
||||
|
||||
return `https://api.teleboy.ch/epg/broadcasts?begin=${begin}&end=${end}&expand=flags,primary_image&station=${channel.site_id}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'x-teleboy-apikey': API_KEY
|
||||
}
|
||||
},
|
||||
parser({ content }) {
|
||||
const items = parseItems(content)
|
||||
|
||||
return items.map(item => {
|
||||
return {
|
||||
start: dayjs(item.begin),
|
||||
stop: dayjs(item.end),
|
||||
title: item.title,
|
||||
subtitle: item.subtitle || null,
|
||||
description: item.short_description || null,
|
||||
date: item.year ? item.year.toString() : null,
|
||||
season: item.serie_season || null,
|
||||
episode: item.serie_episode || null,
|
||||
starRatings: parseRating(item),
|
||||
image: parseImage(item)
|
||||
}
|
||||
})
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://api.teleboy.ch/epg/stations', module.exports.request)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data.data.items.map(channel => ({
|
||||
lang: channel.language,
|
||||
name: channel.name,
|
||||
site_id: channel.id
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseImage(item) {
|
||||
if (!item?.primary_image?.base_path || !item?.primary_image?.hash) return null
|
||||
|
||||
return `${item.primary_image.base_path}teleboyteaser6/${item.primary_image.hash}.jpg`
|
||||
}
|
||||
|
||||
function parseRating(item) {
|
||||
if (!item.imdb_rating) return null
|
||||
|
||||
return {
|
||||
system: 'IMDb',
|
||||
value: item.imdb_rating
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
if (!data?.data?.items || !Array.isArray(data.data.items)) return []
|
||||
|
||||
return data.data.items
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
const API_KEY = 'e899f715940a209148f834702fc7f340b6b0496b62120b3ed9c9b3ec4d7dca00'
|
||||
|
||||
module.exports = {
|
||||
site: 'teleboy.ch',
|
||||
url({ channel, date }) {
|
||||
const begin = date.format('YYYY-MM-DD HH:mm:ss')
|
||||
const end = date.add(1, 'd').format('YYYY-MM-DD HH:mm:ss')
|
||||
|
||||
return `https://api.teleboy.ch/epg/broadcasts?begin=${begin}&end=${end}&expand=flags,primary_image&station=${channel.site_id}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'x-teleboy-apikey': API_KEY
|
||||
}
|
||||
},
|
||||
parser({ content }) {
|
||||
const items = parseItems(content)
|
||||
|
||||
return items.map(item => {
|
||||
return {
|
||||
start: dayjs(item.begin),
|
||||
stop: dayjs(item.end),
|
||||
title: item.title,
|
||||
subtitle: item.subtitle || null,
|
||||
description: item.short_description || null,
|
||||
date: item.year ? item.year.toString() : null,
|
||||
season: item.serie_season || null,
|
||||
episode: item.serie_episode || null,
|
||||
starRatings: parseRating(item),
|
||||
image: parseImage(item)
|
||||
}
|
||||
})
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://api.teleboy.ch/epg/stations', module.exports.request)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
return data.data.items.map(channel => ({
|
||||
lang: channel.language,
|
||||
name: channel.name,
|
||||
site_id: channel.id
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseImage(item) {
|
||||
if (!item?.primary_image?.base_path || !item?.primary_image?.hash) return null
|
||||
|
||||
return `${item.primary_image.base_path}teleboyteaser6/${item.primary_image.hash}.jpg`
|
||||
}
|
||||
|
||||
function parseRating(item) {
|
||||
if (!item.imdb_rating) return null
|
||||
|
||||
return {
|
||||
system: 'IMDb',
|
||||
value: item.imdb_rating
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
if (!data?.data?.items || !Array.isArray(data.data.items)) return []
|
||||
|
||||
return data.data.items
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
const { parser, url, request } = require('./teleboy.ch.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2025-01-26', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: '303', xmltv_id: 'SRF1.ch' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://api.teleboy.ch/epg/broadcasts?begin=2025-01-26 00:00:00&end=2025-01-27 00:00:00&expand=flags,primary_image&station=303'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-teleboy-apikey': 'e899f715940a209148f834702fc7f340b6b0496b62120b3ed9c9b3ec4d7dca00'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
|
||||
let results = parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(35)
|
||||
expect(results[0]).toMatchObject({
|
||||
title: 'Der Staatsanwalt',
|
||||
description:
|
||||
'Der Tod eines beliebten Wasserretters konfrontiert Oberstaatsanwalt Bernd Reuther, Hauptkommissarin Kerstin Klar und Oberkommissar Max Fischer mit einem undurchsichtigen Geflecht aus Lügen.',
|
||||
subtitle: 'Tod eines Helden',
|
||||
episode: 6,
|
||||
season: 16,
|
||||
date: '2021',
|
||||
image:
|
||||
'https://media.teleboy.ch/media/teleboyteaser6/bd01aed53c7a37399ae034c2a1a2cc8aa31943f2.jpg',
|
||||
starRatings: {
|
||||
system: 'IMDb',
|
||||
value: 6
|
||||
},
|
||||
start: '2025-01-25T22:45:00.000Z',
|
||||
stop: '2025-01-25T23:50:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url, request } = require('./teleboy.ch.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2025-01-26', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = { site_id: '303', xmltv_id: 'SRF1.ch' }
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://api.teleboy.ch/epg/broadcasts?begin=2025-01-26 00:00:00&end=2025-01-27 00:00:00&expand=flags,primary_image&station=303'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-teleboy-apikey': 'e899f715940a209148f834702fc7f340b6b0496b62120b3ed9c9b3ec4d7dca00'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
|
||||
let results = parser({ content })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(35)
|
||||
expect(results[0]).toMatchObject({
|
||||
title: 'Der Staatsanwalt',
|
||||
description:
|
||||
'Der Tod eines beliebten Wasserretters konfrontiert Oberstaatsanwalt Bernd Reuther, Hauptkommissarin Kerstin Klar und Oberkommissar Max Fischer mit einem undurchsichtigen Geflecht aus Lügen.',
|
||||
subtitle: 'Tod eines Helden',
|
||||
episode: 6,
|
||||
season: 16,
|
||||
date: '2021',
|
||||
image:
|
||||
'https://media.teleboy.ch/media/teleboyteaser6/bd01aed53c7a37399ae034c2a1a2cc8aa31943f2.jpg',
|
||||
starRatings: {
|
||||
system: 'IMDb',
|
||||
value: 6
|
||||
},
|
||||
start: '2025-01-25T22:45:00.000Z',
|
||||
stop: '2025-01-25T23:50:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user