2025-09-28 17:55:05 +03:00
|
|
|
const cheerio = require('cheerio')
|
|
|
|
|
const axios = require('axios')
|
2026-04-09 00:02:18 +02:00
|
|
|
const dayjs = require('dayjs')
|
|
|
|
|
const utc = require('dayjs/plugin/utc')
|
|
|
|
|
const timezone = require('dayjs/plugin/timezone')
|
|
|
|
|
dayjs.extend(utc)
|
|
|
|
|
dayjs.extend(timezone)
|
2025-09-28 17:55:05 +03:00
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
site: 'tvgids.nl',
|
|
|
|
|
days: 2,
|
|
|
|
|
url: function ({ date, channel }) {
|
|
|
|
|
const path =
|
2026-04-09 00:02:18 +02:00
|
|
|
dayjs().utc().day() === dayjs(date).utc().day()
|
2025-09-28 17:55:05 +03:00
|
|
|
? ''
|
|
|
|
|
: `${date.format('DD-MM-YYYY')}/`
|
|
|
|
|
|
|
|
|
|
return `https://www.tvgids.nl/gids/${path}${channel.site_id}`
|
|
|
|
|
},
|
|
|
|
|
parser: function ({ content, date }) {
|
|
|
|
|
date = date.subtract(1, 'd')
|
|
|
|
|
let programs = []
|
|
|
|
|
const items = parseItems(content)
|
|
|
|
|
items.forEach(item => {
|
|
|
|
|
const $item = cheerio.load(item)
|
|
|
|
|
const prev = programs[programs.length - 1]
|
|
|
|
|
let start = parseStart($item, date)
|
|
|
|
|
if (prev) {
|
|
|
|
|
if (start < prev.start) {
|
2026-04-09 00:02:18 +02:00
|
|
|
start = start.add(1, 'day')
|
|
|
|
|
date = date.add(1, 'day')
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
prev.stop = start
|
|
|
|
|
}
|
2026-04-09 00:02:18 +02:00
|
|
|
const stop = start.add(30, 'minute')
|
2025-09-28 17:55:05 +03:00
|
|
|
programs.push({
|
|
|
|
|
title: parseTitle($item),
|
|
|
|
|
description: parseDescription($item),
|
|
|
|
|
image: parseImage($item),
|
|
|
|
|
start,
|
|
|
|
|
stop
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return programs
|
|
|
|
|
},
|
|
|
|
|
async channels() {
|
|
|
|
|
const data = await axios
|
|
|
|
|
.get('https://www.tvgids.nl/gids/')
|
|
|
|
|
.then(r => r.data)
|
|
|
|
|
.catch(console.log)
|
|
|
|
|
const $ = cheerio.load(data)
|
|
|
|
|
|
|
|
|
|
const channels = []
|
|
|
|
|
$('.guide__channel-logo-container').each((i, el) => {
|
|
|
|
|
channels.push({
|
|
|
|
|
site_id: $(el).find('a').attr('id'),
|
|
|
|
|
name: $(el).find('img').attr('title'),
|
|
|
|
|
lang: 'nl'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return channels
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseTitle($item) {
|
|
|
|
|
return $item('.program__title').text().trim()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseDescription($item) {
|
|
|
|
|
return $item('.program__text').text().trim()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseImage($item) {
|
|
|
|
|
return $item('.program__thumbnail').data('src')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseStart($item, date) {
|
|
|
|
|
const time = $item('.program__starttime').clone().children().remove().end().text().trim()
|
|
|
|
|
|
2026-04-09 00:02:18 +02:00
|
|
|
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Europe/Amsterdam').utc()
|
2025-09-28 17:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseItems(content) {
|
|
|
|
|
const $ = cheerio.load(content)
|
|
|
|
|
|
|
|
|
|
return $('.guide__guide .program').toArray()
|
|
|
|
|
}
|