mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Update m.tv.sms.cz.config.js
This commit is contained in:
parent
22b197d3f4
commit
32fdf396df
1 changed files with 47 additions and 33 deletions
|
@ -3,13 +3,14 @@ const iconv = require('iconv-lite')
|
|||
const { JSDOM } = jsdom
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
var customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
var timezone = require('dayjs/plugin/timezone')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
let PM = false
|
||||
module.exports = {
|
||||
lang: 'cs',
|
||||
site: 'm.tv.sms.cz',
|
||||
|
@ -28,40 +29,53 @@ module.exports = {
|
|||
},
|
||||
parser: function ({ buffer, date }) {
|
||||
const programs = []
|
||||
const string = iconv.decode(buffer, 'win1250')
|
||||
const dom = new JSDOM(string)
|
||||
const items = dom.window.document.querySelectorAll('#obsah > div > div.porady > div.porad')
|
||||
const items = parseItems(buffer)
|
||||
items.forEach((item, i) => {
|
||||
const time = (item.querySelector('div > span') || { textContent: '' }).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
const title = (item.querySelector('a > div') || { textContent: '' }).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
const description = (item.querySelector('a > div.detail') || { textContent: '' }).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
|
||||
if (time && title) {
|
||||
let local = dayjs.utc(time, 'HH.mm').date(date.date()).month(date.month()).year(date.year())
|
||||
|
||||
if (local.hour() <= 6 && i > items.length / 2) {
|
||||
local = local.date(local.date() + 1)
|
||||
}
|
||||
const start = dayjs.tz(local.toString(), 'Europe/Prague').toString()
|
||||
|
||||
if (programs.length && !programs[programs.length - 1].stop) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
description,
|
||||
start
|
||||
})
|
||||
const title = parseTitle(item)
|
||||
const description = parseDescription(item)
|
||||
const start = parseStart(item, date)
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
const stop = parseStop(item, date)
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
description,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
return date.tz('Europe/Prague').endOf('d').add(6, 'h')
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let time = (item.querySelector('div > span') || { textContent: '' }).textContent.trim()
|
||||
|
||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
||||
|
||||
return dayjs.tz(time, 'MM/DD/YYYY HH.mm', 'Europe/Prague')
|
||||
}
|
||||
|
||||
function parseDescription(item) {
|
||||
return (item.querySelector('a > div.detail') || { textContent: '' }).textContent.trim()
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return (item.querySelector('a > div') || { textContent: '' }).textContent.trim()
|
||||
}
|
||||
|
||||
function parseItems(buffer) {
|
||||
const string = iconv.decode(buffer, 'win1250')
|
||||
const dom = new JSDOM(string)
|
||||
|
||||
return dom.window.document.querySelectorAll('#obsah > div > div.porady > div.porad')
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue