Move sites into a folders

This commit is contained in:
Aleksandr Statciuk
2021-10-15 03:31:13 +03:00
parent b92feaf2b6
commit 6955909ee4
97 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
require('dayjs/locale/ca')
dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
module.exports = {
site: 'andorradifusio.ad',
url({ channel }) {
return `https://www.andorradifusio.ad/programacio/${channel.site_id}`
},
parser({ content, date }) {
let PM = false
const programs = []
const items = parseItems(content, date)
items.forEach(item => {
const title = item.title
let start = parseStart(item, date)
if (start.hour() > 11) PM = true
if (start.hour() < 12 && PM) start = start.add(1, 'd')
const stop = start.add(1, 'h')
if (programs.length) {
programs[programs.length - 1].stop = start
}
programs.push({
title,
start,
stop
})
})
return programs
}
}
function parseStart(item, date) {
time = `${date.format('MM/DD/YYYY')} ${item.time}`
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Madrid')
}
function parseItems(content, date) {
const $ = cheerio.load(content)
const dayOfWeek = dayjs(date).locale('ca').format('dddd').toLowerCase()
const column = $('.programacio-dia > h3')
.filter((i, el) => $(el).text().startsWith(dayOfWeek))
.first()
.parent()
const items = []
const titles = column.find(`p`).toArray()
column.find(`h4`).each((i, time) => {
items.push({
time: $(time).text(),
title: $(titles[i]).text()
})
})
return items
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="andorradifusio.ad">
<channels>
<channel lang="ca" xmltv_id="AndorraTV.ad" site_id="atv">Andorra TV</channel>
</channels>
</site>