mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Create sat.tv.config.js
This commit is contained in:
parent
297392eea2
commit
9961fa1853
1 changed files with 127 additions and 0 deletions
127
sites/sat.tv/sat.tv.config.js
Normal file
127
sites/sat.tv/sat.tv.config.js
Normal file
|
@ -0,0 +1,127 @@
|
|||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const API_ENDPOINT = 'https://sat.tv/wp-content/themes/twentytwenty-child/ajax_chaines.php'
|
||||
|
||||
module.exports = {
|
||||
site: 'sat.tv',
|
||||
days: 2,
|
||||
url: API_ENDPOINT,
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers({ channel }) {
|
||||
return {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
Cookie: `pll_language=${channel.lang}`
|
||||
}
|
||||
},
|
||||
data({ channel, date }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('dateFiltre', date.format('YYYY-MM-DD'))
|
||||
params.append('hoursFiltre', '0')
|
||||
params.append('satLineup', '38')
|
||||
params.append('satSatellite', '1')
|
||||
params.append('userDateTime', date.valueOf())
|
||||
params.append('userTimezone', 'Europe/London')
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
parser: function ({ content, date, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
items.forEach(item => {
|
||||
let $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
let duration = parseDuration($item)
|
||||
let stop = start.add(duration, 'm')
|
||||
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ lang }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('dateFiltre', dayjs().format('YYYY-MM-DD'))
|
||||
params.append('hoursFiltre', '0')
|
||||
params.append('satLineup', '38')
|
||||
params.append('satSatellite', '1')
|
||||
params.append('userDateTime', dayjs().valueOf())
|
||||
params.append('userTimezone', 'Europe/London')
|
||||
const data = await axios
|
||||
.post(API_ENDPOINT, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
Cookie: `pll_language=${lang}`
|
||||
}
|
||||
})
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
const $ = cheerio.load(data)
|
||||
const channels = $('.main-container-channels-events > .container-channel-events').toArray()
|
||||
|
||||
return channels.map(item => {
|
||||
const name = $(item).find('.channel-title').text().trim()
|
||||
return {
|
||||
lang,
|
||||
site_id: name,
|
||||
name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
const src = $item('.event-logo img:not(.no-img)').attr('src')
|
||||
|
||||
return src ? `https://sat.tv${src}` : null
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.event-data-title').text()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.event-data-desc').text()
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
let eventDataDate = $item('.event-data-date').text().trim()
|
||||
let [_, time] = eventDataDate.match(/(\d{2}:\d{2})/) || [null, null]
|
||||
if (!time) return null
|
||||
|
||||
return dayjs.utc(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm')
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
let eventDataInfo = $item('.event-data-info').text().trim()
|
||||
let [_, h, m] = eventDataInfo.match(/(\d{2})h(\d{2})/) || [null, 0, 0]
|
||||
|
||||
return parseInt(h) * 60 + parseInt(m)
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const $ = cheerio.load(content)
|
||||
const channelData = $('.main-container-channels-events > .container-channel-events')
|
||||
.filter((index, el) => {
|
||||
return $(el).find('.channel-title').text().trim() === channel.site_id
|
||||
})
|
||||
.first()
|
||||
if (!channelData) return []
|
||||
|
||||
return $(channelData).find('.container-event').toArray()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue