mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update URL/parser for astro.com.my
This commit is contained in:
parent
cbce105a68
commit
d69f780895
2 changed files with 55 additions and 21 deletions
|
@ -2,36 +2,29 @@ const dayjs = require('dayjs')
|
|||
const utc = require('dayjs/plugin/utc')
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
module.exports = {
|
||||
site: 'astro.com.my',
|
||||
url: function ({ date, channel }) {
|
||||
return `http://ams-api.astro.com.my/ams/v3/getEvents?periodStart=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}:00:00:00&periodEnd=${date.format('YYYY-MM-DD')}:23:59:59&channelId=${channel.site_id}`
|
||||
url: function ({ channel }) {
|
||||
return `https://contenthub-api.eco.astro.com.my/channel/${channel.site_id}.json`
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
const programs = []
|
||||
const data = JSON.parse(content)
|
||||
const items = data.getevent
|
||||
if (!items.length) return programs
|
||||
const schedules = data.response.schedule
|
||||
|
||||
items.forEach(item => {
|
||||
if (item.programmeTitle && item.displayDateTimeUtc && item.displayDuration) {
|
||||
const start = dayjs.utc(item.displayDateTimeUtc)
|
||||
const duration = parseDuration(item.displayDuration)
|
||||
const stop = start.add(duration, 's')
|
||||
programs.push({
|
||||
title: item.programmeTitle,
|
||||
description: item.shortSynopsis,
|
||||
category: item.subGenre,
|
||||
icon: item.epgEventImage,
|
||||
start: start.toString(),
|
||||
stop: stop.toString()
|
||||
for(let items of Object.values(schedules)){
|
||||
items.forEach(item => {
|
||||
const start = dayjs.utc(item.datetimeInUtc)
|
||||
const duration = parseDuration(item.duration)
|
||||
const stop = start.add(duration, 's')
|
||||
programs.push({
|
||||
title: item.title,
|
||||
start: start,
|
||||
stop: stop
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
|
41
sites/astro.com.my/astro.com.my.test.js
Normal file
41
sites/astro.com.my/astro.com.my.test.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
const { parser, url } = require('./astro.com.my.config.js')
|
||||
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-08-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '235',
|
||||
xmltv_id: 'AstroArena.my'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe(
|
||||
'https://contenthub-api.eco.astro.com.my/channel/235.json'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `{"responseCode":200,"responseMessage":"Channel Detail","response":{"schedule":{"2022-08-29":[{"eventId":"40182037","title":"Motor: Cub Prix 2022","programmeId":"KAEQR","episodeId":"KAEQY","datetime":"2022-08-29 00:15:00.0","datetimeInUtc":"2022-08-28 16:15:00.0","duration":"02:25:00","siTrafficKey":"1:10000285:47439431","detailUrl":"/details/Motor-Cub-Prix-2022-1:10000285:47439431"}],"2022-08-30":[{"eventId":"40197573","title":"BWF Kejohanan Dunia 2022","programmeId":"KAGFN","episodeId":"KDGUX","datetime":"2022-08-30 00:00:00.0","datetimeInUtc":"2022-08-29 16:00:00.0","duration":"05:15:00","siTrafficKey":"1:10000285:47489961","detailUrl":"/details/BWF-Kejohanan-Dunia-2022-1:10000285:47489961"}]}}}`
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2022-08-28T16:15:00.000Z',
|
||||
stop: '2022-08-28T18:40:00.000Z',
|
||||
title: 'Motor: Cub Prix 2022',
|
||||
},
|
||||
{
|
||||
start: '2022-08-29T16:00:00.000Z',
|
||||
stop: '2022-08-29T21:15:00.000Z',
|
||||
title: 'BWF Kejohanan Dunia 2022',
|
||||
}
|
||||
])
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue