diff --git a/sites/vtm.be/vtm.be.config.js b/sites/vtm.be/vtm.be.config.js new file mode 100644 index 00000000..9eaa0ddb --- /dev/null +++ b/sites/vtm.be/vtm.be.config.js @@ -0,0 +1,55 @@ +const dayjs = require('dayjs') +const isBetween = require('dayjs/plugin/isBetween') + +dayjs.extend(isBetween) + +module.exports = { + site: 'vtm.be', + url: function ({ channel }) { + return `https://vtm.be/tv-gids/${channel.site_id}` + }, + request: { + timeout: 15000, + headers: { + Cookie: + 'ak_bmsc=8103DDA2C2C37ECD922124463C746A4C~000000000000000000000000000000~YAAQNwVJF7ndI+p8AQAAYDkcCg0mQAkQ2jDHjSfnXl9VIGnzditECZ1FDj1Yi72a8rv/Q454lDDY0Dm3TPqxJUuNLzxJGmgkLmei4IIIwzKJWbB6wC/FMQApoI1NbGz+tUErryic1HWdbZ2dz1IX+AkOHJ9RVupYG5GmkSEQdFG1+/dSZoBMWEeb/5VOCLmNXRDP7k8LnSXaIuKqp5c2MQB+uQ9DdHUd6bIje3dzuxbka9+nJZ+eX/pNbgWI41X2tiXLvPZKh91Tk9k98zrK0pwBnGpTJqDVxmafYH/CjkXoLgEUW3loZfgL9SqddG706a4LnRPhyLzW6W6SH7Q0QOFE4g54NKADVttS2gbXgVrICvo0bb0FAESaFjc5uDyOd+fV2XBGzw==; authId=54da9bc2-d387-4923-8773-3d33ec68710e; gtm_session=1; _sp_ses.417f=*; _ga=GA1.2.525677035.1636552212; _gid=GA1.2.386833723.1636552212; tcf20_purposes=functional|analytics|targeted_advertising|non-personalised_ads|personalisation|marketing|social_media|advertising_1|advertising_2|advertising_3|advertising_4|advertising_7|advertising_9|advertising_10; _gcl_au=1.1.112810754.1636552212; _gat_UA-538372-57=1; sp=4a32f074-5526-4654-9389-2516d799ec68; _gat_UA-6602938-21=1; _sp_id.417f=0c81a857-09dc-47c2-8e51-4fed976211c4.1636552212.1.1636552214.1636552212.55934f90-4bad-47ff-8c5e-cf904126dcfb; bm_sv=1A45EF31D80D05B688C17EAD85964E29~hFpINNxpFphfJ2LLPoLQTauvUpyAf3kaTeGZAMfI/UTMlTRFjoAGBQJPEUPvSw3rXw/swqqAICc74l56pEBVSw6aJYqaoRaiRAZXyWZzQ6jAoeP5SMsZwtvNzYQ3aJXVWM8W8a98J0trlnSjIIsRPQ==' + } + }, + logo({ content, channel }) { + const data = parseContent(content) + + return data && data.channelDetail[channel.site_id] + ? data.channelDetail[channel.site_id].channelLogoUrl + : null + }, + parser: function ({ content, date }) { + let programs = [] + const data = parseContent(content) + const items = parseItems(data, date) + items.forEach(item => { + programs.push({ + title: item.title, + description: item.synopsis, + category: item.genre, + icon: item.imageUrl, + start: dayjs(item.from).toJSON(), + stop: dayjs(item.to).toJSON() + }) + }) + + return programs + } +} + +function parseContent(content) { + const [_, json] = content.match(/window.__EPG_REDUX_DATA__=(.*);\n/i) || [null, null] + const data = JSON.parse(json) + + return data +} + +function parseItems(data, date) { + if (!data || !data.broadcasts) return [] + + return Object.values(data.broadcasts).filter(i => dayjs(i.from).isBetween(date, date.add(1, 'd'))) +} diff --git a/sites/vtm.be/vtm.be.test.js b/sites/vtm.be/vtm.be.test.js new file mode 100644 index 00000000..2603a441 --- /dev/null +++ b/sites/vtm.be/vtm.be.test.js @@ -0,0 +1,50 @@ +// npx epg-grabber --config=sites/vtm.be/vtm.be.config.js --channels=sites/vtm.be/vtm.be_be.channels.xml --output=.gh-pages/guides/be/vtm.be.epg.xml --days=2 + +const { parser, url, logo } = require('./vtm.be.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-10', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'vtm', + xmltv_id: 'VTM.be' +} +const content = ` ` + +it('can generate valid url', () => { + const result = url({ channel }) + expect(result).toBe('https://vtm.be/tv-gids/vtm') +}) + +it('can get logo url', () => { + expect(logo({ content, channel })).toBe( + 'https://images4.persgroep.net/rcs/-JpJ692wUcyJ14N20YNDKhK3JEU/diocontent/175372657/_fitwidth/500?appId=da11c75db9b73ea0f41f0cd0da631c71' + ) +}) + +it('can parse response', () => { + const result = parser({ date, channel, content }) + expect(result).toMatchObject([ + { + start: '2021-11-10T23:45:00.000Z', + stop: '2021-11-11T00:20:00.000Z', + title: 'Wooninspiraties', + icon: 'https://images4.persgroep.net/rcs/z5qrZHumkjuN5rWzoaRJ_BTdL7A/diocontent/209688322/_fill/600/400?appId=da11c75db9b73ea0f41f0cd0da631c71', + description: `Een team gaat op pad om inspiratie op te doen over alles wat met wonen en leven te maken heeft; Ze trekken heel het land door om de laatste trends en tips op het gebied van wonen te achterhalen.`, + category: 'Magazine' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: ` ` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/vtm.be/vtm.be_be.channels.xml b/sites/vtm.be/vtm.be_be.channels.xml new file mode 100644 index 00000000..31206d8f --- /dev/null +++ b/sites/vtm.be/vtm.be_be.channels.xml @@ -0,0 +1,12 @@ + + + + VTM + VTM 2 + VTM 3 + VTM 4 + Q-music Vlaanderen + VTM Gold + VTM Kids + + \ No newline at end of file