mirror of
https://github.com/iptv-org/epg
synced 2026-05-05 17:07:03 -04:00
The retrieved schedules from firstmedia.com api indeed confusing. Taken for example
the following snippet:
```
{
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>
38 lines
2.3 KiB
JavaScript
38 lines
2.3 KiB
JavaScript
const { url, parser } = require('./firstmedia.com.config.js')
|
|
const dayjs = require('dayjs')
|
|
const utc = require('dayjs/plugin/utc')
|
|
dayjs.extend(utc)
|
|
|
|
const date = dayjs.utc('2023-11-08').startOf('d')
|
|
const channel = { site_id: '243', xmltv_id: 'AlJazeeraEnglish.qa', lang: 'id' }
|
|
|
|
it('can generate valid url', () => {
|
|
expect(url({ channel, date })).toBe(
|
|
'https://api.firstmedia.com/api/content/tv-guide/list?date=08/11/2023&channel=243&startTime=0&endTime=24'
|
|
)
|
|
})
|
|
|
|
it('can parse response', () => {
|
|
const content =
|
|
'{"data":{"entries":{"243":[{"createdAt":"2023-11-05T17:09:34.000Z","updatedAt":"2023-11-05T17:09:34.000Z","id":"009f3a34-8164-4ff9-b981-9dcab1a518fc","channelNo":"243","programmeId":null,"title":"News Live","episode":null,"slug":"news-live","date":"2023-11-08 17:00:00","startTime":"2023-11-08 20:00:00","endTime":"2023-11-08 20:30:00","length":1800,"description":"News Live","long_description":"Up to date news and analysis from around the world.","status":true,"channel":{"id":"7fd7a9a6-af32-c861-d2b0-4ddc7846fad2","key":"AljaInt","no":243,"name":"Al Jazeera International","slug":"al-jazeera-international","website":null,"description":"<p>An international 24-hour English-language It is the first English-language news channel brings you the latest global news stories, analysis from the Middle East & worldwide.</p>","shortDescription":null,"logo":"files/logos/channels/11-NEWS/AlJazeera Int SD-FirstMedia-Chl-243.jpg","externalId":"132","type":"radio","status":true,"chanel":"SD","locale":"id","relationId":"5a6ea4ae-a008-4889-9c68-7a6f1838e81d","onlyfm":null,"genress":[{"id":"1db3bb43-b00d-49af-b272-6c058a8c0b49","name":"International Free View"},{"id":"2e81a4bd-9719-4186-820a-7e035e07be13","name":"News"}]}}]}}}'
|
|
const results = parser({ content, channel, date })
|
|
|
|
// All time in Asia/Jakarta
|
|
// 2023-11-08 17:00:00 -> 2023-11-08 20:00:00 = 2023-11-08 03:00:00
|
|
// 2023-11-08 17:00:00 -> 2023-11-08 20:30:00 = 2023-11-08 03:30:00
|
|
expect(results).toMatchObject([
|
|
{
|
|
start: '2023-11-07T20:00:00.000Z',
|
|
stop: '2023-11-07T20:30:00.000Z',
|
|
title: 'News Live',
|
|
description: 'Up to date news and analysis from around the world.'
|
|
}
|
|
])
|
|
})
|
|
|
|
it('can handle empty guide', () => {
|
|
const results = parser({ content: '' })
|
|
|
|
expect(results).toMatchObject([])
|
|
})
|