mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Add Freeview description
This commit is contained in:
@@ -14,21 +14,24 @@ module.exports = {
|
|||||||
|
|
||||||
return `https://www.freeview.co.uk/api/tv-guide?nid=${networkId}&start=${startTimestamp}`
|
return `https://www.freeview.co.uk/api/tv-guide?nid=${networkId}&start=${startTimestamp}`
|
||||||
},
|
},
|
||||||
parser({ content, channel }) {
|
async parser({ content, channel }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
let items = parseItems(content, channel)
|
let items = parseItems(content, channel)
|
||||||
items.forEach(item => {
|
for (const item of items) {
|
||||||
const start = parseStart(item)
|
const start = parseStart(item)
|
||||||
const duration = parseDuration(item.duration)
|
const duration = parseDuration(item.duration)
|
||||||
const stop = start.add(duration, 'ms')
|
const stop = start.add(duration, 'ms')
|
||||||
|
const details = await loadProgramDetails(item)
|
||||||
|
const synopsis = details?.synopsis
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.main_title,
|
title: item.main_title,
|
||||||
subtitle: item.secondary_title,
|
subtitle: item.secondary_title,
|
||||||
|
description: synopsis?.long || synopsis?.medium || synopsis?.short || null,
|
||||||
image: parseImage(item),
|
image: parseImage(item),
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
},
|
},
|
||||||
@@ -71,3 +74,15 @@ function parseItems(content, channel) {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadProgramDetails(item) {
|
||||||
|
const url = `https://www.freeview.co.uk/api/program?pid=${item.program_id}&start_time=${item.start_time}&duration=${item.duration}`
|
||||||
|
const data = await axios
|
||||||
|
.get(url)
|
||||||
|
.then(r => {
|
||||||
|
const programs = r?.data?.data?.programs
|
||||||
|
return Array.isArray(programs) && programs.length > 0 ? programs[0] : {}
|
||||||
|
})
|
||||||
|
.catch(console.log)
|
||||||
|
return data || {}
|
||||||
|
}
|
||||||
@@ -4,8 +4,10 @@ const path = require('path')
|
|||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
const axios = require('axios')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
jest.mock('axios')
|
||||||
|
|
||||||
const date = dayjs.utc('2025-01-16', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2025-01-16', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
@@ -19,9 +21,17 @@ it('can generate valid url', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', async () => {
|
||||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
axios.get.mockImplementation(requestUrl => {
|
||||||
let results = parser({ content, channel })
|
if (requestUrl.includes('https://www.freeview.co.uk/api/program?pid=')) {
|
||||||
|
return Promise.resolve({data: {data: {programs: [{}]}}})
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({data: {}})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'), 'utf8')
|
||||||
|
let results = await parser({ content, channel })
|
||||||
results = results.map(p => {
|
results = results.map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
@@ -45,8 +55,8 @@ it('can parse response', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', async () => {
|
||||||
const results = parser({
|
const results = await parser({
|
||||||
content: '[]',
|
content: '[]',
|
||||||
channel
|
channel
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user