Fixes linter errors
This commit is contained in:
1 parent
57e508fc3b
commit
63c86a2b30
393 files changed
+28447
-28443
No files matched your search
@@ -1,89 +1,89 @@
|
||||
const axios = require('axios')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
const API_ENDPOINT = 'http://epg.i-cable.com/ci/channel'
|
||||
|
||||
module.exports = {
|
||||
site: 'epg.i-cable.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1h
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
return `${API_ENDPOINT}/epg/${channel.site_id}/${date.format('YYYY-MM-DD')}?api=api`
|
||||
},
|
||||
parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
for (let item of items) {
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart(item, date)
|
||||
const stop = start.plus({ minutes: 30 })
|
||||
if (prev) {
|
||||
if (start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
programs.push({
|
||||
title: parseTitle(item, channel),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang }) {
|
||||
const data = await axios
|
||||
.get(`${API_ENDPOINT}/category/0?api=api`)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
let channels = []
|
||||
const promises = data.cates.map(c => axios.get(`${API_ENDPOINT}/category/${c.cate_id}?api=api`))
|
||||
await Promise.allSettled(promises).then(results => {
|
||||
results.forEach(r => {
|
||||
if (r.status === 'fulfilled') {
|
||||
channels = channels.concat(r.value.data.chs)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return channels.map(c => {
|
||||
let name = lang === 'zh' ? c.channel_name : c.channel_name_en
|
||||
name = c.remark_id == 3 ? `${name} [HD]` : name
|
||||
|
||||
return {
|
||||
site_id: c.channel_no,
|
||||
name,
|
||||
lang
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle(item, channel) {
|
||||
return channel.lang === 'en' ? item.programme_name_eng : item.programme_name_chi
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let meridiem = item.session_mark === 'PM' ? 'PM' : 'AM'
|
||||
return DateTime.fromFormat(
|
||||
`${date.format('YYYY-MM-DD')} ${item.time} ${meridiem}`,
|
||||
'yyyy-MM-dd hh:mm a',
|
||||
{
|
||||
zone: 'Asia/Hong_Kong'
|
||||
}
|
||||
).toUTC()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.epgs)) return []
|
||||
|
||||
return data.epgs
|
||||
}
|
||||
const axios = require('axios')
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
const API_ENDPOINT = 'http://epg.i-cable.com/ci/channel'
|
||||
|
||||
module.exports = {
|
||||
site: 'epg.i-cable.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1h
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
return `${API_ENDPOINT}/epg/${channel.site_id}/${date.format('YYYY-MM-DD')}?api=api`
|
||||
},
|
||||
parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
for (let item of items) {
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = parseStart(item, date)
|
||||
const stop = start.plus({ minutes: 30 })
|
||||
if (prev) {
|
||||
if (start < prev.start) {
|
||||
start = start.plus({ days: 1 })
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
programs.push({
|
||||
title: parseTitle(item, channel),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang }) {
|
||||
const data = await axios
|
||||
.get(`${API_ENDPOINT}/category/0?api=api`)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
|
||||
let channels = []
|
||||
const promises = data.cates.map(c => axios.get(`${API_ENDPOINT}/category/${c.cate_id}?api=api`))
|
||||
await Promise.allSettled(promises).then(results => {
|
||||
results.forEach(r => {
|
||||
if (r.status === 'fulfilled') {
|
||||
channels = channels.concat(r.value.data.chs)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return channels.map(c => {
|
||||
let name = lang === 'zh' ? c.channel_name : c.channel_name_en
|
||||
name = c.remark_id == 3 ? `${name} [HD]` : name
|
||||
|
||||
return {
|
||||
site_id: c.channel_no,
|
||||
name,
|
||||
lang
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle(item, channel) {
|
||||
return channel.lang === 'en' ? item.programme_name_eng : item.programme_name_chi
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let meridiem = item.session_mark === 'PM' ? 'PM' : 'AM'
|
||||
return DateTime.fromFormat(
|
||||
`${date.format('YYYY-MM-DD')} ${item.time} ${meridiem}`,
|
||||
'yyyy-MM-dd hh:mm a',
|
||||
{
|
||||
zone: 'Asia/Hong_Kong'
|
||||
}
|
||||
).toUTC()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.epgs)) return []
|
||||
|
||||
return data.epgs
|
||||
}
|
||||
@@ -1,73 +1,73 @@
|
||||
// npm run channels:parse -- --config=./sites/epg.i-cable.com/epg.i-cable.com.config.js --output=./sites/epg.i-cable.com/epg.i-cable.com.channels.xml --set=lang:zh
|
||||
// npm run grab -- --site=epg.i-cable.com
|
||||
|
||||
const { parser, url } = require('./epg.i-cable.com.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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-11-15', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '003',
|
||||
xmltv_id: 'HOYTV.hk',
|
||||
lang: 'zh'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'http://epg.i-cable.com/ci/channel/epg/003/2022-11-15?api=api'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-14T22:00:00.000Z',
|
||||
stop: '2022-11-14T23:00:00.000Z',
|
||||
title: 'Bloomberg 時段'
|
||||
})
|
||||
|
||||
expect(results[31]).toMatchObject({
|
||||
start: '2022-11-15T21:00:00.000Z',
|
||||
stop: '2022-11-15T21:30:00.000Z',
|
||||
title: 'Bloomberg 時段'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response in English', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const channelEN = { ...channel, lang: 'en' }
|
||||
let results = parser({ content, channel: channelEN, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-14T22:00:00.000Z',
|
||||
stop: '2022-11-14T23:00:00.000Z',
|
||||
title: 'Bloomberg Hour'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
const results = parser({ date, channel, content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/epg.i-cable.com/epg.i-cable.com.config.js --output=./sites/epg.i-cable.com/epg.i-cable.com.channels.xml --set=lang:zh
|
||||
// npm run grab -- --site=epg.i-cable.com
|
||||
|
||||
const { parser, url } = require('./epg.i-cable.com.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)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-11-15', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '003',
|
||||
xmltv_id: 'HOYTV.hk',
|
||||
lang: 'zh'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'http://epg.i-cable.com/ci/channel/epg/003/2022-11-15?api=api'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-14T22:00:00.000Z',
|
||||
stop: '2022-11-14T23:00:00.000Z',
|
||||
title: 'Bloomberg 時段'
|
||||
})
|
||||
|
||||
expect(results[31]).toMatchObject({
|
||||
start: '2022-11-15T21:00:00.000Z',
|
||||
stop: '2022-11-15T21:30:00.000Z',
|
||||
title: 'Bloomberg 時段'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response in English', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const channelEN = { ...channel, lang: 'en' }
|
||||
let results = parser({ content, channel: channelEN, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-14T22:00:00.000Z',
|
||||
stop: '2022-11-14T23:00:00.000Z',
|
||||
title: 'Bloomberg Hour'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||
const results = parser({ date, channel, content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
Reference in new issue
Block a user