-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathelcinema.com.config.js
147 lines (120 loc) · 4.06 KB
/
elcinema.com.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const cheerio = require('cheerio')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat')
require('dayjs/locale/ar')
dayjs.extend(customParseFormat)
dayjs.extend(timezone)
dayjs.extend(utc)
const headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 OPR/115.0.0.0' }
module.exports = {
site: 'elcinema.com',
days: 2,
request: { headers },
url({ channel }) {
const lang = channel.lang === 'en' ? 'en/' : '/'
return `https://elcinema.com/${lang}tvguide/${channel.site_id}/`
},
parser({ content, channel, date }) {
const programs = []
const items = parseItems(content, channel, date)
items.forEach(item => {
const start = parseStart(item, date)
const duration = parseDuration(item)
const stop = start.add(duration, 'm')
programs.push({
title: parseTitle(item),
description: parseDescription(item),
category: parseCategory(item),
image: parseImage(item),
start,
stop
})
})
return programs
},
async channels({ lang }) {
const axios = require('axios')
const data = await axios
.get(`https://elcinema.com/${lang}/tvguide/`)
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(data)
return $('.tv-line')
.map((i, el) => {
const link = $(el).find('.channel > div > div.hide-for-small-only > a')
const name = $(link).text()
const href = $(link).attr('href')
const [, site_id] = href.match(/\/(\d+)\/$/)
return {
lang,
site_id,
name
}
})
.get()
}
}
function parseImage(item) {
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')
return imgSrc || null
}
function parseCategory(item) {
const $ = cheerio.load(item)
const category = $('.row > div.columns.small-6.large-3 > ul > li:nth-child(2)').text()
return category.replace(/\(\d+\)/, '').trim() || null
}
function parseDuration(item) {
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, '') || ''
}
function parseStart(item, initDate) {
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() ||
''
time = time
.replace(/\[.*\]/, '')
.replace('مساءً', 'PM')
.replace('صباحًا', 'AM')
.trim()
time = `${initDate.format('YYYY-MM-DD')} ${time}`
return dayjs.tz(time, 'YYYY-MM-DD hh:mm A', dayjs.tz.guess())
}
function parseTitle(item) {
const $ = cheerio.load(item)
return (
$('.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
)
}
function parseDescription(item) {
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', '')
}
function parseItems(content, channel, date) {
const $ = cheerio.load(content)
const dateString = date.locale(channel.lang).format('dddd D')
const list = $('.dates')
.filter((i, el) => {
let parsedDateString = $(el).text().trim()
parsedDateString = parsedDateString.replace(/\s\s+/g, ' ')
return parsedDateString.includes(dateString)
})
.first()
.parent()
.next()
return $('.padded-half', list).toArray()
}