From 4724e9a3a8aa2c11a5286c6de99b192eccc38ace Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 25 Nov 2021 00:57:25 +0300 Subject: [PATCH 1/2] Update turksatkablo.com.tr.test.js --- .../turksatkablo.com.tr.test.js | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/sites/turksatkablo.com.tr/turksatkablo.com.tr.test.js b/sites/turksatkablo.com.tr/turksatkablo.com.tr.test.js index a115c647..13a157c4 100644 --- a/sites/turksatkablo.com.tr/turksatkablo.com.tr.test.js +++ b/sites/turksatkablo.com.tr/turksatkablo.com.tr.test.js @@ -1,4 +1,4 @@ -// npx epg-grabber --config=sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js --channels=sites/turksatkablo.com.tr/turksatkablo.com.tr_tr.channels.xml --days=2 --output=.gh-pages/guides/tr/turksatkablo.com.tr.epg.xml +// npx epg-grabber --config=sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js --channels=sites/turksatkablo.com.tr/turksatkablo.com.tr_tr.channels.xml --output=.gh-pages/guides/tr/turksatkablo.com.tr.epg.xml --days=2 const { parser, url } = require('./turksatkablo.com.tr.config.js') const dayjs = require('dayjs') @@ -17,15 +17,35 @@ it('can generate valid url', () => { }) it('can parse response', () => { - const result = parser({ date, channel, content }) - expect(result[0]).toMatchObject({ - start: 'Sun, 24 Oct 2021 22:15:00 GMT', - stop: 'Mon, 25 Oct 2021 00:00:00 GMT', - title: 'Ölüm Ormanı' - }) - expect(result[2]).toMatchObject({ - start: 'Mon, 25 Oct 2021 20:45:00 GMT', - stop: 'Tue, 26 Oct 2021 00:45:00 GMT', - title: 'Kaçakçı' + const result = parser({ date, channel, content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p }) + expect(result).toMatchObject([ + { + start: '2021-10-24T22:15:00.000Z', + stop: '2021-10-25T00:00:00.000Z', + title: 'Ölüm Ormanı' + }, + { + start: '2021-10-25T12:00:00.000Z', + stop: '2021-10-25T14:00:00.000Z', + title: 'Kızım' + }, + { + start: '2021-10-25T20:45:00.000Z', + stop: '2021-10-26T00:45:00.000Z', + title: 'Kaçakçı' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `` + }) + expect(result).toMatchObject([]) }) From ccedaa8b2836284b643d464fe358b1f402a61ff2 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 25 Nov 2021 00:57:29 +0300 Subject: [PATCH 2/2] Update turksatkablo.com.tr.config.js --- .../turksatkablo.com.tr.config.js | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js b/sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js index 9b6f0a8a..f811c61b 100644 --- a/sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js +++ b/sites/turksatkablo.com.tr/turksatkablo.com.tr.config.js @@ -9,26 +9,28 @@ dayjs.extend(customParseFormat) module.exports = { site: 'turksatkablo.com.tr', - ignore: true, // NOTE: server is not stable url: function ({ date }) { return `https://www.turksatkablo.com.tr/userUpload/EPG/y.json?_=${date.valueOf()}` }, parser: function ({ content, channel, date }) { - let PM = false let programs = [] const items = parseItems(content, channel) items.forEach(item => { + const prev = programs[programs.length - 1] let start = parseStart(item, date) - if (start.hour() > 11) PM = true - if (start.hour() < 12 && PM) start = start.add(1, 'd') + if (prev && start.isBefore(prev.start)) { + start = start.add(1, 'd') + date = date.add(1, 'd') + } let stop = parseStop(item, date) - if (stop.hour() > 11) PM = true - if (stop.hour() < 12 && PM) stop = stop.add(1, 'd') - + if (prev && stop.isBefore(start)) { + stop = stop.add(1, 'd') + date = date.add(1, 'd') + } programs.push({ title: item.b, - start: start.toString(), - stop: stop.toString() + start, + stop }) }) @@ -37,22 +39,24 @@ module.exports = { } function parseStart(item, date) { - const time = `${date.format('MM/DD/YYYY')} ${item.c}` + const time = `${date.format('YYYY-MM-DD')} ${item.c}` - return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Istanbul') + return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Europe/Istanbul') } function parseStop(item, date) { - const time = `${date.format('MM/DD/YYYY')} ${item.d}` + const time = `${date.format('YYYY-MM-DD')} ${item.d}` - return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Istanbul') + return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Europe/Istanbul') } function parseItems(content, channel) { - const parsed = JSON.parse(content) - const channels = parsed.k - if (!channels) return [] - const data = channels.find(c => c.x == channel.site_id) + let parsed + try { + parsed = JSON.parse(content) + } catch (e) {} + if (!parsed || !parsed.k) return [] + const data = parsed.k.find(c => c.x == channel.site_id) return data ? data.p : [] }