Merge pull request #2089 from iptv-org/fix-clickthecity.com

Fix clickthecity.com
This commit is contained in:
Ismaël Moret 2023-06-18 22:53:48 +02:00 committed by GitHub
commit ca52e32a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1988 additions and 96 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,38 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<site site="clickthecity.com">
<channels>
<channel lang="en" xmltv_id="A2Z.ph" site_id="a2z-channel-11">A2Z Channel 11</channel>
<channel lang="en" xmltv_id="ANC.ph" site_id="anc">ANC</channel>
<channel lang="en" xmltv_id="AnimaxPhilippines.ph" site_id="animax">Animax</channel>
<channel lang="en" xmltv_id="AXNPhilippines.ph" site_id="axn">AXN</channel>
<channel lang="en" xmltv_id="CelestialMoviesPinoy.hk" site_id="celestial-movies-pinoy">Celestial Movies Pinoy</channel>
<channel lang="en" xmltv_id="CinemaOneGlobal.ph" site_id="cinema-one">Cinema One</channel>
<channel lang="en" xmltv_id="CinemaxAsia.sg" site_id="cinemax">Cinemax</channel>
<channel lang="en" xmltv_id="CNNPhilippines.ph" site_id="cnn-philippines">CNN Philippines</channel>
<channel lang="en" xmltv_id="CrimePlusInvestigationAsia.sg" site_id="crime-investigation">Crime &amp; Investigation</channel>
<channel lang="en" xmltv_id="IBC13.ph" site_id="ibc-tv-13">IBC 13</channel>
<channel lang="en" xmltv_id="ETC.ph" site_id="etc">ETC</channel>
<channel lang="en" xmltv_id="GEM.sg" site_id="gem">GEM</channel>
<channel lang="en" xmltv_id="GMANewsTV.ph" site_id="gma-news-tv">GMA News TV</channel>
<channel lang="en" xmltv_id="GMATV.ph" site_id="gma">GMA</channel>
<channel lang="en" xmltv_id="GTV.ph" site_id="gtv">GTV</channel>
<channel lang="en" xmltv_id="HBOAsia.sg" site_id="hbo-asia">HBO Asia</channel>
<channel lang="en" xmltv_id="HistoryPhilippines.ph" site_id="history">History</channel>
<channel lang="en" xmltv_id="JeepneyTV.ph" site_id="jeepney-tv">Jeepney TV</channel>
<channel lang="en" xmltv_id="KapamilyaChannel.ph" site_id="kapamilya-channel">Kapamilya Channel</channel>
<channel lang="en" xmltv_id="KMoviesPinoy.ph" site_id="k-movies-pinoy">K Movies Pinoy</channel>
<channel lang="en" xmltv_id="Liga.ph" site_id="liga">Liga</channel>
<channel lang="en" xmltv_id="MetroChannel.ph" site_id="metro-channel">Metro Channel</channel>
<channel lang="en" xmltv_id="MyxPhilippines.ph" site_id="myx">MYX</channel>
<channel lang="en" xmltv_id="NationalGeographicPhilippines.ph" site_id="national-geographic">National Geographic</channel>
<channel lang="en" xmltv_id="Net25.ph" site_id="net-25">Net 25</channel>
<channel lang="en" xmltv_id="NickelodeonPhilippines.ph" site_id="nickelodeon">Nickelodeon</channel>
<channel lang="en" xmltv_id="PBO.ph" site_id="pbo">PBO</channel>
<channel lang="en" xmltv_id="PTV.ph" site_id="ptv">PTV</channel>
<channel lang="en" xmltv_id="ROCKEntertainment.sg" site_id="rock-entertainment">Rock Entertainment</channel>
<channel lang="en" xmltv_id="ROCKExtreme.sg" site_id="rock-extreme">Rock Extreme</channel>
<channel lang="en" xmltv_id="TeleNovelaChannel.ph" site_id="telenovela-channel">TeleNovela Channel</channel>
<channel lang="en" xmltv_id="TV5.ph" site_id="tv5">TV5</channel>
<channel lang="en" xmltv_id="VivaCinema.ph" site_id="viva-tv">VIVA Cinema</channel>
<!-- <channel lang="en" xmltv_id="" site_id="137">Solar Flix</channel> -->
<!-- <channel lang="en" xmltv_id="" site_id="163">Crime Investigation</channel> -->
<channel lang="en" xmltv_id="A2Z.ph" site_id="189">a2z Channel 11</channel>
<channel lang="en" xmltv_id="ANC.ph" site_id="13">ANC</channel>
<channel lang="en" xmltv_id="AnimaxPhilippines.ph" site_id="168">Animax</channel>
<channel lang="en" xmltv_id="AXNPhilippines.ph" site_id="126">AXN</channel>
<channel lang="en" xmltv_id="CelestialMoviesPinoy.hk" site_id="181">Celestial Movies Pinoy</channel>
<channel lang="en" xmltv_id="CinemaOneGlobal.ph" site_id="82">Cinema One</channel>
<channel lang="en" xmltv_id="CinemaxAsia.sg" site_id="30">Cinemax</channel>
<channel lang="en" xmltv_id="CNNPhilippines.ph" site_id="177">CNN Philippines</channel>
<channel lang="en" xmltv_id="GEM.sg" site_id="183">GEM</channel>
<channel lang="en" xmltv_id="GMATV.ph" site_id="2">GMA</channel>
<channel lang="en" xmltv_id="GTV.ph" site_id="143">GTV</channel>
<channel lang="en" xmltv_id="HBOAsia.sg" site_id="8">HBO</channel>
<channel lang="en" xmltv_id="HistoryPhilippines.ph" site_id="162">History</channel>
<channel lang="en" xmltv_id="IBC13.ph" site_id="7">IBC TV 13</channel>
<channel lang="en" xmltv_id="JeepneyTV.ph" site_id="179">Jeepney TV</channel>
<channel lang="en" xmltv_id="KapamilyaChannel.ph" site_id="184">Kapamilya Channel</channel>
<channel lang="en" xmltv_id="KMoviesPinoy.ph" site_id="182">K-Movies Pinoy</channel>
<channel lang="en" xmltv_id="Liga.ph" site_id="188">Liga</channel>
<channel lang="en" xmltv_id="MetroChannel.ph" site_id="66">Metro Channel</channel>
<channel lang="en" xmltv_id="MyxPhilippines.ph" site_id="139">MYX</channel>
<channel lang="en" xmltv_id="NationalGeographicPhilippines.ph" site_id="75">National Geographic</channel>
<channel lang="en" xmltv_id="Net25.ph" site_id="133">Net 25</channel>
<channel lang="en" xmltv_id="NickelodeonPhilippines.ph" site_id="78">Nickelodeon</channel>
<channel lang="en" xmltv_id="PBO.ph" site_id="142">PBO</channel>
<channel lang="en" xmltv_id="PTV.ph" site_id="4">PTV</channel>
<channel lang="en" xmltv_id="ROCKEntertainment.sg" site_id="180">Rock Entertainment</channel>
<channel lang="en" xmltv_id="ROCKExtreme.sg" site_id="186">Rock Extreme</channel>
<channel lang="en" xmltv_id="TagalizedMovieChannel.ph" site_id="178">Tagalized Movie Channel</channel>
<channel lang="en" xmltv_id="TeleNovelaChannel.ph" site_id="160">Telenovela Channel</channel>
<channel lang="en" xmltv_id="TV5.ph" site_id="5">TV5</channel>
<channel lang="en" xmltv_id="VivaCinema.ph" site_id="155">VIVA Cinema</channel>
</channels>
</site>

View File

@ -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()
}

View File

@ -1,21 +1,23 @@
// npm run channels:parse -- --config=./sites/clickthecity.com/clickthecity.com.config.js --output=./sites/clickthecity.com/clickthecity.com.channels.xml
// npx epg-grabber --config=sites/clickthecity.com/clickthecity.com.config.js --channels=sites/clickthecity.com/clickthecity.com.channels.xml --output=guide.xml --days=2
// npx epg-grabber --config=sites/clickthecity.com/clickthecity.com.config.js --channels=sites/clickthecity.com/clickthecity.com.channels.xml --output=guide.xml
const { parser, url, request } = require('./clickthecity.com.config.js')
const fs = require('fs')
const path = require('path')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2022-03-05', 'YYYY-MM-DD').startOf('d')
const date = dayjs.utc('2023-06-12', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'tv5',
site_id: '5',
xmltv_id: 'TV5.ph'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe('https://www.clickthecity.com/tv/network/tv5')
expect(url({ channel })).toBe('https://www.clickthecity.com/tv/channels/?netid=5')
})
it('can generate valid request method', () => {
@ -30,36 +32,31 @@ it('can generate valid request headers', () => {
it('can generate valid request data', () => {
const result = request.data({ date })
expect(result.get('optDate')).toBe('2022-03-05')
expect(result.get('optDate')).toBe('2023-06-12')
expect(result.get('optTime')).toBe('00:00:00')
})
it('can parse response', () => {
const content = `<!doctypehtml><html class=html lang=en-US prefix="og: https://ogp.me/ns#"><body class="aa-prefix-click- content-right-sidebar default-breakpoint dropdown-mobile elementor-default elementor-kit-114471 elementor-page-62235 elementor-template-full-width has-breadcrumbs has-sidebar network-template-default oceanwp-theme page-header-disabled postid-62183 single single-network wp-custom-logo wp-embed-responsive"itemscope=itemscope itemtype=https://schema.org/WebPage><div class="clr site"id=outer-wrap><a class="screen-reader-text skip-link"href=#main>Skip to content</a><div class=clr id=wrap><main class="clr site-main"id=main role=main><div class="category-tv elementor elementor-62235 elementor-location-single entry has-media has-post-thumbnail hentry network post-62183 status-publish type-network"data-elementor-id=62235 data-elementor-settings=[] data-elementor-type=single><div class=elementor-section-wrap><section class="elementor-element elementor-section-height-default elementor-section-height-default elementor-element-9dc0219 elementor-section elementor-section-boxed elementor-top-section"data-element_type=section data-id=9dc0219><div class="elementor-column-gap-default elementor-container"><div class=elementor-row><div class="elementor-element elementor-col-50 elementor-column elementor-element-b6192ca elementor-top-column"data-element_type=column data-id=b6192ca data-settings='{"background_background":"classic"}'><div class="elementor-column-wrap elementor-element-populated"><div class=elementor-widget-wrap><div class="elementor-element elementor-element-c4989ed elementor-widget elementor-widget-shortcode"data-element_type=widget data-id=c4989ed data-widget_type=shortcode.default><div class=elementor-widget-container><div class=elementor-shortcode><form class=form-inline id=frmTV method=POST name=frmTV role=form><div class=w-100><table class="card d-table overflow-hidden rounded shadow table table-bordered table-striped"id=tvlistings><tr class="bg-dark text-light"><th colspan=2>Tomorrow, March 05<tr><td class=cTme width=100>12:00 am<td class="cPrg showlnkcon"><a class="font-weight-bold text-dark"href="/tv/tvshow.php?id=109793&amp;starttime=12%3A00+AM&amp;endtime=1%3A00+AM"name=0>CCF Worship Service</a><tr><td class=cTme width=100>06:30 am<td class="cPrg showlnkcon"><a class="font-weight-bold text-dark"href="/tv/tvshow.php?id=94697&amp;starttime=6%3A30+AM&amp;endtime=7%3A30+AM"name=1>Word Of God</a><tr class="bg-dark text-light"><th colspan="2">Tonight, March 05</th></tr><tr> <td class="cTme">08:00 pm</td><td class="cPrg showlnkcon"> <a class="font-weight-bold text-dark" name="10" href="/tv/tvshow.php?id=113538&amp;starttime=8%3A00+PM&amp;endtime=9%3A00+PM">Rated Korina S2 </a> </td></tr><tr class="bg-dark text-light"><th colspan=2>Sunday, March 06<tr><td class=cTme>12:00 am<td class="cPrg showlnkcon"><a class="font-weight-bold text-dark"href="/tv/tvshow.php?id=114754&amp;starttime=12%3A00+AM&amp;endtime=3%3A30+AM"name=13>2021 PBA Governor's Cup</a></table></div></form></div></div></div></div></div></div></div></div></section></div></div></main></div></div>`
const result = parser({ content, date }).map(p => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const results = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-03-04T16:00:00.000Z',
stop: '2022-03-04T17:00:00.000Z',
title: `CCF Worship Service`
},
{
start: '2022-03-04T22:30:00.000Z',
stop: '2022-03-04T23:30:00.000Z',
expect(results.length).toBe(20)
expect(results[0]).toMatchObject({
start: '2023-06-11T21:00:00.000Z',
stop: '2023-06-11T22:00:00.000Z',
title: `Word Of God`
},
{
start: '2022-03-05T12:00:00.000Z',
stop: '2022-03-05T13:00:00.000Z',
title: `Rated Korina S2`
}
])
})
expect(results[19]).toMatchObject({
start: '2023-06-12T15:30:00.000Z',
stop: '2023-06-12T16:00:00.000Z',
title: `La Suerte De Loli`
})
})
it('can handle empty guide', () => {