Files
epg/sites/clickthecity.com/clickthecity.com.config.js

100 lines
2.6 KiB
JavaScript
Raw Normal View History

2022-03-04 23:25:57 +03:00
const cheerio = require('cheerio')
const axios = require('axios')
2023-06-12 02:54:41 +03:00
const { DateTime } = require('luxon')
2022-03-04 23:25:57 +03:00
module.exports = {
site: 'clickthecity.com',
2023-01-10 12:40:01 +03:00
days: 2,
2022-03-04 23:25:57 +03:00
url({ channel }) {
2023-06-12 02:54:41 +03:00
return `https://www.clickthecity.com/tv/channels/?netid=${channel.site_id}`
2022-03-04 23:25:57 +03:00
},
request: {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded'
},
data({ date }) {
const params = new URLSearchParams()
2023-06-12 02:54:41 +03:00
params.append(
'optDate',
DateTime.fromMillis(date.valueOf()).setZone('Asia/Manila').toFormat('yyyy-MM-dd')
)
2022-03-04 23:25:57 +03:00
params.append('optTime', '00:00:00')
return params
}
},
parser({ content, date }) {
const programs = []
2023-06-12 02:54:41 +03:00
const items = parseItems(content)
2022-03-04 23:25:57 +03:00
items.forEach(item => {
const $item = cheerio.load(item)
2023-06-12 02:54:41 +03:00
let start = parseStart($item, date)
let stop = parseStop($item, date)
if (!start || !stop) return
if (start > stop) {
stop = stop.plus({ days: 1 })
}
2022-03-04 23:25:57 +03:00
programs.push({
title: parseTitle($item),
start,
stop
})
})
return programs
},
async channels() {
const html = await axios
2023-10-02 06:35:33 +03:00
.get('https://www.clickthecity.com/tv/channels/')
2022-03-04 23:25:57 +03:00
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(html)
2023-06-12 02:54:41 +03:00
const items = $('#channels .col').toArray()
2022-03-04 23:25:57 +03:00
return items.map(item => {
2023-06-12 02:54:41 +03:00
const name = $(item).find('.card-body').text().trim()
2022-03-04 23:25:57 +03:00
const url = $(item).find('a').attr('href')
2023-10-02 06:35:33 +03:00
const [, site_id] = url.match(/netid=(\d+)/) || [null, null]
2022-03-04 23:25:57 +03:00
return {
site_id,
name
}
})
}
}
function parseTitle($item) {
return $item('td > a').text().trim()
}
function parseStart($item, date) {
2023-06-12 02:54:41 +03:00
const url = $item('td.cPrg > a').attr('href') || ''
2023-10-02 06:35:33 +03:00
let [, time] = url.match(/starttime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
2022-03-04 23:25:57 +03:00
if (!time) return null
2023-06-12 02:54:41 +03:00
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
2022-03-04 23:25:57 +03:00
2023-06-12 02:54:41 +03:00
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
2022-03-04 23:25:57 +03:00
}
function parseStop($item, date) {
2023-06-12 02:54:41 +03:00
const url = $item('td.cPrg > a').attr('href') || ''
2023-10-02 06:35:33 +03:00
let [, time] = url.match(/endtime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
2022-03-04 23:25:57 +03:00
if (!time) return null
2023-06-12 02:54:41 +03:00
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
2022-03-04 23:25:57 +03:00
2023-06-12 02:54:41 +03:00
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
2022-03-04 23:25:57 +03:00
}
2023-06-12 02:54:41 +03:00
function parseItems(content) {
2022-03-04 23:25:57 +03:00
const $ = cheerio.load(content)
2023-10-02 06:35:33 +03:00
return $('#tvlistings > tbody > tr')
2023-06-12 02:54:41 +03:00
.filter(function () {
return $(this).find('td.cPrg').length
})
.toArray()
2022-03-04 23:25:57 +03:00
}