mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10: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')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'astro.com.my',
|
site: 'astro.com.my',
|
||||||
url: function ({ date, channel }) {
|
url: function ({ channel }) {
|
||||||
return `http://ams-api.astro.com.my/ams/v3/getEvents?periodStart=${date.format(
|
return `https://contenthub-api.eco.astro.com.my/channel/${channel.site_id}.json`
|
||||||
'YYYY-MM-DD'
|
|
||||||
)}:00:00:00&periodEnd=${date.format('YYYY-MM-DD')}:23:59:59&channelId=${channel.site_id}`
|
|
||||||
},
|
},
|
||||||
parser: function ({ content }) {
|
parser: function ({ content }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const data = JSON.parse(content)
|
const data = JSON.parse(content)
|
||||||
const items = data.getevent
|
const schedules = data.response.schedule
|
||||||
if (!items.length) return programs
|
|
||||||
|
|
||||||
items.forEach(item => {
|
for(let items of Object.values(schedules)){
|
||||||
if (item.programmeTitle && item.displayDateTimeUtc && item.displayDuration) {
|
items.forEach(item => {
|
||||||
const start = dayjs.utc(item.displayDateTimeUtc)
|
const start = dayjs.utc(item.datetimeInUtc)
|
||||||
const duration = parseDuration(item.displayDuration)
|
const duration = parseDuration(item.duration)
|
||||||
const stop = start.add(duration, 's')
|
const stop = start.add(duration, 's')
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.programmeTitle,
|
title: item.title,
|
||||||
description: item.shortSynopsis,
|
start: start,
|
||||||
category: item.subGenre,
|
stop: stop
|
||||||
icon: item.epgEventImage,
|
})
|
||||||
start: start.toString(),
|
|
||||||
stop: stop.toString()
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
}
|
||||||
return programs
|
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