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

118 lines
3.1 KiB
JavaScript
Raw Normal View History

2021-11-11 14:53:34 +03:00
const cheerio = require('cheerio')
2021-08-19 19:58:30 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
2021-11-11 14:53:34 +03:00
require('dayjs/locale/ar')
2021-08-19 19:58:30 +03:00
dayjs.extend(customParseFormat)
dayjs.extend(timezone)
dayjs.extend(utc)
module.exports = {
site: 'elcinema.com',
url({ channel }) {
2021-11-10 15:07:08 +03:00
const lang = channel.lang === 'en' ? 'en/' : '/'
return `https://elcinema.com/${lang}tvguide/${channel.site_id}/`
2021-08-19 19:58:30 +03:00
},
2021-11-11 14:53:34 +03:00
parser({ content, channel, date }) {
2021-08-19 19:58:30 +03:00
const programs = []
2021-11-11 14:53:34 +03:00
const items = parseItems(content, channel, date)
2021-08-19 19:58:30 +03:00
items.forEach(item => {
const start = parseStart(item, date)
const duration = parseDuration(item)
const stop = start.add(duration, 'm')
programs.push({
2021-11-11 14:53:34 +03:00
title: parseTitle(item),
description: parseDescription(item),
category: parseCategory(item),
icon: parseIcon(item),
2022-08-28 17:16:42 +03:00
start,
stop
2021-08-19 19:58:30 +03:00
})
})
return programs
}
}
function parseIcon(item) {
2021-11-11 14:53:34 +03:00
const $ = cheerio.load(item)
const imgSrc =
$('.row > div.columns.small-3.large-1 > a > img').data('src') ||
$('.row > div.columns.small-5.large-1 > img').data('src')
2021-08-19 19:58:30 +03:00
2021-11-11 14:53:34 +03:00
return imgSrc || null
2021-08-19 19:58:30 +03:00
}
function parseCategory(item) {
2021-11-11 14:53:34 +03:00
const $ = cheerio.load(item)
const category = $('.row > div.columns.small-6.large-3 > ul > li:nth-child(2)').text()
2021-08-19 19:58:30 +03:00
2021-11-11 14:53:34 +03:00
return category.replace(/\(\d+\)/, '').trim() || null
2021-08-19 19:58:30 +03:00
}
function parseDuration(item) {
2021-11-11 14:53:34 +03:00
const $ = cheerio.load(item)
const duration =
$('.row > div.columns.small-3.large-2 > ul > li:nth-child(2) > span').text() ||
$('.row > div.columns.small-7.large-11 > ul > li:nth-child(2) > span').text()
return duration.replace(/\D/g, '') || ''
2021-08-19 19:58:30 +03:00
}
function parseStart(item, initDate) {
2021-11-11 14:53:34 +03:00
const $ = cheerio.load(item)
let time =
$('.row > div.columns.small-3.large-2 > ul > li:nth-child(1)').text() ||
$('.row > div.columns.small-7.large-11 > ul > li:nth-child(2)').text() ||
''
2021-08-19 19:58:30 +03:00
time = time
.replace(/\[.*\]/, '')
.replace('مساءً', 'PM')
.replace('صباحًا', 'AM')
.trim()
2022-08-28 17:16:42 +03:00
time = `${initDate.format('YYYY-MM-DD')} ${time}`
2021-08-19 19:58:30 +03:00
2022-08-28 17:16:42 +03:00
return dayjs.tz(time, 'YYYY-MM-DD hh:mm A', dayjs.tz.guess())
2021-08-19 19:58:30 +03:00
}
function parseTitle(item) {
2021-11-11 14:53:34 +03:00
const $ = cheerio.load(item)
2021-08-19 19:58:30 +03:00
return (
2021-11-11 14:53:34 +03:00
$('.row > div.columns.small-6.large-3 > ul > li:nth-child(1) > a').text() ||
$('.row > div.columns.small-7.large-11 > ul > li:nth-child(1)').text() ||
null
)
2021-08-19 19:58:30 +03:00
}
function parseDescription(item) {
2021-11-11 14:53:34 +03:00
const $ = cheerio.load(item)
const excerpt = $('.row > div.columns.small-12.large-6 > ul > li:nth-child(3)').text() || ''
return excerpt.replace('...اقرأ المزيد', '').replace('...Read more', '')
2021-08-19 19:58:30 +03:00
}
2021-11-11 14:53:34 +03:00
function parseItems(content, channel, date) {
const $ = cheerio.load(content)
2022-02-01 05:01:50 +03:00
2022-08-28 17:16:42 +03:00
const dateString = date.locale(channel.lang).format('dddd D')
2022-02-01 05:01:50 +03:00
2021-11-11 14:53:34 +03:00
const list = $('.dates')
.filter((i, el) => {
2022-01-12 14:02:45 +03:00
let parsedDateString = $(el).text().trim()
parsedDateString = parsedDateString.replace(/\s\s+/g, ' ')
2022-02-01 05:01:50 +03:00
2022-08-28 17:16:42 +03:00
return parsedDateString.includes(dateString)
2021-11-11 14:53:34 +03:00
})
.first()
.parent()
.next()
2021-08-19 19:58:30 +03:00
2021-11-11 14:53:34 +03:00
return $('.padded-half', list).toArray()
2021-08-19 19:58:30 +03:00
}