mirror of
https://github.com/iptv-org/epg
synced 2026-04-28 13:37:01 -04:00
Replace LF line endings with CRLF
This commit is contained in:
@@ -1,92 +1,92 @@
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const tz = 'Asia/Hong_Kong'
|
||||
|
||||
module.exports = {
|
||||
site: 'programme.tvb.com',
|
||||
days: 2,
|
||||
url({ channel, date, time = null }) {
|
||||
return `https://programme.tvb.com/api/schedule?input_date=${date.format(
|
||||
'YYYYMMDD'
|
||||
)}&network_code=${channel.site_id}&_t=${time ? time : parseInt(Date.now() / 1000)}`
|
||||
},
|
||||
parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
const data = content ? JSON.parse(content) : {}
|
||||
if (Array.isArray(data.data?.list)) {
|
||||
for (const d of data.data.list) {
|
||||
if (Array.isArray(d.schedules)) {
|
||||
const schedules = d.schedules.filter(s => s.network_code === channel.site_id)
|
||||
schedules.forEach((s, i) => {
|
||||
const start = dayjs.tz(s.event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
|
||||
let stop
|
||||
if (i < schedules.length - 1) {
|
||||
stop = dayjs.tz(schedules[i + 1].event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
|
||||
} else {
|
||||
stop = date.add(1, 'd')
|
||||
}
|
||||
programs.push({
|
||||
title: channel.lang === 'en' ? s.en_programme_title : s.programme_title,
|
||||
description: channel.lang === 'en' ? s.en_synopsis : s.synopsis,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang = 'en' }) {
|
||||
const channels = []
|
||||
const axios = require('axios')
|
||||
const base = 'https://programme.tvb.com'
|
||||
const queues = [base]
|
||||
while (true) {
|
||||
if (queues.length) {
|
||||
const url = queues.shift()
|
||||
const content = await axios
|
||||
.get(url)
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
if (content) {
|
||||
const assets = content.match(/assets\/index\.([a-z0-9]+)\.js/g)
|
||||
if (assets) {
|
||||
queues.push(...assets.map(a => base + '/' + a))
|
||||
} else {
|
||||
const metadata = content.match(/e=(\[(.*?)\])/)
|
||||
if (metadata) {
|
||||
const infos = eval(metadata[1])
|
||||
if (Array.isArray(infos)) {
|
||||
infos
|
||||
.filter(a => a.code.length)
|
||||
.map(a => {
|
||||
channels.push({
|
||||
lang,
|
||||
site_id: a.code,
|
||||
name: lang === 'en' ? a.nameEn : a.name
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (queues.length) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const tz = 'Asia/Hong_Kong'
|
||||
|
||||
module.exports = {
|
||||
site: 'programme.tvb.com',
|
||||
days: 2,
|
||||
url({ channel, date, time = null }) {
|
||||
return `https://programme.tvb.com/api/schedule?input_date=${date.format(
|
||||
'YYYYMMDD'
|
||||
)}&network_code=${channel.site_id}&_t=${time ? time : parseInt(Date.now() / 1000)}`
|
||||
},
|
||||
parser({ content, channel, date }) {
|
||||
const programs = []
|
||||
const data = content ? JSON.parse(content) : {}
|
||||
if (Array.isArray(data.data?.list)) {
|
||||
for (const d of data.data.list) {
|
||||
if (Array.isArray(d.schedules)) {
|
||||
const schedules = d.schedules.filter(s => s.network_code === channel.site_id)
|
||||
schedules.forEach((s, i) => {
|
||||
const start = dayjs.tz(s.event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
|
||||
let stop
|
||||
if (i < schedules.length - 1) {
|
||||
stop = dayjs.tz(schedules[i + 1].event_datetime, 'YYYY-MM-DD HH:mm:ss', tz)
|
||||
} else {
|
||||
stop = date.add(1, 'd')
|
||||
}
|
||||
programs.push({
|
||||
title: channel.lang === 'en' ? s.en_programme_title : s.programme_title,
|
||||
description: channel.lang === 'en' ? s.en_synopsis : s.synopsis,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang = 'en' }) {
|
||||
const channels = []
|
||||
const axios = require('axios')
|
||||
const base = 'https://programme.tvb.com'
|
||||
const queues = [base]
|
||||
while (true) {
|
||||
if (queues.length) {
|
||||
const url = queues.shift()
|
||||
const content = await axios
|
||||
.get(url)
|
||||
.then(response => response.data)
|
||||
.catch(console.error)
|
||||
if (content) {
|
||||
const assets = content.match(/assets\/index\.([a-z0-9]+)\.js/g)
|
||||
if (assets) {
|
||||
queues.push(...assets.map(a => base + '/' + a))
|
||||
} else {
|
||||
const metadata = content.match(/e=(\[(.*?)\])/)
|
||||
if (metadata) {
|
||||
const infos = eval(metadata[1])
|
||||
if (Array.isArray(infos)) {
|
||||
infos
|
||||
.filter(a => a.code.length)
|
||||
.map(a => {
|
||||
channels.push({
|
||||
lang,
|
||||
site_id: a.code,
|
||||
name: lang === 'en' ? a.nameEn : a.name
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (queues.length) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
const { parser, url } = require('./programme.tvb.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)
|
||||
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const date = dayjs.utc('2024-12-06', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'J',
|
||||
xmltv_id: 'Jade.hk',
|
||||
lang: 'en'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const time = 1733491000
|
||||
expect(url({ channel, date, time })).toBe(
|
||||
'https://programme.tvb.com/api/schedule?input_date=20241206&network_code=J&_t=1733491000'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response (en)', () => {
|
||||
const results = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(3)
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2024-12-06T15:55:00.000Z',
|
||||
stop: '2024-12-06T16:55:00.000Z',
|
||||
title: 'Line Walker: Bull Fight#16[Can][PG]'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response (zh)', () => {
|
||||
const results = parser({ content, channel: { ...channel, lang: 'zh' }, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(3)
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2024-12-06T15:55:00.000Z',
|
||||
stop: '2024-12-06T16:55:00.000Z',
|
||||
title: '使徒行者3#16[粵][PG]',
|
||||
description:
|
||||
'文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: '',
|
||||
date
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
const { parser, url } = require('./programme.tvb.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)
|
||||
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const date = dayjs.utc('2024-12-06', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'J',
|
||||
xmltv_id: 'Jade.hk',
|
||||
lang: 'en'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
const time = 1733491000
|
||||
expect(url({ channel, date, time })).toBe(
|
||||
'https://programme.tvb.com/api/schedule?input_date=20241206&network_code=J&_t=1733491000'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response (en)', () => {
|
||||
const results = parser({ content, channel, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(3)
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2024-12-06T15:55:00.000Z',
|
||||
stop: '2024-12-06T16:55:00.000Z',
|
||||
title: 'Line Walker: Bull Fight#16[Can][PG]'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response (zh)', () => {
|
||||
const results = parser({ content, channel: { ...channel, lang: 'zh' }, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(3)
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2024-12-06T15:55:00.000Z',
|
||||
stop: '2024-12-06T16:55:00.000Z',
|
||||
title: '使徒行者3#16[粵][PG]',
|
||||
description:
|
||||
'文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: '',
|
||||
date
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channels>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="" site_id="B">tvb plus</channel>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="Jade.hk" site_id="J">jade</channel>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="Pearl.hk" site_id="P">pearl</channel>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="TVBNewsChannel.hk" site_id="C">tvb news channel</channel>
|
||||
</channels>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channels>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="" site_id="B">tvb plus</channel>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="Jade.hk" site_id="J">jade</channel>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="Pearl.hk" site_id="P">pearl</channel>
|
||||
<channel site="programme.tvb.com" lang="en" xmltv_id="TVBNewsChannel.hk" site_id="C">tvb news channel</channel>
|
||||
</channels>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channels>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="" site_id="B">TVB Plus</channel>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="Jade.hk" site_id="J">翡翠台</channel>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="Pearl.hk" site_id="P">明珠台</channel>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBNewsChannel.hk" site_id="C">無綫新聞台</channel>
|
||||
</channels>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<channels>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="" site_id="B">TVB Plus</channel>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="Jade.hk" site_id="J">翡翠台</channel>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="Pearl.hk" site_id="P">明珠台</channel>
|
||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBNewsChannel.hk" site_id="C">無綫新聞台</channel>
|
||||
</channels>
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
# programme.tvb.com
|
||||
|
||||
https://www.programme.tvb.com/
|
||||
|
||||
### Download the guide
|
||||
|
||||
English:
|
||||
|
||||
```sh
|
||||
npm run grab --- --site=programme.tvb.com --lang=en
|
||||
```
|
||||
|
||||
Chinese:
|
||||
|
||||
```sh
|
||||
npm run grab --- --site=programme.tvb.com --lang=zh
|
||||
```
|
||||
|
||||
### Update channel list
|
||||
|
||||
English:
|
||||
|
||||
```sh
|
||||
npm run channels:parse --- --config=sites/programme.tvb.com/programme.tvb.com.config.js --output=sites/programme.tvb.com/programme.tvb.com_en.channels.xml --set=lang:en
|
||||
```
|
||||
|
||||
Chinese:
|
||||
|
||||
```sh
|
||||
npm run channels:parse --- --config=sites/programme.tvb.com/programme.tvb.com.config.js --output=sites/programme.tvb.com/programme.tvb.com_zh.channels.xml --set=lang:zh
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
```sh
|
||||
npm test --- programme.tvb.com
|
||||
```
|
||||
# programme.tvb.com
|
||||
|
||||
https://www.programme.tvb.com/
|
||||
|
||||
### Download the guide
|
||||
|
||||
English:
|
||||
|
||||
```sh
|
||||
npm run grab --- --site=programme.tvb.com --lang=en
|
||||
```
|
||||
|
||||
Chinese:
|
||||
|
||||
```sh
|
||||
npm run grab --- --site=programme.tvb.com --lang=zh
|
||||
```
|
||||
|
||||
### Update channel list
|
||||
|
||||
English:
|
||||
|
||||
```sh
|
||||
npm run channels:parse --- --config=sites/programme.tvb.com/programme.tvb.com.config.js --output=sites/programme.tvb.com/programme.tvb.com_en.channels.xml --set=lang:en
|
||||
```
|
||||
|
||||
Chinese:
|
||||
|
||||
```sh
|
||||
npm run channels:parse --- --config=sites/programme.tvb.com/programme.tvb.com.config.js --output=sites/programme.tvb.com/programme.tvb.com_zh.channels.xml --set=lang:zh
|
||||
```
|
||||
|
||||
### Test
|
||||
|
||||
```sh
|
||||
npm test --- programme.tvb.com
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user