Merge pull request #1243 from iptv-org/update-astro.com.my

Update astro.com.my
This commit is contained in:
Aleksandr Statciuk 2022-10-31 02:48:36 +03:00 committed by GitHub
commit e276de8748
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 161 additions and 36 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,2 +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>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>PYWWJ0TM0RSWSX09</RequestId><HostId>WU2+m2j4IPZtj2j5k2C9NB41iM2QaK+LqVlBk2kLCNDrddFBXPkjCFLBiALXw8xTPF4xIPTZOWs=</HostId></Error>

View file

@ -0,0 +1,27 @@
{
"responseCode": 200,
"responseMessage": "Linear Asset Detail",
"response": {
"eventId": "40609678",
"channelId": 425,
"channelStbNumber": "305",
"isHd": true,
"imageUrl": "https://s3-ap-southeast-1.amazonaws.com/ams-astro/production/images/1035X328883.jpg",
"title": "Triumph in the Skies Ep06",
"programmeId": "328827",
"episodeId": "328883",
"datetime": "2022-10-31 00:10:00.0",
"datetimeInUtc": "2022-10-30 16:10:00.0",
"duration": "00:52:00",
"siTrafficKey": "1:10000526:47979653",
"certification": "U",
"shortSynopsis": "This classic drama depicts the many aspects of two complicated relationships set against an airline company. Will those involved ever find true love?",
"longSynopsis": null,
"cast": "Francis Ng Chun Yu,Joe Ma Tak Chung,Flora Chan Wai San",
"director": "Joe Ma Tak Chung",
"filter": "Filter/71",
"subFilter": [
"Filter/24"
]
}
}

View file

@ -1,30 +1,62 @@
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
const API_ENDPOINT = `https://contenthub-api.eco.astro.com.my`
module.exports = {
site: 'astro.com.my',
url: function ({ channel }) {
return `https://contenthub-api.eco.astro.com.my/channel/${channel.site_id}.json`
return `${API_ENDPOINT}/channel/${channel.site_id}.json`
},
parser: function ({ content, date }) {
async parser({ content, date }) {
const programs = []
const items = parseItems(content, date)
items.forEach(item => {
for (let item of items) {
const start = dayjs.utc(item.datetimeInUtc)
const duration = parseDuration(item.duration)
const stop = start.add(duration, 's')
const details = await loadProgramDetails(item)
programs.push({
title: item.title,
sub_title: item.subtitles,
description: details.longSynopsis || details.shortSynopsis,
actors: parseList(details.cast),
directors: parseList(details.director),
icon: details.imageUrl,
rating: parseRating(details),
categories: parseCategories(details),
episode: parseEpisode(item),
start: start,
stop: stop
})
})
}
return programs
}
}
function parseEpisode(item) {
const [_, number] = item.title.match(/Ep(\d+)$/) || [null, null]
return number ? parseInt(number) : null
}
function parseList(list) {
return typeof list === 'string' ? list.split(',') : []
}
function parseRating(details) {
return details.certification
? {
system: 'LPF',
value: details.certification
}
: null
}
function parseItems(content, date) {
try {
const data = JSON.parse(content)
@ -44,3 +76,40 @@ function parseDuration(duration) {
return hours * 3600 + minutes * 60 + seconds
}
function parseCategories(details) {
const genres = {
'filter/2': 'Action',
'filter/4': 'Anime',
'filter/12': 'Cartoons',
'filter/16': 'Comedy',
'filter/19': 'Crime',
'filter/24': 'Drama',
'filter/25': 'Educational',
'filter/36': 'Horror',
'filter/39': 'Live Action',
'filter/55': 'Pre-school',
'filter/56': 'Reality',
'filter/60': 'Romance',
'filter/68': 'Talk Show',
'filter/69': 'Thriller',
'filter/72': 'Variety',
'filter/75': 'Series',
'filter/100': 'Others (Children)'
}
return Array.isArray(details.subFilter)
? details.subFilter.map(g => genres[g.toLowerCase()]).filter(Boolean)
: []
}
async function loadProgramDetails(item) {
const url = `${API_ENDPOINT}/api/v1/linear-detail?siTrafficKey=${item.siTrafficKey}`
const data = await axios
.get(url)
.then(r => r.data)
.catch(err => console.log(err.message))
if (!data) return {}
return data.response || {}
}

View file

@ -3,40 +3,70 @@
const { parser, url } = require('./astro.com.my.config.js')
const fs = require('fs')
const path = require('path')
const axios = require('axios')
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')
jest.mock('axios')
const date = dayjs.utc('2022-10-31', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '235',
xmltv_id: 'AstroArena.my'
site_id: '425',
xmltv_id: 'TVBClassic.hk'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe('https://contenthub-api.eco.astro.com.my/channel/235.json')
expect(url({ channel })).toBe('https://contenthub-api.eco.astro.com.my/channel/425.json')
})
it('can parse response', () => {
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
const results = parser({ content, date }).map(p => {
axios.get.mockImplementation(url => {
if (
url ===
'https://contenthub-api.eco.astro.com.my/api/v1/linear-detail?siTrafficKey=1:10000526:47979653'
) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
})
} else {
return Promise.resolve({ data: '' })
}
})
let results = await parser({ content, channel, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(14)
expect(results.length).toBe(31)
expect(results[0]).toMatchObject({
start: '2022-08-29T16:00:00.000Z',
stop: '2022-08-29T21:15:00.000Z',
title: 'BWF Kejohanan Dunia 2022'
start: '2022-10-30T16:10:00.000Z',
stop: '2022-10-30T17:02:00.000Z',
title: 'Triumph in the Skies Ep06',
description:
'This classic drama depicts the many aspects of two complicated relationships set against an airline company. Will those involved ever find true love?',
actors: ['Francis Ng Chun Yu', 'Joe Ma Tak Chung', 'Flora Chan Wai San'],
directors: ['Joe Ma Tak Chung'],
icon: 'https://s3-ap-southeast-1.amazonaws.com/ams-astro/production/images/1035X328883.jpg',
rating: {
system: 'LPF',
value: 'U'
},
episode: 6,
categories: ['Drama']
})
})
it('can handle empty guide', () => {
it('can handle empty guide', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
const result = parser({ date, content })
expect(result).toMatchObject([])
const results = await parser({ date, content })
expect(results).toMatchObject([])
})

View file

@ -3,7 +3,6 @@
<channels>
<channel lang="ms" xmltv_id="8TV.my" site_id="115">8TV</channel>
<channel lang="ms" xmltv_id="ABCAustraliaAsia.au" site_id="461">ABC</channel>
<channel lang="ms" xmltv_id="AXNMalaysia.my" site_id="131">AXN</channel>
<channel lang="ms" xmltv_id="AdithyaTV.in" site_id="67">Adithya TV</channel>
<channel lang="ms" xmltv_id="AlJazeeraEnglish.qa" site_id="374">Aljazeera</channel>
<channel lang="ms" xmltv_id="AnimalPlanetMalaysia.my" site_id="377">Animal Planet</channel>
@ -48,7 +47,7 @@
<channel lang="ms" xmltv_id="AstroWarna.my" site_id="272">Astro Warna</channel>
<channel lang="ms" xmltv_id="AstroXiaoTaiYang.my" site_id="387">Astro Xiao Tai Yang</channel>
<channel lang="ms" xmltv_id="AwesomeTV.my" site_id="433">Awesome TV</channel>
<!-- <channel lang="ms" xmltv_id="" site_id="459">BBC Brit</channel> -->
<channel lang="ms" xmltv_id="AXNMalaysia.my" site_id="131">AXN</channel>
<channel lang="ms" xmltv_id="BBCEarthAsia.uk" site_id="452">BBC Earth</channel>
<channel lang="ms" xmltv_id="BBCFirstMalaysia.my" site_id="458">BBC First</channel>
<channel lang="ms" xmltv_id="BBCLifestyleAsia.uk" site_id="451">BBC Lifestyle</channel>
@ -60,20 +59,20 @@
<channel lang="ms" xmltv_id="BloombergTVAsiaPacific.hk" site_id="422">Bloomberg TV</channel>
<channel lang="ms" xmltv_id="Boo.my" site_id="251">Boo</channel>
<channel lang="ms" xmltv_id="BoomerangSoutheastAsia.us" site_id="430">Boomerang</channel>
<channel lang="ms" xmltv_id="CartoonNetworkAsia.sg" site_id="371">Cartoon Network HD</channel>
<channel lang="ms" xmltv_id="CCTV4Asia.cn" site_id="385">CCTV 4</channel>
<channel lang="ms" xmltv_id="CelestialClassicMovies.hk" site_id="187">Celestial Classic Movies</channel>
<channel lang="ms" xmltv_id="CelestialMoviesMalaysia.my" site_id="134">Celestial Movies</channel>
<channel lang="ms" xmltv_id="CGTN.cn" site_id="426">CGTN</channel>
<channel lang="ms" xmltv_id="ChuttiTVMalaysia.my" site_id="51">Chutti TV</channel>
<channel lang="ms" xmltv_id="CinemaxAsia.sg" site_id="337">Cinemax</channel>
<channel lang="ms" xmltv_id="CNA.sg" site_id="295">CNA</channel>
<channel lang="ms" xmltv_id="CNBCAsia.sg" site_id="423">CNBC Asia-Pacific</channel>
<channel lang="ms" xmltv_id="CNNInternationalAsiaPacific.hk" site_id="336">CNN</channel>
<channel lang="ms" xmltv_id="CTiAsia.tw" site_id="424">CTI TV</channel>
<channel lang="ms" xmltv_id="CartoonNetworkAsia.sg" site_id="371">Cartoon Network HD</channel>
<channel lang="ms" xmltv_id="CelestialClassicMovies.hk" site_id="187">Celestial Classic Movies</channel>
<channel lang="ms" xmltv_id="CelestialMoviesMalaysia.my" site_id="134">Celestial Movies</channel>
<channel lang="ms" xmltv_id="ChuttiTVMalaysia.my" site_id="51">Chutti TV</channel>
<channel lang="ms" xmltv_id="CinemaxAsia.sg" site_id="337">Cinemax</channel>
<channel lang="ms" xmltv_id="Colors.in" site_id="365">Colors</channel>
<channel lang="ms" xmltv_id="ColorsTamil.in" site_id="298">Colors Tamil</channel>
<channel lang="ms" xmltv_id="CrimePlusInvestigationAsia.us" site_id="369">Crime + Investigation</channel>
<channel lang="ms" xmltv_id="CTiAsia.tw" site_id="424">CTI TV</channel>
<channel lang="ms" xmltv_id="DiscoveryAsiaThailand.th" site_id="136">Discovery Asia</channel>
<channel lang="ms" xmltv_id="DiscoveryChannelHDIndonesia.id" site_id="376">Discovery Channel</channel>
<channel lang="ms" xmltv_id="DMAXAsia.sg" site_id="367">DMAX</channel>
@ -82,33 +81,33 @@
<channel lang="ms" xmltv_id="EurosportAsia.fr" site_id="339">Eurosport</channel>
<channel lang="ms" xmltv_id="FoodNetworkAsia.sg" site_id="153">Food Network</channel>
<channel lang="ms" xmltv_id="France24English.fr" site_id="289">France 24 English</channel>
<channel lang="ms" xmltv_id="GolfChannelMalaysia.my" site_id="189">Golf Channel</channel>
<channel lang="ms" xmltv_id="GoShopChinese.my" site_id="202">Go Shop Chinese</channel>
<channel lang="ms" xmltv_id="GoShopMalay111.my" site_id="403">Go Shop Malay 111</channel>
<channel lang="ms" xmltv_id="GoShopMalay118.my" site_id="192">Go Shop Malay 118</channel>
<channel lang="ms" xmltv_id="GoShopMalay120.my" site_id="294">Go Shop Malay 120</channel>
<channel lang="ms" xmltv_id="GolfChannelMalaysia.my" site_id="189">Golf Channel</channel>
<channel lang="ms" xmltv_id="HBOAsia.sg" site_id="143">HBO</channel>
<channel lang="ms" xmltv_id="HBOFamilyAsia.sg" site_id="450">HBO Family</channel>
<channel lang="ms" xmltv_id="HBOHitsAsia.sg" site_id="449">HBO Hits</channel>
<channel lang="ms" xmltv_id="HBOAsia.sg" site_id="143">HBO</channel>
<channel lang="ms" xmltv_id="HGTVAsia.us" site_id="198">HGTV</channel>
<channel lang="ms" xmltv_id="HistoryAsia.us" site_id="144">History</channel>
<channel lang="ms" xmltv_id="Hits.sg" site_id="179">Hits</channel>
<channel lang="ms" xmltv_id="HitsMovies.sg" site_id="391">Hits Movies</channel>
<channel lang="ms" xmltv_id="iQIYI.cn" site_id="355">Iqiyi</channel>
<channel lang="ms" xmltv_id="KBSWorld.kr" site_id="161">KBS World</channel>
<channel lang="ms" xmltv_id="KPlus.sg" site_id="266">K+</channel>
<channel lang="ms" xmltv_id="Kix.hk" site_id="157">Kix</channel>
<channel lang="ms" xmltv_id="KPlus.sg" site_id="266">K+</channel>
<channel lang="ms" xmltv_id="LifetimeAsia.us" site_id="447">Lifetime</channel>
<channel lang="ms" xmltv_id="MTVAsia.sg" site_id="420">MTV</channel>
<channel lang="ms" xmltv_id="MoonbugKids.uk" site_id="465">Moonbug Kids</channel>
<channel lang="ms" xmltv_id="NHKWorldPremium.jp" site_id="428">NHK World Premium</channel>
<channel lang="ms" xmltv_id="NTV7.my" site_id="93">NTV 7</channel>
<channel lang="ms" xmltv_id="MTVAsia.sg" site_id="420">MTV</channel>
<channel lang="ms" xmltv_id="NatGeoPeopleMalaysia.my" site_id="199">Nat Geo People</channel>
<channel lang="ms" xmltv_id="NationalGeographicMalaysia.my" site_id="140">National Geographic</channel>
<channel lang="ms" xmltv_id="NationalGeographicWildMalaysia.my" site_id="322">National Geographic Wild</channel>
<channel lang="ms" xmltv_id="NickJrAsia.sg" site_id="392">Nick Jr</channel>
<channel lang="ms" xmltv_id="NHKWorldPremium.jp" site_id="428">NHK World Premium</channel>
<channel lang="ms" xmltv_id="NickelodeonAsia.sg" site_id="370">Nickelodeon</channel>
<channel lang="ms" xmltv_id="NickJrAsia.sg" site_id="392">Nick Jr</channel>
<channel lang="ms" xmltv_id="NjoiTV.my" site_id="302">Njoi TV</channel>
<channel lang="ms" xmltv_id="NTV7.my" site_id="93">NTV 7</channel>
<channel lang="ms" xmltv_id="OneTVAsia.sg" site_id="133">One</channel>
<channel lang="ms" xmltv_id="ParamountNetworkMalaysia.my" site_id="448">Paramount Network</channel>
<channel lang="ms" xmltv_id="PhoenixChineseChannel.hk" site_id="382">Phoenix Chinese Channel</channel>
@ -124,6 +123,7 @@
<channel lang="ms" xmltv_id="StarVijay.in" site_id="357">Star Vijay</channel>
<channel lang="ms" xmltv_id="SunMusic.in" site_id="417">Sun Music</channel>
<channel lang="ms" xmltv_id="SunTVMalaysia.my" site_id="358">Sun TV</channel>
<channel lang="ms" xmltv_id="TADAA.my" site_id="432">Ta-Daa!</channel>
<channel lang="ms" xmltv_id="TLCSoutheastAsia.us" site_id="338">TLC</channel>
<channel lang="ms" xmltv_id="TV3.my" site_id="106">TV 3</channel>
<channel lang="ms" xmltv_id="TV9.my" site_id="48">TV 9</channel>
@ -136,9 +136,8 @@
<channel lang="ms" xmltv_id="TVNAsia.hk" site_id="190">TVN HD</channel>
<channel lang="ms" xmltv_id="TVNMovies.hk" site_id="274">TVN Movies</channel>
<channel lang="ms" xmltv_id="TVS.my" site_id="429">TVS</channel>
<channel lang="ms" xmltv_id="TADAA.my" site_id="432">Ta-Daa!</channel>
<channel lang="ms" xmltv_id="WWENetwork.us" site_id="194">WWE Network</channel>
<channel lang="ms" xmltv_id="WarnerTVAsia.us" site_id="270">Warner TV</channel>
<channel lang="ms" xmltv_id="WWENetwork.us" site_id="194">WWE Network</channel>
<channel lang="ms" xmltv_id="ZeeTamil.in" site_id="297">Zee Tamil</channel>
</channels>
</site>