mirror of
https://github.com/iptv-org/epg
synced 2025-12-17 10:56:57 -05:00
Merge pull request #1045 from RevGear/master
Update URL/parser for astro.com.my
This commit is contained in:
1
sites/astro.com.my/__data__/content.json
Normal file
1
sites/astro.com.my/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
2
sites/astro.com.my/__data__/no_content.html
Normal file
2
sites/astro.com.my/__data__/no_content.html
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>F90SGHZYJ699VPE2</RequestId><HostId>FnSQQRmSgIWQjkrtu/JlD5UhB4sdDbjGxbxQi11+2LybUKavIk0RGzBxFU7imETDsT9eMoSvl8M=</HostId></Error>
|
||||||
@@ -2,40 +2,40 @@ 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, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const data = JSON.parse(content)
|
const items = parseItems(content, date)
|
||||||
const items = data.getevent
|
|
||||||
if (!items.length) return programs
|
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
if (item.programmeTitle && item.displayDateTimeUtc && item.displayDuration) {
|
const start = dayjs.utc(item.datetimeInUtc)
|
||||||
const start = dayjs.utc(item.displayDateTimeUtc)
|
const duration = parseDuration(item.duration)
|
||||||
const duration = parseDuration(item.displayDuration)
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseItems(content, date) {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(content)
|
||||||
|
const schedules = data.response.schedule
|
||||||
|
|
||||||
|
return schedules[date.format('YYYY-MM-DD')] || []
|
||||||
|
} catch (e) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parseDuration(duration) {
|
function parseDuration(duration) {
|
||||||
const match = duration.match(/(\d{2}):(\d{2}):(\d{2})/)
|
const match = duration.match(/(\d{2}):(\d{2}):(\d{2})/)
|
||||||
const hours = parseInt(match[1])
|
const hours = parseInt(match[1])
|
||||||
|
|||||||
42
sites/astro.com.my/astro.com.my.test.js
Normal file
42
sites/astro.com.my/astro.com.my.test.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// npx epg-grabber --config=sites/astro.com.my/astro.com.my.config.js --channels=sites/astro.com.my/astro.com.my_my.channels.xml --output=guide.xml --timeout=30000 --days=2
|
||||||
|
|
||||||
|
const { parser, url } = require('./astro.com.my.config.js')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
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-30', '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 = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||||
|
const results = parser({ content, date }).map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(results.length).toBe(14)
|
||||||
|
expect(results[0]).toMatchObject({
|
||||||
|
start: '2022-08-29T16:00:00.000Z',
|
||||||
|
stop: '2022-08-29T21:15:00.000Z',
|
||||||
|
title: 'BWF Kejohanan Dunia 2022'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||||
|
const result = parser({ date, content })
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user