mirror of
https://github.com/iptv-org/epg
synced 2026-03-21 19:30:52 -04:00
Replace LF endings with CRLF
This commit is contained in:
@@ -1,137 +1,137 @@
|
||||
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: 'content.astro.com.my',
|
||||
days: 2,
|
||||
url: function ({ channel }) {
|
||||
return `${API_ENDPOINT}/channel/${channel.site_id}.json`
|
||||
},
|
||||
async parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
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: details.title,
|
||||
sub_title: item.subtitles,
|
||||
description: details.longSynopsis || details.shortSynopsis,
|
||||
actors: parseList(details.cast),
|
||||
directors: parseList(details.director),
|
||||
image: details.imageUrl,
|
||||
rating: parseRating(details),
|
||||
categories: parseCategories(details),
|
||||
episode: parseEpisode(item),
|
||||
season: parseSeason(details),
|
||||
start: start,
|
||||
stop: stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://contenthub-api.eco.astro.com.my/channel/all.json')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.response.map(item => {
|
||||
return {
|
||||
lang: 'ms',
|
||||
site_id: item.id,
|
||||
name: item.title
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseEpisode(item) {
|
||||
const [, number] = item.title.match(/Ep(\d+)$/) || [null, null]
|
||||
|
||||
return number ? parseInt(number) : null
|
||||
}
|
||||
|
||||
function parseSeason(details) {
|
||||
const [, season] = details.title ? details.title.match(/ S(\d+)/) || [null, null] : [null, null]
|
||||
|
||||
return season ? parseInt(season) : 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)
|
||||
const schedules = data.response.schedule
|
||||
|
||||
return schedules[date.format('YYYY-MM-DD')] || []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function parseDuration(duration) {
|
||||
const match = duration.match(/(\d{2}):(\d{2}):(\d{2})/)
|
||||
const hours = parseInt(match[1])
|
||||
const minutes = parseInt(match[2])
|
||||
const seconds = parseInt(match[3])
|
||||
|
||||
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(error => console.log(error.message))
|
||||
if (!data) return {}
|
||||
|
||||
return data.response || {}
|
||||
}
|
||||
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: 'content.astro.com.my',
|
||||
days: 2,
|
||||
url: function ({ channel }) {
|
||||
return `${API_ENDPOINT}/channel/${channel.site_id}.json`
|
||||
},
|
||||
async parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
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: details.title,
|
||||
sub_title: item.subtitles,
|
||||
description: details.longSynopsis || details.shortSynopsis,
|
||||
actors: parseList(details.cast),
|
||||
directors: parseList(details.director),
|
||||
image: details.imageUrl,
|
||||
rating: parseRating(details),
|
||||
categories: parseCategories(details),
|
||||
episode: parseEpisode(item),
|
||||
season: parseSeason(details),
|
||||
start: start,
|
||||
stop: stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://contenthub-api.eco.astro.com.my/channel/all.json')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.response.map(item => {
|
||||
return {
|
||||
lang: 'ms',
|
||||
site_id: item.id,
|
||||
name: item.title
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseEpisode(item) {
|
||||
const [, number] = item.title.match(/Ep(\d+)$/) || [null, null]
|
||||
|
||||
return number ? parseInt(number) : null
|
||||
}
|
||||
|
||||
function parseSeason(details) {
|
||||
const [, season] = details.title ? details.title.match(/ S(\d+)/) || [null, null] : [null, null]
|
||||
|
||||
return season ? parseInt(season) : 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)
|
||||
const schedules = data.response.schedule
|
||||
|
||||
return schedules[date.format('YYYY-MM-DD')] || []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function parseDuration(duration) {
|
||||
const match = duration.match(/(\d{2}):(\d{2}):(\d{2})/)
|
||||
const hours = parseInt(match[1])
|
||||
const minutes = parseInt(match[2])
|
||||
const seconds = parseInt(match[3])
|
||||
|
||||
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(error => console.log(error.message))
|
||||
if (!data) return {}
|
||||
|
||||
return data.response || {}
|
||||
}
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
const { parser, url } = require('./content.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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-31', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '425',
|
||||
xmltv_id: 'TVBClassic.hk'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('https://contenthub-api.eco.astro.com.my/channel/425.json')
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
|
||||
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(31)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-30T16:10:00.000Z',
|
||||
stop: '2022-10-30T17:02:00.000Z',
|
||||
title: 'Triumph in the Skies S1 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'],
|
||||
image: 'https://s3-ap-southeast-1.amazonaws.com/ams-astro/production/images/1035X328883.jpg',
|
||||
rating: {
|
||||
system: 'LPF',
|
||||
value: 'U'
|
||||
},
|
||||
episode: 6,
|
||||
season: 1,
|
||||
categories: ['Drama']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const results = await parser({ date, content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./content.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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-31', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '425',
|
||||
xmltv_id: 'TVBClassic.hk'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('https://contenthub-api.eco.astro.com.my/channel/425.json')
|
||||
})
|
||||
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
|
||||
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(31)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-30T16:10:00.000Z',
|
||||
stop: '2022-10-30T17:02:00.000Z',
|
||||
title: 'Triumph in the Skies S1 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'],
|
||||
image: 'https://s3-ap-southeast-1.amazonaws.com/ams-astro/production/images/1035X328883.jpg',
|
||||
rating: {
|
||||
system: 'LPF',
|
||||
value: 'U'
|
||||
},
|
||||
episode: 6,
|
||||
season: 1,
|
||||
categories: ['Drama']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const results = await parser({ date, content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user