epg/sites/tv.yandex.ru.config.js
2021-04-02 20:33:58 +03:00

46 lines
1.3 KiB
JavaScript

const jsdom = require('jsdom')
const { JSDOM } = jsdom
module.exports = {
lang: 'ru',
site: 'tv.yandex.ru',
channels: 'tv.yandex.ru.channels.xml',
output: '.gh-pages/guides/tv.yandex.ru.guide.xml',
request: {
headers: {
Cookie:
'yandexuid=8747786251615498142; Expires=Tue, 11 Mar 2031 21:29:02 GMT; Domain=yandex.ru; Path=/'
}
},
url: function ({ date, channel }) {
const [region, id] = channel.site_id.split('#')
return `https://tv.yandex.ru/${region}/channel/${id}?date=${date.format('YYYY-MM-DD')}`
},
logo: function ({ content }) {
const dom = new JSDOM(content)
const img = dom.window.document.querySelector(
'#mount > div > main > div > div > div.content__header > div > div.channel-header__title > figure > img'
)
return img ? 'https:' + img.src : null
},
parser: function ({ content }) {
const initialState = content.match(/window.__INITIAL_STATE__ = (.*);/i)
let programs = []
if (!initialState && !initialState[1]) return programs
const data = JSON.parse(initialState[1], null, 2)
if (data.channel) {
programs = data.channel.schedule.events.map(i => {
return {
title: i.title,
description: i.program.description,
start: i.start,
stop: i.finish
}
})
}
return programs
}
}