Update digiturk.com.tr.config.js

This commit is contained in:
Aleksandr Statciuk 2021-10-31 07:05:18 +03:00
parent 1c92a69b60
commit 97b65304ce

View file

@ -1,3 +1,8 @@
const dayjs = require('dayjs')
const timezone = require('dayjs/plugin/timezone')
dayjs.extend(timezone)
module.exports = { module.exports = {
site: 'digiturk.com.tr', site: 'digiturk.com.tr',
url: function ({ date, channel }) { url: function ({ date, channel }) {
@ -5,12 +10,32 @@ module.exports = {
channel.site_id channel.site_id
}/${date.format('YYYY-MM-DD')}/0` }/${date.format('YYYY-MM-DD')}/0`
}, },
parser: function ({ content, date, channel }) { parser: function ({ content, channel }) {
const programs = [] const programs = []
const data = JSON.parse(content) const items = parseItems(content, channel)
const items = data.listings[channel.site_id] items.forEach(item => {
if (!items.length) return programs 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 = { const categories = {
'00': 'Diğer', '00': 'Diğer',
E0: 'Romantik Komedi', E0: 'Romantik Komedi',
@ -33,18 +58,13 @@ module.exports = {
F9: 'Life Style' F9: 'Life Style'
} }
items.forEach(item => { return categories[item.Genre]
if (item.ProgramName && item.BroadcastStart && item.BroadcastEnd) { }
programs.push({
title: item.ProgramName, function parseItems(content, channel) {
description: item.LongDescription, const data = JSON.parse(content)
category: categories[item.Genre], const items = data.listings[channel.site_id]
start: item.BroadcastStart, if (!items.length) return []
stop: item.BroadcastEnd
}) return items
}
})
return programs
}
} }