Skip to content

Commit 91ed0b5

Browse files
Merge pull request #2892 from arifbudiman/master
Adjustment to www3.nhk.or.jp parser due to source location and formatting change
2 parents 32d6345 + 892fcfe commit 91ed0b5

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

sites/www3.nhk.or.jp/__data__/schedule.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

sites/www3.nhk.or.jp/www3.nhk.or.jp.config.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ module.exports = {
77
delay: 5000,
88

99
url: function ({ date }) {
10-
return `https://nwapi.nhk.jp/nhkworld/epg/v7b/world/s${date.unix() * 1000}-e${
11-
date.add(1, 'd').unix() * 1000
12-
}.json`
10+
return `https://masterpl.hls.nhkworld.jp/epg/w/${date
11+
.toISOString()
12+
.slice(0, 10)
13+
.replace(/-/g, '')}.json`
1314
},
1415

1516
request: {
@@ -26,21 +27,20 @@ module.exports = {
2627
return context.channel.logo
2728
},
2829

29-
parser: function (context) {
30+
async parser(context) {
3031
const programs = []
31-
3232
const items = parseItems(context.content)
3333

34-
items.forEach(item => {
34+
for (let item of items) {
3535
programs.push({
3636
title: item.title,
37-
start: parseStart(item),
38-
stop: parseStop(item),
37+
sub_title: item.episodeTitle,
38+
start: dayjs(item.startTime, 'YYYY-MM-DDTHH:mm:ssZ'),
39+
stop: dayjs(item.endTime, 'YYYY-MM-DDTHH:mm:ssZ'),
3940
description: item.description,
40-
image: parseImage(item),
41-
sub_title: item.subtitle
41+
image: item.episodeThumbnailURL ? item.episodeThumbnailURL : item.thumbnail
4242
})
43-
})
43+
}
4444

4545
return programs
4646
}
@@ -49,20 +49,8 @@ module.exports = {
4949
function parseItems(content) {
5050
if (content != '') {
5151
const data = JSON.parse(content)
52-
return !data || !data.channel || !Array.isArray(data.channel.item) ? [] : data.channel.item
52+
return !data || !data.data || !Array.isArray(data.data) ? [] : data.data
5353
} else {
5454
return []
5555
}
5656
}
57-
58-
function parseStart(item) {
59-
return dayjs.unix(parseInt(item.pubDate) / 1000)
60-
}
61-
62-
function parseStop(item) {
63-
return dayjs.unix(parseInt(item.endDate) / 1000)
64-
}
65-
66-
function parseImage(item) {
67-
return 'https://www.nhk.or.jp' + item.thumbnail
68-
}
Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,67 @@
11
const { url, parser } = require('./www3.nhk.or.jp.config.js')
2+
const fs = require('fs')
3+
const path = require('path')
24
const dayjs = require('dayjs')
35
const utc = require('dayjs/plugin/utc')
46
dayjs.extend(utc)
57

6-
const date = dayjs.utc('2023-04-29', 'YYYY-MM-DD').startOf('d')
8+
const date = dayjs.utc('2025-10-20', 'YYYY-MM-DD').startOf('d')
9+
710
const channel = {
811
site_id: '0',
912
xmltv_id: 'NHKWorldJapan.jp',
1013
lang: 'en',
1114
logo: 'https://www3.nhk.or.jp/nhkworld/common/site_images/nw_webapp_1024x1024.png'
1215
}
1316

17+
const content = fs.readFileSync(path.resolve(__dirname, '__data__/schedule.json'), 'utf8')
18+
19+
const context = { channel: channel, content: content, date: date }
20+
1421
it('can generate valid url', () => {
15-
expect(url({ channel, date })).toBe(
16-
'https://nwapi.nhk.jp/nhkworld/epg/v7b/world/s1682726400000-e1682812800000.json'
22+
expect(url({ date })).toBe(
23+
'https://masterpl.hls.nhkworld.jp/epg/w/20251020.json'
1724
)
1825
})
1926

20-
it('can parse response', () => {
21-
const content =
22-
'{"channel":{"item":[{"seriesId":"1007","airingId":"000","title":"NHK NEWSLINE","description":"NHK WORLD-JAPAN\'s flagship hourly news program delivers the latest world news, business and weather, with a focus on Japan and the rest of Asia.","link":"/nhkworld/en/news/","pubDate":"1682726400000","endDate":"1682727000000","vodReserved":false,"jstrm":"1","wstrm":"1","subtitle":"","content":"","content_clean":"","pgm_gr_id":"","thumbnail":"/nhkworld/upld/thumbnails/en/tv/regular_program/340aed63308aafd1178172abf6325231_large.jpg","thumbnail_s":"/nhkworld/upld/thumbnails/en/tv/regular_program/340aed63308aafd1178172abf6325231_small.jpg","showlist":"0","internal":"0","genre":{"TV":"11","Top":"","LC":""},"vod_id":"","vod_url":"","analytics":"[nhkworld]simul;NHK NEWSLINE;w02,001;1007-000-2023;2023-04-29T09:00:00+09:00"}]}}'
23-
const results = parser({ content })
27+
it('can handle empty guide', async () => {
28+
const results = await parser({ content: '' })
29+
expect(results).toMatchObject([])
30+
})
31+
32+
it('can parse response', async () => {
33+
const results = await parser(context)
2434

25-
expect(results).toMatchObject([
35+
expect(results[0]).toMatchObject(
2636
{
2737
title: 'NHK NEWSLINE',
28-
start: dayjs(1682726400000),
29-
stop: dayjs(1682727000000),
30-
description:
31-
"NHK WORLD-JAPAN's flagship hourly news program delivers the latest world news, business and weather, with a focus on Japan and the rest of Asia.",
32-
image:
33-
'https://www.nhk.or.jp/nhkworld/upld/thumbnails/en/tv/regular_program/340aed63308aafd1178172abf6325231_large.jpg',
34-
sub_title: ''
38+
sub_title: '',
39+
start: dayjs('2025-10-19T15:00:00.000Z'),
40+
stop: dayjs('2025-10-19T15:10:00.000Z'),
41+
description: 'NHK NEWSLINE brings you up to date with the latest from Japan, Asia and around the world. Our team covers breaking news and major developments, with trusted anchors to tie it all together.',
42+
image: '',
3543
}
36-
])
37-
})
44+
)
3845

39-
it('can handle empty guide', () => {
40-
const results = parser({ content: '' })
46+
expect(results[1]).toMatchObject(
47+
{
48+
title: 'J-MELO',
49+
sub_title: 'Furui Riho and shallm',
50+
start: dayjs('2025-10-19T15:10:00.000Z'),
51+
stop: dayjs('2025-10-19T15:38:00.000Z'),
52+
description: '*This program was first broadcast on April 13, 2025. \nJoin May J. for Japanese music! This week: Furui Riho (a singer-songwriter with gospel roots) and shallm (a band project from vocalist, lyricist, and composer lia).\nOn Demand until October 26, 2025',
53+
image: 'https://www3.nhk.or.jp/nhkworld/en/shows/2004445/images/wide_l_7eJOqZrlZQFF8GEPfH0emqOOlggwyC543Cv71Oou.jpg',
54+
}
55+
)
4156

42-
expect(results).toMatchObject([])
57+
expect(results[2]).toMatchObject(
58+
{
59+
title: 'INFO',
60+
sub_title: '',
61+
start: dayjs('2025-10-19T15:38:00.000Z'),
62+
stop: dayjs('2025-10-19T15:40:00.000Z'),
63+
description: ' ',
64+
image: '',
65+
}
66+
)
4367
})

0 commit comments

Comments
 (0)