mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update elcinema.com.config.js
This commit is contained in:
parent
751bea9596
commit
fe5e5a23a7
1 changed files with 52 additions and 64 deletions
|
@ -1,9 +1,9 @@
|
||||||
const jsdom = require('jsdom')
|
const cheerio = require('cheerio')
|
||||||
const { JSDOM } = jsdom
|
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
require('dayjs/locale/ar')
|
||||||
|
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
@ -17,31 +17,25 @@ module.exports = {
|
||||||
return `https://elcinema.com/${lang}tvguide/${channel.site_id}/`
|
return `https://elcinema.com/${lang}tvguide/${channel.site_id}/`
|
||||||
},
|
},
|
||||||
logo({ content }) {
|
logo({ content }) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const img = dom.window.document.querySelector('.intro-box > .row > div.columns.large-2 > img')
|
const imgSrc = $('.intro-box > .row > div.columns.large-2 > img').attr('src')
|
||||||
|
|
||||||
return img.src || null
|
return imgSrc || null
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, channel, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
|
const items = parseItems(content, channel, date)
|
||||||
const items = parseItems(content, date)
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
|
||||||
const description = parseDescription(item)
|
|
||||||
const category = parseCategory(item)
|
|
||||||
const icon = parseIcon(item)
|
|
||||||
const start = parseStart(item, date)
|
const start = parseStart(item, date)
|
||||||
const duration = parseDuration(item)
|
const duration = parseDuration(item)
|
||||||
const stop = start.add(duration, 'm')
|
const stop = start.add(duration, 'm')
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title: parseTitle(item),
|
||||||
description,
|
description: parseDescription(item),
|
||||||
category,
|
category: parseCategory(item),
|
||||||
icon,
|
icon: parseIcon(item),
|
||||||
start,
|
start: start.toJSON(),
|
||||||
stop
|
stop: stop.toJSON()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -50,41 +44,36 @@ module.exports = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseIcon(item) {
|
function parseIcon(item) {
|
||||||
const img =
|
const $ = cheerio.load(item)
|
||||||
item.querySelector('.row > div.columns.small-3.large-1 > a > img') ||
|
const imgSrc =
|
||||||
item.querySelector('.row > div.columns.small-5.large-1 > img')
|
$('.row > div.columns.small-3.large-1 > a > img').data('src') ||
|
||||||
|
$('.row > div.columns.small-5.large-1 > img').data('src')
|
||||||
|
|
||||||
return img.dataset.src || null
|
return imgSrc || null
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseCategory(item) {
|
function parseCategory(item) {
|
||||||
const category = (
|
const $ = cheerio.load(item)
|
||||||
item.querySelector('.row > div.columns.small-6.large-3 > ul > li:nth-child(2)') || {
|
const category = $('.row > div.columns.small-6.large-3 > ul > li:nth-child(2)').text()
|
||||||
textContent: ''
|
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
|
|
||||||
return category.replace(/\(\d+\)/, '').trim()
|
return category.replace(/\(\d+\)/, '').trim() || null
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDuration(item) {
|
function parseDuration(item) {
|
||||||
const duration = (
|
const $ = cheerio.load(item)
|
||||||
item.querySelector('.row > div.columns.small-3.large-2 > ul > li:nth-child(2) > span') ||
|
const duration =
|
||||||
item.querySelector('.row > div.columns.small-7.large-11 > ul > li:nth-child(2) > span') || {
|
$('.row > div.columns.small-3.large-2 > ul > li:nth-child(2) > span').text() ||
|
||||||
textContent: ''
|
$('.row > div.columns.small-7.large-11 > ul > li:nth-child(2) > span').text()
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
|
|
||||||
return duration.replace(/\D/g, '')
|
return duration.replace(/\D/g, '') || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, initDate) {
|
function parseStart(item, initDate) {
|
||||||
let time = (
|
const $ = cheerio.load(item)
|
||||||
item.querySelector('.row > div.columns.small-3.large-2 > ul > li:nth-child(1)') ||
|
let time =
|
||||||
item.querySelector('.row > div.columns.small-7.large-11 > ul > li:nth-child(2)') || {
|
$('.row > div.columns.small-3.large-2 > ul > li:nth-child(1)').text() ||
|
||||||
textContent: ''
|
$('.row > div.columns.small-7.large-11 > ul > li:nth-child(2)').text() ||
|
||||||
}
|
''
|
||||||
).textContent
|
|
||||||
|
|
||||||
time = time
|
time = time
|
||||||
.replace(/\[.*\]/, '')
|
.replace(/\[.*\]/, '')
|
||||||
|
@ -94,37 +83,36 @@ function parseStart(item, initDate) {
|
||||||
|
|
||||||
time = `${initDate.format('DD/MM/YYYY')} ${time}`
|
time = `${initDate.format('DD/MM/YYYY')} ${time}`
|
||||||
|
|
||||||
return dayjs.tz(time, 'DD/MM/YYYY H:mm A', 'Africa/Algiers')
|
return dayjs.tz(time, 'DD/MM/YYYY H:mm A', 'Africa/Cairo')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
function parseTitle(item) {
|
||||||
|
const $ = cheerio.load(item)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
item.querySelector('.row > div.columns.small-6.large-3 > ul > li:nth-child(1) > a') ||
|
$('.row > div.columns.small-6.large-3 > ul > li:nth-child(1) > a').text() ||
|
||||||
item.querySelector('.row > div.columns.small-7.large-11 > ul > li:nth-child(1)') || {
|
$('.row > div.columns.small-7.large-11 > ul > li:nth-child(1)').text() ||
|
||||||
textContent: ''
|
null
|
||||||
}
|
)
|
||||||
).textContent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDescription(item) {
|
function parseDescription(item) {
|
||||||
const excerpt = (
|
const $ = cheerio.load(item)
|
||||||
item.querySelector('.row > div.columns.small-12.large-6 > ul > li:nth-child(3)') || {
|
const excerpt = $('.row > div.columns.small-12.large-6 > ul > li:nth-child(3)').text() || ''
|
||||||
textContent: ''
|
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
const desc = (
|
|
||||||
item.querySelector('.row > div.columns.small-12.large-6 > ul > li:nth-child(3) > .hide') || {
|
|
||||||
textContent: ''
|
|
||||||
}
|
|
||||||
).textContent
|
|
||||||
|
|
||||||
return excerpt.replace('...اقرأ المزيد', '').replace('...Read more', '') + desc
|
return excerpt.replace('...اقرأ المزيد', '').replace('...Read more', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, date) {
|
function parseItems(content, channel, date) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const diff = date.diff(dayjs().startOf('d'), 'd')
|
const dateString = date.locale(channel.lang).format('dddd D MMMM')
|
||||||
const listNum = (diff + 1) * 2
|
const list = $('.dates')
|
||||||
|
.filter((i, el) => {
|
||||||
|
return $(el).text().trim() === dateString
|
||||||
|
})
|
||||||
|
.first()
|
||||||
|
.parent()
|
||||||
|
.next()
|
||||||
|
|
||||||
return dom.window.document.querySelectorAll(`.tvgrid > div:nth-child(${listNum}) > .padded-half`)
|
return $('.padded-half', list).toArray()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue