mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Merge pull request #2130 from iptv-org/add-nhkworldpremium.com
Add nhkworldpremium.com
This commit is contained in:
commit
3a119500bd
6 changed files with 161 additions and 0 deletions
1
sites/nhkworldpremium.com/__data__/content_en.json
Normal file
1
sites/nhkworldpremium.com/__data__/content_en.json
Normal file
File diff suppressed because one or more lines are too long
1
sites/nhkworldpremium.com/__data__/content_ja.json
Normal file
1
sites/nhkworldpremium.com/__data__/content_ja.json
Normal file
File diff suppressed because one or more lines are too long
56
sites/nhkworldpremium.com/nhkworldpremium.com.config.js
Normal file
56
sites/nhkworldpremium.com/nhkworldpremium.com.config.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
module.exports = {
|
||||
site: 'nhkworldpremium.com',
|
||||
days: 7,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url({ channel }) {
|
||||
return `https://nhkworldpremium.com/backend/api/v1/front/episodes?lang=${channel.lang}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const start = dayjs.tz(item.schedule, 'Asia/Seoul')
|
||||
const duration = parseDuration(item)
|
||||
const stop = start.add(duration, 's')
|
||||
programs.push({
|
||||
title: item.programTitle,
|
||||
sub_title: item.episodeTitle,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseDuration(item) {
|
||||
const [h, m, s] = item.period.split(':')
|
||||
|
||||
if (!h || !m || !s) return 0
|
||||
|
||||
return parseInt(h) * 3600 + parseInt(m) * 60 + parseInt(s)
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
|
||||
if (!data || !data.item || !Array.isArray(data.item.episodes)) return []
|
||||
|
||||
return data.item.episodes.filter(ep => ep.schedule.startsWith(date.format('YYYY-MM-DD')))
|
||||
} catch (err) {
|
||||
return []
|
||||
}
|
||||
}
|
91
sites/nhkworldpremium.com/nhkworldpremium.com.test.js
Normal file
91
sites/nhkworldpremium.com/nhkworldpremium.com.test.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
// npx epg-grabber --config=sites/nhkworldpremium.com/nhkworldpremium.com.config.js --channels=sites/nhkworldpremium.com/nhkworldpremium.com_en.channels.xml --output=guide.xml
|
||||
// npx epg-grabber --config=sites/nhkworldpremium.com/nhkworldpremium.com.config.js --channels=sites/nhkworldpremium.com/nhkworldpremium.com_ja.channels.xml --output=guide.xml
|
||||
|
||||
const { parser, url, request } = require('./nhkworldpremium.com.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('2023-07-10', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '#',
|
||||
xmltv_id: 'NHKWorldPremium.jp',
|
||||
lang: 'en'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel })).toBe('https://nhkworldpremium.com/backend/api/v1/front/episodes?lang=en')
|
||||
})
|
||||
|
||||
it('can generate valid url for Japanese guide', () => {
|
||||
const channel = {
|
||||
site_id: '#',
|
||||
xmltv_id: 'NHKWorldPremium.jp',
|
||||
lang: 'ja'
|
||||
}
|
||||
|
||||
expect(url({ channel })).toBe('https://nhkworldpremium.com/backend/api/v1/front/episodes?lang=ja')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_en.json'))
|
||||
let results = parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(56)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-07-09T15:35:00.000Z',
|
||||
stop: '2023-07-09T16:20:00.000Z',
|
||||
title: 'NHK Amateur Singing Contest',
|
||||
sub_title: '"Maizuru City, Kyoto Prefecture"'
|
||||
})
|
||||
|
||||
expect(results[55]).toMatchObject({
|
||||
start: '2023-07-10T14:35:00.000Z',
|
||||
stop: '2023-07-10T15:15:00.000Z',
|
||||
title: 'International News Report 2023',
|
||||
sub_title: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response with Japanese guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_ja.json'))
|
||||
let results = parser({ content, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(56)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-07-09T15:35:00.000Z',
|
||||
stop: '2023-07-09T16:20:00.000Z',
|
||||
title: 'NHKのど自慢',
|
||||
sub_title: '【京都から生放送!▽前川清・相川七瀬】'
|
||||
})
|
||||
|
||||
expect(results[55]).toMatchObject({
|
||||
start: '2023-07-10T14:35:00.000Z',
|
||||
stop: '2023-07-10T15:15:00.000Z',
|
||||
title: '国際報道2023',
|
||||
sub_title: null
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({ content: {}, date })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="nhkworldpremium.com">
|
||||
<channels>
|
||||
<channel lang="en" xmltv_id="NHKWorldPremium.jp" site_id="#">NHK World Premium</channel>
|
||||
</channels>
|
||||
</site>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="nhkworldpremium.com">
|
||||
<channels>
|
||||
<channel lang="ja" xmltv_id="NHKWorldPremium.jp" site_id="#">NHK World Premium</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue