mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #2494 from tohenk/fix/programme.tvb.com
Update programme.tvb.com guide.
This commit is contained in:
commit
ce4f3e6935
9 changed files with 147 additions and 79 deletions
File diff suppressed because one or more lines are too long
1
sites/programme.tvb.com/__data__/content.json
Normal file
1
sites/programme.tvb.com/__data__/content.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"code":0,"message":"","data":{"total":1,"list":[{"network_code":"j","ref_date":20241206,"schedules":[{"box_set_id":203,"network_code":"J","video_ratio":"2","video_definition":"1","event_time":1733500200,"event_datetime":"2024-12-06 23:50:00","programme_title":"天氣報告[粵] 及 潮流生活誌[粵]","en_programme_title":"Weather Report[Can] and Pop Lifestyle Guide (Ad Mag)[Can]","synopsis":"","en_synopsis":"","programme_path":"weatherreport_203","default_language":1,"play_available":1,"mytv_super_url":"https://www.mytvsuper.com/tc/programme/weatherreport_203/天氣報告[粵] 及 潮流生活誌[粵]","on_air_code":"L2,","tag":[{"icon":"hd","title":"HD"}]},{"box_set_id":0,"network_code":"J","video_ratio":"2","video_definition":"1","event_time":1733500500,"event_datetime":"2024-12-06 23:55:00","programme_title":"使徒行者3#16[粵][PG]","en_programme_title":"Line Walker: Bull Fight#16[Can][PG]","synopsis":"文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。","en_synopsis":"","programme_path":"","default_language":0,"play_available":0,"mytv_super_url":"","on_air_code":"S2,C2,C3,C1,A,PG11L,","tag":[{"icon":"s","title":"繁/簡中文字幕"},{"icon":"e","title":"英文字幕"},{"icon":"pg","title":"PG11L"},{"icon":"hd","title":"HD"}]},{"box_set_id":0,"network_code":"J","video_ratio":"1","video_definition":"2","event_time":1733504100,"event_datetime":"2024-12-07 00:55:00","programme_title":"宣傳易[粵]","en_programme_title":"TV Easy[Can]","synopsis":"","en_synopsis":"","programme_path":"","default_language":0,"play_available":0,"mytv_super_url":"","on_air_code":"D2,","tag":[]}]}]}}
|
|
@ -1,3 +0,0 @@
|
||||||
|
|
||||||
<ul class="clearfix" date="2022-11-15">
|
|
||||||
</ul>
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<channels>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="J2.hk" site_id="B">J2</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">Pearl</channel>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBChineseDrama.hk" site_id="U">華語劇台</channel>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBClassic.hk" site_id="E">TVB經典台</channel>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBClassicMovies.hk" site_id="W">粵語片台</channel>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBFinanceSportsInformationChannel.hk" site_id="A">無綫財經體育資訊台</channel>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBNewsChannel.hk" site_id="C">無綫新聞台</channel>
|
|
||||||
<channel site="programme.tvb.com" lang="zh" xmltv_id="TVBXingHe.hk" site_id="X">TVB星河頻道</channel>
|
|
||||||
</channels>
|
|
|
@ -1,5 +1,4 @@
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const cheerio = require('cheerio')
|
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
@ -8,57 +7,88 @@ dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
const tz = 'Asia/Hong_Kong'
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'programme.tvb.com',
|
site: 'programme.tvb.com',
|
||||||
days: 2,
|
days: 2,
|
||||||
url: function ({ channel, date }) {
|
url({ channel, date, time = null }) {
|
||||||
return `https://programme.tvb.com/ajax.php?action=channellist&code=${
|
return `https://programme.tvb.com/api/schedule?input_date=${
|
||||||
channel.site_id
|
date.format('YYYYMMDD')
|
||||||
}&date=${date.format('YYYY-MM-DD')}`
|
}&network_code=${channel.site_id}&_t=${time ? time : parseInt(Date.now() / 1000)}`
|
||||||
},
|
},
|
||||||
parser: function ({ content, date }) {
|
parser({ content, channel, date }) {
|
||||||
let programs = []
|
const programs = []
|
||||||
const items = parseItems(content)
|
const data = content ? JSON.parse(content) : {}
|
||||||
items.forEach(item => {
|
if (Array.isArray(data.data?.list)) {
|
||||||
const prev = programs[programs.length - 1]
|
const dt = date.format('YYYY-MM-DD')
|
||||||
const $item = cheerio.load(item)
|
for (const d of data.data.list) {
|
||||||
let start = parseStart($item, date)
|
if (Array.isArray(d.schedules)) {
|
||||||
if (prev) {
|
const schedules = d.schedules
|
||||||
if (start.isBefore(prev.start)) {
|
.filter(s => s.network_code === channel.site_id)
|
||||||
start = start.add(1, 'd')
|
schedules.forEach((s, i) => {
|
||||||
date = date.add(1, 'd')
|
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')
|
||||||
}
|
}
|
||||||
prev.stop = start
|
|
||||||
}
|
|
||||||
const stop = start.add(30, 'm')
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title: parseTitle($item),
|
title: channel.lang === 'en' ? s.en_programme_title : s.programme_title,
|
||||||
description: parseDescription($item),
|
description: channel.lang === 'en' ? s.en_synopsis : s.synopsis,
|
||||||
start,
|
start,
|
||||||
stop
|
stop
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return programs
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle($item) {
|
|
||||||
return $item('.ftit').text().trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseDescription($item) {
|
|
||||||
return $item('.full').text().trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseStart($item, date) {
|
|
||||||
const time = $item('.time').text()
|
|
||||||
|
|
||||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD hh:mmA', 'Asia/Hong_Kong')
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(content) {
|
|
||||||
const $ = cheerio.load(content)
|
|
||||||
|
|
||||||
return $('ul > li.item').toArray()
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,41 +4,60 @@ const path = require('path')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const date = dayjs.utc('2022-11-15', 'YYYY-MM-DD').startOf('d')
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||||
|
const date = dayjs.utc('2024-12-06', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: 'B',
|
site_id: 'J',
|
||||||
xmltv_id: 'J2.hk'
|
xmltv_id: 'Jade.hk',
|
||||||
|
lang: 'en'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url({ channel, date })).toBe(
|
const time = 1733491000
|
||||||
'https://programme.tvb.com/ajax.php?action=channellist&code=B&date=2022-11-15'
|
expect(url({ channel, date, time })).toBe(
|
||||||
|
'https://programme.tvb.com/api/schedule?input_date=20241206&network_code=J&_t=1733491000'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response (en)', () => {
|
||||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
const results = parser({ content, channel, date }).map(p => {
|
||||||
const results = parser({ content, date }).map(p => {
|
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(results[0]).toMatchObject({
|
expect(results.length).toBe(3)
|
||||||
start: '2022-11-14T22:00:00.000Z',
|
expect(results[1]).toMatchObject({
|
||||||
stop: '2022-11-14T23:00:00.000Z',
|
start: '2024-12-06T15:55:00.000Z',
|
||||||
title: '想見你#3[粵/普][PG]',
|
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:
|
description:
|
||||||
'韻如因父母離婚都不要自己而跑出家門,遇到子維,兩人互吐心事。雨萱順著照片上的唱片行線索,找到一家同名咖啡店,從文磊處得知照片中人是已經過世的韻如,從而推測那個男生也不是詮勝,但她內心反而更加痛苦。'
|
'文鼎從淑梅手上救走大聖爺兒子,大聖爺還恩於歡喜,答允支持九指強。崇聯社定下選舉日子,恰巧是韋傑出獄之日,頭目們顧念舊日恩義,紛紛轉投浩洋。浩洋帶亞希逛傢俬店,憧憬二人未來。亞希向家強承認愛上浩洋,要求退出臥底任務。作榮與歡喜暗中會面,將國際犯罪組織「永恆幫」情報交給他。阿火遭家強出賣,到沐足店搶錢。家強逮住阿火,惟被合星誤會而受拘捕。家強把正植遺下的頸鏈和學生證交還,合星意識到家強已知悉正植身世。',
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
const result = parser({
|
const result = parser({
|
||||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html')),
|
content: '',
|
||||||
date
|
date
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
|
|
|
@ -0,0 +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>
|
|
@ -0,0 +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>
|
|
@ -1,11 +1,33 @@
|
||||||
# programme.tvb.com
|
# programme.tvb.com
|
||||||
|
|
||||||
https://programme.tvb.com/
|
https://www.programme.tvb.com/
|
||||||
|
|
||||||
### Download the guide
|
### Download the guide
|
||||||
|
|
||||||
|
English:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm run grab -- --site=programme.tvb.com
|
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
|
### Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue