diff --git a/sites/bein.com/bein.com.config.js b/sites/bein.com/bein.com.config.js index 03be9ccc..6b895eaa 100644 --- a/sites/bein.com/bein.com.config.js +++ b/sites/bein.com/bein.com.config.js @@ -1,16 +1,10 @@ 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') - -dayjs.extend(utc) -dayjs.extend(timezone) -dayjs.extend(customParseFormat) +const { DateTime } = require('luxon') module.exports = { site: 'bein.com', days: 2, + timeout: 30000, // 30 seconds request: { cache: { ttl: 60 * 60 * 1000 // 1 hour @@ -18,16 +12,18 @@ module.exports = { }, url: function ({ date, channel }) { const [category] = channel.site_id.split('#') - const postid = (channel.lang === 'ar') ? '25344' : '25356' + const postid = channel.lang === 'ar' ? '25344' : '25356' - return `https://www.bein.com/${channel.lang}/epg-ajax-template/?action=epg_fetch&category=${category}&cdate=${date.format( + return `https://www.bein.com/${ + channel.lang + }/epg-ajax-template/?action=epg_fetch&category=${category}&cdate=${date.format( 'YYYY-MM-DD' )}&language=${channel.lang.toUpperCase()}&loadindex=0&mins=00&offset=0&postid=${postid}&serviceidentity=bein.net` }, parser: function ({ content, channel, date }) { let programs = [] const items = parseItems(content, channel) - date = date.subtract(1, 'd') + date = DateTime.fromMillis(date.valueOf()).minus({ days: 1 }) items.forEach(item => { const $item = cheerio.load(item) const title = parseTitle($item) @@ -36,15 +32,15 @@ module.exports = { const prev = programs[programs.length - 1] let start = parseTime($item, date) if (prev) { - if (start.isBefore(prev.start)) { - start = start.add(1, 'd') - date = date.add(1, 'd') + if (start < prev.start) { + start = start.plus({ days: 1 }) + date = date.plus({ days: 1 }) } prev.stop = start } let stop = parseTime($item, start) - if (stop.isBefore(start)) { - stop = stop.add(1, 'd') + if (stop < start) { + stop = stop.plus({ days: 1 }) } programs.push({ title, @@ -71,9 +67,9 @@ function parseTime($item, date) { .text() .match(/^(\d{2}:\d{2})/) || [null, null] if (!time) return null - time = `${date.format('YYYY-MM-DD')} ${time}` + time = `${date.toFormat('yyyy-MM-dd')} ${time}` - return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Asia/Qatar') + return DateTime.fromFormat(time, 'yyyy-MM-dd HH:mm', { zone: 'Asia/Qatar' }).toUTC() } function parseItems(content, channel) {