mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Merge pull request #1333 from iptv-org/add-programme.tvb.com
Add guide from programme.tvb.com
This commit is contained in:
commit
7d8e23b93c
6 changed files with 147 additions and 0 deletions
17
.github/workflows/programme.tvb.com.yml
vendored
Normal file
17
.github/workflows/programme.tvb.com.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
name: programme.tvb.com
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 3 * * *'
|
||||
workflow_dispatch:
|
||||
workflow_run:
|
||||
workflows: [_trigger]
|
||||
types:
|
||||
- completed
|
||||
jobs:
|
||||
load:
|
||||
uses: ./.github/workflows/_load.yml
|
||||
with:
|
||||
site: ${{github.workflow}}
|
||||
secrets:
|
||||
APP_ID: ${{ secrets.APP_ID }}
|
||||
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
|
3
sites/programme.tvb.com/__data__/content.html
Normal file
3
sites/programme.tvb.com/__data__/content.html
Normal file
File diff suppressed because one or more lines are too long
3
sites/programme.tvb.com/__data__/no-content.html
Normal file
3
sites/programme.tvb.com/__data__/no-content.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
<ul class="clearfix" date="2022-11-15">
|
||||
</ul>
|
63
sites/programme.tvb.com/programme.tvb.com.config.js
Normal file
63
sites/programme.tvb.com/programme.tvb.com.config.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
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)
|
||||
|
||||
module.exports = {
|
||||
site: 'programme.tvb.com',
|
||||
url: function ({ channel, date }) {
|
||||
return `https://programme.tvb.com/ajax.php?action=channellist&code=${
|
||||
channel.site_id
|
||||
}&date=${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
const stop = start.add(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
47
sites/programme.tvb.com/programme.tvb.com.test.js
Normal file
47
sites/programme.tvb.com/programme.tvb.com.test.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
// npx epg-grabber --config=sites/programme.tvb.com/programme.tvb.com.config.js --channels=sites/programme.tvb.com/programme.tvb.com_hk.channels.xml --output=guide.xml --days=2
|
||||
|
||||
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 date = dayjs.utc('2022-11-15', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'B',
|
||||
xmltv_id: 'J2.hk'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://programme.tvb.com/ajax.php?action=channellist&code=B&date=2022-11-15'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).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: '想見你#3[粵/普][PG]',
|
||||
description:
|
||||
'韻如因父母離婚都不要自己而跑出家門,遇到子維,兩人互吐心事。雨萱順著照片上的唱片行線索,找到一家同名咖啡店,從文磊處得知照片中人是已經過世的韻如,從而推測那個男生也不是詮勝,但她內心反而更加痛苦。'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.html')),
|
||||
date
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
14
sites/programme.tvb.com/programme.tvb.com_hk.channels.xml
Normal file
14
sites/programme.tvb.com/programme.tvb.com_hk.channels.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="programme.tvb.com">
|
||||
<channels>
|
||||
<channel lang="zh" xmltv_id="J2.hk" site_id="B">J2</channel>
|
||||
<channel lang="zh" xmltv_id="TVBChineseDrama.hk" site_id="U">華語劇台</channel>
|
||||
<channel lang="zh" xmltv_id="TVBClassic.hk" site_id="E">TVB經典台</channel>
|
||||
<channel lang="zh" xmltv_id="TVBClassicMovies.hk" site_id="W">粵語片台</channel>
|
||||
<channel lang="zh" xmltv_id="TVBFinanceInformationChannel.hk" site_id="A">無綫財經體育資訊台</channel>
|
||||
<channel lang="zh" xmltv_id="TVBJade.hk" site_id="J">翡翠台</channel>
|
||||
<channel lang="zh" xmltv_id="TVBNewsChannel.hk" site_id="C">無綫新聞台</channel>
|
||||
<channel lang="zh" xmltv_id="TVBPearl.hk" site_id="P">Pearl</channel>
|
||||
<channel lang="zh" xmltv_id="TVBXingHe.hk" site_id="X">TVB星河頻道</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue