diff --git a/sites/pbsguam.org/pbsguam.org.config.js b/sites/pbsguam.org/pbsguam.org.config.js new file mode 100644 index 00000000..c27f2ebb --- /dev/null +++ b/sites/pbsguam.org/pbsguam.org.config.js @@ -0,0 +1,38 @@ +const dayjs = require('dayjs') +const isBetween = require('dayjs/plugin/isBetween') + +dayjs.extend(isBetween) + +module.exports = { + site: 'pbsguam.org', + url: 'https://pbsguam.org/calendar/', + logo({ channel }) { + return channel.logo + }, + parser: function ({ content, date }) { + let programs = [] + const items = parseItems(content, date) + items.forEach(item => { + programs.push({ + title: item.title, + start: dayjs(item.start), + stop: dayjs(item.end) + }) + }) + + return programs + } +} + +function parseItems(content, date) { + const [_, json] = content.match(/EventsSchedule_1 = (.*);/i) || [null, null] + if (!json) return [] + const data = JSON.parse(json) + if (!data || !Array.isArray(data.feed)) return [] + + return data.feed.filter( + i => + dayjs(i.start).isBetween(date, date.add(1, 'd')) || + dayjs(i.end).isBetween(date, date.add(1, 'd')) + ) +} diff --git a/sites/pbsguam.org/pbsguam.org.test.js b/sites/pbsguam.org/pbsguam.org.test.js new file mode 100644 index 00000000..1a60500d --- /dev/null +++ b/sites/pbsguam.org/pbsguam.org.test.js @@ -0,0 +1,55 @@ +// npx epg-grabber --config=sites/pbsguam.org/pbsguam.org.config.js --channels=sites/pbsguam.org/pbsguam.org_gu.channels.xml --output=.gh-pages/guides/gu/pbsguam.org.epg.xml --days=2 + +const { parser, url, logo } = require('./pbsguam.org.config.js') +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('2021-11-25', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '#', + xmltv_id: 'KGTF.us', + logo: 'https://pbsguam.org/wp-content/uploads/sites/10/2021/09/pbs-guam-blue.png' +} + +it('can generate valid url', () => { + expect(url).toBe('https://pbsguam.org/calendar/') +}) + +it('can get logo url', () => { + expect(logo({ channel })).toBe( + 'https://pbsguam.org/wp-content/uploads/sites/10/2021/09/pbs-guam-blue.png' + ) +}) + +it('can parse response', () => { + const content = `
` + const result = parser({ date, content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2021-11-25T08:30:00.000Z', + stop: '2021-11-25T09:00:00.000Z', + title: 'Xavier Riddle and the Secret Museum' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: ` ` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/pbsguam.org/pbsguam.org_gu.channels.xml b/sites/pbsguam.org/pbsguam.org_gu.channels.xml new file mode 100644 index 00000000..5704bbcf --- /dev/null +++ b/sites/pbsguam.org/pbsguam.org_gu.channels.xml @@ -0,0 +1,6 @@ + +