Update clickthecity.com.config.js
This commit is contained in:
@@ -1,19 +1,12 @@
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
const { DateTime } = require('luxon')
|
||||
|
||||
module.exports = {
|
||||
site: 'clickthecity.com',
|
||||
days: 2,
|
||||
url({ channel }) {
|
||||
return `https://www.clickthecity.com/tv/network/${channel.site_id}`
|
||||
return `https://www.clickthecity.com/tv/channels/?netid=${channel.site_id}`
|
||||
},
|
||||
request: {
|
||||
method: 'POST',
|
||||
@@ -22,7 +15,10 @@ module.exports = {
|
||||
},
|
||||
data({ date }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('optDate', dayjs(date).tz('Asia/Manila').format('YYYY-MM-DD'))
|
||||
params.append(
|
||||
'optDate',
|
||||
DateTime.fromMillis(date.valueOf()).setZone('Asia/Manila').toFormat('yyyy-MM-dd')
|
||||
)
|
||||
params.append('optTime', '00:00:00')
|
||||
|
||||
return params
|
||||
@@ -30,13 +26,16 @@ module.exports = {
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
const start = parseStart($item, date)
|
||||
const stop = parseStop($item, date)
|
||||
if (stop && prev && stop.isBefore(prev.start)) return
|
||||
let start = parseStart($item, date)
|
||||
let stop = parseStop($item, date)
|
||||
if (!start || !stop) return
|
||||
if (start > stop) {
|
||||
stop = stop.plus({ days: 1 })
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
@@ -48,18 +47,16 @@ module.exports = {
|
||||
},
|
||||
async channels() {
|
||||
const html = await axios
|
||||
.get(`https://www.clickthecity.com/tv-networks/`)
|
||||
.get(`https://www.clickthecity.com/tv/channels/`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(html)
|
||||
const items = $(
|
||||
'#main > div > div > div > section.elementor-section.elementor-top-section.elementor-element.elementor-element-a3c51b3.elementor-section-boxed.elementor-section-height-default.elementor-section-height-default > div > div > div.elementor-column.elementor-col-50.elementor-top-column.elementor-element.elementor-element-b23e0a8 > div > div > div.elementor-element.elementor-element-b46952e.elementor-posts--align-center.elementor-grid-tablet-3.elementor-grid-mobile-3.elementor-grid-4.elementor-posts--thumbnail-top.elementor-widget.elementor-widget-posts > div > div > article'
|
||||
).toArray()
|
||||
const items = $('#channels .col').toArray()
|
||||
|
||||
return items.map(item => {
|
||||
const name = $(item).find('div > h3').text().trim()
|
||||
const name = $(item).find('.card-body').text().trim()
|
||||
const url = $(item).find('a').attr('href')
|
||||
const [_, site_id] = url.match(/network\/(.*)\//) || [null, null]
|
||||
const [_, site_id] = url.match(/netid=(\d+)/) || [null, null]
|
||||
|
||||
return {
|
||||
site_id,
|
||||
@@ -74,32 +71,29 @@ function parseTitle($item) {
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const url = $item('td > a').attr('href') || ''
|
||||
const [_, time] = url.match(/starttime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
||||
const url = $item('td.cPrg > a').attr('href') || ''
|
||||
let [_, time] = url.match(/starttime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
||||
if (!time) return null
|
||||
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
|
||||
|
||||
return dayjs.tz(
|
||||
`${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':')}`,
|
||||
'YYYY-MM-DD h:mm A',
|
||||
'Asia/Manila'
|
||||
)
|
||||
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
|
||||
}
|
||||
|
||||
function parseStop($item, date) {
|
||||
const url = $item('td > a').attr('href') || ''
|
||||
const [_, time] = url.match(/endtime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
||||
const url = $item('td.cPrg > a').attr('href') || ''
|
||||
let [_, time] = url.match(/endtime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
||||
if (!time) return null
|
||||
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
|
||||
|
||||
return dayjs.tz(
|
||||
`${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':')}`,
|
||||
'YYYY-MM-DD h:mm A',
|
||||
'Asia/Manila'
|
||||
)
|
||||
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
const stringDate = date.format('MMMM DD')
|
||||
|
||||
return $(`#tvlistings > tbody > tr:not(.bg-dark)`).toArray()
|
||||
return $(`#tvlistings > tbody > tr`)
|
||||
.filter(function () {
|
||||
return $(this).find('td.cPrg').length
|
||||
})
|
||||
.toArray()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user