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,77 +1,77 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'iltalehti.fi',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
const [group] = channel.site_id.split('#')
|
||||
|
||||
return `https://telkku.com/api/channel-groups/default_builtin_channelgroup${group}/offering?startTime=00%3A00%3A00.000&duration=PT24H&inclusionPolicy=IncludeOngoingAlso&limit=1000&tvDate=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}&view=PublicationDetails`
|
||||
},
|
||||
parser: function ({ content, channel }) {
|
||||
let programs = []
|
||||
const items = getItems(content, channel)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
image: getImage(item),
|
||||
start: getStart(item),
|
||||
stop: getStop(item)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://telkku.com/api/channel-groups')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let items = []
|
||||
data.response.forEach(group => {
|
||||
group.channels.forEach(channel => {
|
||||
items.push({
|
||||
lang: 'fi',
|
||||
site_id: `${group.id}#${channel.id}`,
|
||||
name: channel.name
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return items
|
||||
}
|
||||
}
|
||||
|
||||
function getImage(item) {
|
||||
const image = item.images.find(i => i.type === 'default' && i.sizeTag === '1200x630')
|
||||
|
||||
return image ? image.url : null
|
||||
}
|
||||
|
||||
function getStart(item) {
|
||||
return dayjs(item.startTime)
|
||||
}
|
||||
|
||||
function getStop(item) {
|
||||
return dayjs(item.endTime)
|
||||
}
|
||||
|
||||
function getItems(content, channel) {
|
||||
const [, channelId] = channel.site_id.split('#')
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !data.response || !Array.isArray(data.response.publicationsByChannel)) return []
|
||||
const channelData = data.response.publicationsByChannel.find(i => i.channel.id === channelId)
|
||||
if (!channelData || !Array.isArray(channelData.publications)) return []
|
||||
|
||||
return channelData.publications
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'iltalehti.fi',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
const [group] = channel.site_id.split('#')
|
||||
|
||||
return `https://telkku.com/api/channel-groups/default_builtin_channelgroup${group}/offering?startTime=00%3A00%3A00.000&duration=PT24H&inclusionPolicy=IncludeOngoingAlso&limit=1000&tvDate=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}&view=PublicationDetails`
|
||||
},
|
||||
parser: function ({ content, channel }) {
|
||||
let programs = []
|
||||
const items = getItems(content, channel)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
image: getImage(item),
|
||||
start: getStart(item),
|
||||
stop: getStop(item)
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://telkku.com/api/channel-groups')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
let items = []
|
||||
data.response.forEach(group => {
|
||||
group.channels.forEach(channel => {
|
||||
items.push({
|
||||
lang: 'fi',
|
||||
site_id: `${group.id}#${channel.id}`,
|
||||
name: channel.name
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return items
|
||||
}
|
||||
}
|
||||
|
||||
function getImage(item) {
|
||||
const image = item.images.find(i => i.type === 'default' && i.sizeTag === '1200x630')
|
||||
|
||||
return image ? image.url : null
|
||||
}
|
||||
|
||||
function getStart(item) {
|
||||
return dayjs(item.startTime)
|
||||
}
|
||||
|
||||
function getStop(item) {
|
||||
return dayjs(item.endTime)
|
||||
}
|
||||
|
||||
function getItems(content, channel) {
|
||||
const [, channelId] = channel.site_id.split('#')
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !data.response || !Array.isArray(data.response.publicationsByChannel)) return []
|
||||
const channelData = data.response.publicationsByChannel.find(i => i.channel.id === channelId)
|
||||
if (!channelData || !Array.isArray(channelData.publications)) return []
|
||||
|
||||
return channelData.publications
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
const { parser, url } = require('./iltalehti.fi.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('2022-10-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1#yle-tv1',
|
||||
xmltv_id: 'YleTV1.fi'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://telkku.com/api/channel-groups/default_builtin_channelgroup1/offering?startTime=00%3A00%3A00.000&duration=PT24H&inclusionPolicy=IncludeOngoingAlso&limit=1000&tvDate=2022-10-29&view=PublicationDetails'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const results = parser({ content, channel }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-28T20:50:00.000Z',
|
||||
stop: '2022-10-28T21:20:00.000Z',
|
||||
title: 'Puoli seitsemän',
|
||||
description:
|
||||
'Vieraana näyttelijä Elias Salonen. Puoli seiskassa vietetään sekä halloweeniä että joulua, kun Olli-Pekka tapaa todellisen jouluttajan. Juontajina Anniina Valtonen, Tuulianna Tola ja Olli-Pekka Kursi.',
|
||||
image:
|
||||
'https://thumbor.prod.telkku.com/YTglotoUl7aJtzPtYnvM9tH03sY=/1200x630/smart/filters:quality(86):format(jpeg)/img.prod.telkku.com/program-images/0f885238ac16ce167a9d80eace450254.jpg'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json')),
|
||||
channel
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./iltalehti.fi.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('2022-10-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1#yle-tv1',
|
||||
xmltv_id: 'YleTV1.fi'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://telkku.com/api/channel-groups/default_builtin_channelgroup1/offering?startTime=00%3A00%3A00.000&duration=PT24H&inclusionPolicy=IncludeOngoingAlso&limit=1000&tvDate=2022-10-29&view=PublicationDetails'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const results = parser({ content, channel }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-28T20:50:00.000Z',
|
||||
stop: '2022-10-28T21:20:00.000Z',
|
||||
title: 'Puoli seitsemän',
|
||||
description:
|
||||
'Vieraana näyttelijä Elias Salonen. Puoli seiskassa vietetään sekä halloweeniä että joulua, kun Olli-Pekka tapaa todellisen jouluttajan. Juontajina Anniina Valtonen, Tuulianna Tola ja Olli-Pekka Kursi.',
|
||||
image:
|
||||
'https://thumbor.prod.telkku.com/YTglotoUl7aJtzPtYnvM9tH03sY=/1200x630/smart/filters:quality(86):format(jpeg)/img.prod.telkku.com/program-images/0f885238ac16ce167a9d80eace450254.jpg'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json')),
|
||||
channel
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user