mirror of
https://github.com/iptv-org/epg
synced 2025-12-18 11:27:06 -05:00
Fix firstmedia.com schedule mislead.
The retrieved schedules from firstmedia.com api indeed confusing. Taken for example
the following snippet:
```json
{
channelNo: '245',
title: 'News Bulletin',
date: '2023-11-07 17:00:00',
startTime: '2023-11-07 17:00:00',
endTime: '2023-11-07 17:30:00',
description: 'News Bulletin',
long_description: 'Hourly update of international news with an emphasis on the Arab world.'
}
```
Neither `startTime` nor `endTime` is an actual time but an offset from `date`.
If its an actual time then it would overlap with each others.
The workaround is to calculate the start and stop time offset, sort the schedules
based on those offset, and last skip overlapped schedules.
Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
@@ -7,24 +7,36 @@ dayjs.extend(utc)
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'firstmedia.com',
|
site: 'firstmedia.com',
|
||||||
days: 1,
|
days: 2,
|
||||||
url: function ({ channel, date }) {
|
url({ channel, date }) {
|
||||||
return `https://api.firstmedia.com/api/content/tv-guide/list?date=${date.format('DD/MM/YYYY')}&channel=${
|
return `https://api.firstmedia.com/api/content/tv-guide/list?date=${date.format('DD/MM/YYYY')}&channel=${
|
||||||
channel.site_id
|
channel.site_id
|
||||||
}&startTime=0&endTime=24`
|
}&startTime=0&endTime=24`
|
||||||
},
|
},
|
||||||
parser: function ({ content, channel }) {
|
parser({ content, channel, date }) {
|
||||||
if (!content || !channel) return []
|
if (!content || !channel) return []
|
||||||
|
|
||||||
let programs = []
|
const programs = []
|
||||||
const items = parseItems(content, channel.site_id)
|
const items = parseItems(content, channel.site_id)
|
||||||
|
.map(item => {
|
||||||
|
item.start = toDelta(item.date, item.startTime)
|
||||||
|
item.stop = toDelta(item.date, item.endTime)
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
.sort((a, b) => a.start - b.start)
|
||||||
|
|
||||||
|
const dt = date.tz('Asia/Jakarta').startOf('d')
|
||||||
|
let lastStop
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
|
if (lastStop === undefined || item.start >= lastStop) {
|
||||||
|
lastStop = item.stop
|
||||||
programs.push({
|
programs.push({
|
||||||
title: parseTitle(item),
|
title: parseTitle(item),
|
||||||
description: parseDescription(item),
|
description: parseDescription(item),
|
||||||
start: parseStart(item).toISOString(),
|
start: asDate(parseStart({ item, date: dt })),
|
||||||
stop: parseStop(item).toISOString()
|
stop: asDate(parseStop({ item, date: dt }))
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
@@ -66,10 +78,22 @@ function parseDescription(item) {
|
|||||||
return item.long_description
|
return item.long_description
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item) {
|
function parseStart({ item, date }) {
|
||||||
return dayjs.tz(item.startTime, 'YYYY-MM-DD HH:mm:ss', 'Asia/Jakarta')
|
return date.add(item.start, 'ms')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item) {
|
function parseStop({ item, date }) {
|
||||||
return dayjs.tz(item.endTime, 'YYYY-MM-DD HH:mm:ss', 'Asia/Jakarta')
|
return date.add(item.stop, 'ms')
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDelta(from, to) {
|
||||||
|
return toDate(to).diff(toDate(from), 'milliseconds')
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDate(date) {
|
||||||
|
return dayjs(date, 'YYYY-MM-DD HH:mm:ss')
|
||||||
|
}
|
||||||
|
|
||||||
|
function asDate(date) {
|
||||||
|
return date.toISOString()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user