2021-09-24 12:04:16 +03:00
|
|
|
|
const dayjs = require('dayjs')
|
|
|
|
|
|
const utc = require('dayjs/plugin/utc')
|
|
|
|
|
|
const timezone = require('dayjs/plugin/timezone')
|
|
|
|
|
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
|
|
|
|
|
|
|
|
|
|
|
dayjs.extend(utc)
|
|
|
|
|
|
dayjs.extend(timezone)
|
|
|
|
|
|
dayjs.extend(customParseFormat)
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
site: 'tv.mail.ru',
|
|
|
|
|
|
url({ channel, date }) {
|
|
|
|
|
|
return `https://tv.mail.ru/ajax/channel/?region_id=70&channel_id=${
|
|
|
|
|
|
channel.site_id
|
|
|
|
|
|
}&date=${date.format('YYYY-MM-DD')}`
|
|
|
|
|
|
},
|
|
|
|
|
|
parser({ content, date }) {
|
|
|
|
|
|
const programs = []
|
|
|
|
|
|
const items = parseItems(content)
|
|
|
|
|
|
items.forEach(item => {
|
2021-11-25 00:36:49 +03:00
|
|
|
|
const prev = programs[programs.length - 1]
|
2021-09-24 12:04:16 +03:00
|
|
|
|
let start = parseStart(item, date)
|
2021-11-25 00:36:49 +03:00
|
|
|
|
if (prev) {
|
|
|
|
|
|
if (start.isBefore(prev.start)) {
|
|
|
|
|
|
start = start.add(1, 'd')
|
|
|
|
|
|
date = date.add(1, 'd')
|
|
|
|
|
|
}
|
|
|
|
|
|
prev.stop = start
|
2021-09-24 12:04:16 +03:00
|
|
|
|
}
|
2021-11-25 00:36:49 +03:00
|
|
|
|
const stop = start.add(1, 'h')
|
2021-09-24 12:04:16 +03:00
|
|
|
|
programs.push({
|
2021-11-25 00:36:49 +03:00
|
|
|
|
title: item.name,
|
|
|
|
|
|
category: parseCategory(item),
|
2021-09-24 12:04:16 +03:00
|
|
|
|
start,
|
|
|
|
|
|
stop
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return programs
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function parseStart(item, date) {
|
2021-11-25 00:36:49 +03:00
|
|
|
|
const dateString = `${date.format('YYYY-MM-DD')} ${item.start}`
|
2021-09-24 12:04:16 +03:00
|
|
|
|
|
2021-11-25 00:36:49 +03:00
|
|
|
|
return dayjs.tz(dateString, 'YYYY-MM-DD HH:mm', 'Europe/Moscow')
|
2021-09-24 12:04:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function parseCategory(item) {
|
|
|
|
|
|
const categories = {
|
|
|
|
|
|
1: 'Фильм',
|
|
|
|
|
|
2: 'Сериал',
|
|
|
|
|
|
6: 'Документальное',
|
2021-11-25 00:36:49 +03:00
|
|
|
|
7: 'Телемагазин',
|
2021-09-24 12:04:16 +03:00
|
|
|
|
8: 'Позновательное',
|
|
|
|
|
|
10: 'Другое',
|
|
|
|
|
|
14: 'ТВ-шоу',
|
|
|
|
|
|
16: 'Досуг,Хобби',
|
|
|
|
|
|
17: 'Ток-шоу',
|
|
|
|
|
|
18: 'Юмористическое',
|
2021-11-25 00:36:49 +03:00
|
|
|
|
23: 'Музыка',
|
2021-09-24 12:04:16 +03:00
|
|
|
|
24: 'Развлекательное',
|
|
|
|
|
|
25: 'Игровое',
|
|
|
|
|
|
26: 'Новости'
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-25 00:36:49 +03:00
|
|
|
|
return categories[item.category_id]
|
2021-09-24 12:04:16 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function parseItems(content) {
|
|
|
|
|
|
const json = JSON.parse(content)
|
2021-11-25 00:36:49 +03:00
|
|
|
|
if (!Array.isArray(json.schedule) || !json.schedule[0]) return []
|
|
|
|
|
|
const event = json.schedule[0].event || []
|
2021-09-24 12:04:16 +03:00
|
|
|
|
|
|
|
|
|
|
return [...event.past, ...event.current]
|
|
|
|
|
|
}
|