From 97b65304cecf0f62238d82a4ac5ad805204d82f4 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 31 Oct 2021 07:05:18 +0300 Subject: [PATCH] Update digiturk.com.tr.config.js --- .../digiturk.com.tr/digiturk.com.tr.config.js | 92 +++++++++++-------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/sites/digiturk.com.tr/digiturk.com.tr.config.js b/sites/digiturk.com.tr/digiturk.com.tr.config.js index 207e805d..2e91dc14 100644 --- a/sites/digiturk.com.tr/digiturk.com.tr.config.js +++ b/sites/digiturk.com.tr/digiturk.com.tr.config.js @@ -1,3 +1,8 @@ +const dayjs = require('dayjs') +const timezone = require('dayjs/plugin/timezone') + +dayjs.extend(timezone) + module.exports = { site: 'digiturk.com.tr', url: function ({ date, channel }) { @@ -5,46 +10,61 @@ module.exports = { channel.site_id }/${date.format('YYYY-MM-DD')}/0` }, - parser: function ({ content, date, channel }) { + parser: function ({ content, channel }) { const programs = [] - const data = JSON.parse(content) - const items = data.listings[channel.site_id] - if (!items.length) return programs - - const categories = { - '00': 'Diğer', - E0: 'Romantik Komedi', - E1: 'Aksiyon', - E4: 'Macera', - E5: 'Dram', - E6: 'Fantastik', - E7: 'Komedi', - E8: 'Korku', - EB: 'Polisiye', - EF: 'Western', - FA: 'Macera', - FB: 'Yarışma', - FC: 'Eğlence', - F0: 'Reality-Show', - F2: 'Haberler', - F4: 'Belgesel', - F6: 'Eğitim', - F7: 'Sanat ve Kültür', - F9: 'Life Style' - } - + const items = parseItems(content, channel) items.forEach(item => { - if (item.ProgramName && item.BroadcastStart && item.BroadcastEnd) { - programs.push({ - title: item.ProgramName, - description: item.LongDescription, - category: categories[item.Genre], - start: item.BroadcastStart, - stop: item.BroadcastEnd - }) - } + programs.push({ + title: item.ProgramName, + description: item.LongDescription, + category: parseCategory(item), + start: parseStart(item), + stop: parseStop(item) + }) }) return programs } } + +function parseStart(item) { + return dayjs.tz(item.BroadcastStart, 'Europe/Istanbul') +} + +function parseStop(item) { + return dayjs.tz(item.BroadcastEnd, 'Europe/Istanbul') +} + +function parseCategory(item) { + const categories = { + '00': 'Diğer', + E0: 'Romantik Komedi', + E1: 'Aksiyon', + E4: 'Macera', + E5: 'Dram', + E6: 'Fantastik', + E7: 'Komedi', + E8: 'Korku', + EB: 'Polisiye', + EF: 'Western', + FA: 'Macera', + FB: 'Yarışma', + FC: 'Eğlence', + F0: 'Reality-Show', + F2: 'Haberler', + F4: 'Belgesel', + F6: 'Eğitim', + F7: 'Sanat ve Kültür', + F9: 'Life Style' + } + + return categories[item.Genre] +} + +function parseItems(content, channel) { + const data = JSON.parse(content) + const items = data.listings[channel.site_id] + if (!items.length) return [] + + return items +}