Update clickthecity.com.config.js
This commit is contained in:
@@ -1,19 +1,12 @@
|
|||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const { DateTime } = require('luxon')
|
||||||
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)
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'clickthecity.com',
|
site: 'clickthecity.com',
|
||||||
days: 2,
|
days: 2,
|
||||||
url({ channel }) {
|
url({ channel }) {
|
||||||
return `https://www.clickthecity.com/tv/network/${channel.site_id}`
|
return `https://www.clickthecity.com/tv/channels/?netid=${channel.site_id}`
|
||||||
},
|
},
|
||||||
request: {
|
request: {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -22,7 +15,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
data({ date }) {
|
data({ date }) {
|
||||||
const params = new URLSearchParams()
|
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')
|
params.append('optTime', '00:00:00')
|
||||||
|
|
||||||
return params
|
return params
|
||||||
@@ -30,13 +26,16 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content, date)
|
const items = parseItems(content)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const prev = programs[programs.length - 1]
|
|
||||||
const $item = cheerio.load(item)
|
const $item = cheerio.load(item)
|
||||||
const start = parseStart($item, date)
|
let start = parseStart($item, date)
|
||||||
const stop = parseStop($item, date)
|
let stop = parseStop($item, date)
|
||||||
if (stop && prev && stop.isBefore(prev.start)) return
|
if (!start || !stop) return
|
||||||
|
if (start > stop) {
|
||||||
|
stop = stop.plus({ days: 1 })
|
||||||
|
}
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title: parseTitle($item),
|
title: parseTitle($item),
|
||||||
start,
|
start,
|
||||||
@@ -48,18 +47,16 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
async channels() {
|
async channels() {
|
||||||
const html = await axios
|
const html = await axios
|
||||||
.get(`https://www.clickthecity.com/tv-networks/`)
|
.get(`https://www.clickthecity.com/tv/channels/`)
|
||||||
.then(r => r.data)
|
.then(r => r.data)
|
||||||
.catch(console.log)
|
.catch(console.log)
|
||||||
const $ = cheerio.load(html)
|
const $ = cheerio.load(html)
|
||||||
const items = $(
|
const items = $('#channels .col').toArray()
|
||||||
'#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()
|
|
||||||
|
|
||||||
return items.map(item => {
|
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 url = $(item).find('a').attr('href')
|
||||||
const [_, site_id] = url.match(/network\/(.*)\//) || [null, null]
|
const [_, site_id] = url.match(/netid=(\d+)/) || [null, null]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
site_id,
|
site_id,
|
||||||
@@ -74,32 +71,29 @@ function parseTitle($item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseStart($item, date) {
|
function parseStart($item, date) {
|
||||||
const url = $item('td > a').attr('href') || ''
|
const url = $item('td.cPrg > a').attr('href') || ''
|
||||||
const [_, time] = url.match(/starttime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
let [_, time] = url.match(/starttime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
||||||
if (!time) return null
|
if (!time) return null
|
||||||
|
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
|
||||||
|
|
||||||
return dayjs.tz(
|
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
|
||||||
`${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':')}`,
|
|
||||||
'YYYY-MM-DD h:mm A',
|
|
||||||
'Asia/Manila'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop($item, date) {
|
function parseStop($item, date) {
|
||||||
const url = $item('td > a').attr('href') || ''
|
const url = $item('td.cPrg > a').attr('href') || ''
|
||||||
const [_, time] = url.match(/endtime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
let [_, time] = url.match(/endtime=(\d{1,2}%3A\d{2}\+(AM|PM))/) || [null, null]
|
||||||
if (!time) return null
|
if (!time) return null
|
||||||
|
time = `${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':').replace('+', ' ')}`
|
||||||
|
|
||||||
return dayjs.tz(
|
return DateTime.fromFormat(time, 'yyyy-MM-dd h:mm a', { zone: 'Asia/Manila' }).toUTC()
|
||||||
`${date.format('YYYY-MM-DD')} ${time.replace('%3A', ':')}`,
|
|
||||||
'YYYY-MM-DD h:mm A',
|
|
||||||
'Asia/Manila'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, date) {
|
function parseItems(content) {
|
||||||
const $ = cheerio.load(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