// npx epg-grabber --config=sites/m.tv.sms.cz/m.tv.sms.cz.config.js --channels=sites/m.tv.sms.cz/m.tv.sms.cz.channels.xml --output=guide.xml --days=2 const { parser, url } = require('./m.tv.sms.cz.config.js') const iconv = require('iconv-lite') 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-03-30', 'YYYY-MM-DD').startOf('d') const channel = { site_id: 'Cero', xmltv_id: '0.es' } it('can generate valid url', () => { expect(url({ channel, date })).toBe( 'https://m.tv.sms.cz/index.php?stanice=Cero&cas=0&den=2022-03-30' ) }) it('can parse response', () => { let content = `
` const buffer = iconv.encode(content, 'win1250') const result = parser({ content, buffer, date }).map(p => { p.start = p.start.toJSON() p.stop = p.stop.toJSON() return p }) expect(result).toMatchObject([ { start: '2022-03-30T03:25:00.000Z', stop: '2022-03-30T04:00:00.000Z', title: `Před kamerou XIX (8)`, description: 'Filmový magazín Francie / USA (2022)' }, { start: '2022-03-30T04:00:00.000Z', stop: '2022-03-30T20:35:00.000Z', title: `Kubánská spojka`, description: 'Na přelomu 80. a 90. let minulého století podnikaly povstalecké skupiny sídlící na Floridě násilné ú...' }, { start: '2022-03-30T20:35:00.000Z', stop: '2022-03-30T23:15:00.000Z', title: `Patriot`, description: 'Jižní Karolína, 1776. Benjamin Martin, hrdina, který bojoval proti Francouzům a Indiánům, žije v kli...' }, { start: '2022-03-30T23:15:00.000Z', stop: '2022-03-31T00:25:00.000Z', title: `Chelsea Handler: Evoluce`, description: 'Chelsea Handlerová se po šestileté přestávce vrací ke stand-up comedy ve speciálu HBO Max. Během hod...' }, { start: '2022-03-31T00:25:00.000Z', stop: '2022-03-31T01:25:00.000Z', title: `Drápy IV (8)`, description: 'Kriminální komediální drama USA (2020)' } ]) }) it('can handle empty guide', () => { const result = parser({ buffer: iconv.encode( Buffer.from( `` ), 'win1250' ) }) expect(result).toMatchObject([]) })