mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge branch 'master' into freearhey-patch-5
This commit is contained in:
commit
dfdac39bb4
2 changed files with 46 additions and 41 deletions
|
@ -9,9 +9,14 @@ 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/' : '/'
|
||||
|
||||
|
|
|
@ -2,13 +2,11 @@ const axios = require('axios')
|
|||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
const fetch = require('node-fetch')
|
||||
const { upperCase } = require('lodash')
|
||||
|
||||
let X_CSRFTOKEN
|
||||
let COOKIE
|
||||
const cookiesToExtract = ['JSESSIONID', 'CSESSIONID', 'CSRFSESSION']
|
||||
const extractedCookies = {}
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
@ -166,11 +164,15 @@ function parseItems(content) {
|
|||
return data.playbilllist
|
||||
}
|
||||
|
||||
// Function to try to fetch COOKIE and X_CSRFTOKEN
|
||||
function fetchCookieAndToken() {
|
||||
return fetch(
|
||||
'https://api.prod.sngtv.magentatv.de/EPG/JSON/Authenticate?SID=firstup&T=Windows_chrome_118',
|
||||
{
|
||||
async function fetchCookieAndToken() {
|
||||
// Only fetch the cookies and csrfToken if they are not already set
|
||||
if (X_CSRFTOKEN && COOKIE) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.request({
|
||||
url: 'https://api.prod.sngtv.magentatv.de/EPG/JSON/Authenticate',
|
||||
headers: {
|
||||
accept: 'application/json, text/javascript, */*; q=0.01',
|
||||
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
|
@ -181,43 +183,41 @@ function fetchCookieAndToken() {
|
|||
Referer: 'https://web.magentatv.de/',
|
||||
'Referrer-Policy': 'strict-origin-when-cross-origin'
|
||||
},
|
||||
body: '{"terminalid":"00:00:00:00:00:00","mac":"00:00:00:00:00:00","terminaltype":"WEBTV","utcEnable":1,"timezone":"Etc/GMT0","userType":3,"terminalvendor":"Unknown"}',
|
||||
method: 'POST'
|
||||
}
|
||||
)
|
||||
.then(response => {
|
||||
// Check if the response status is OK (2xx)
|
||||
if (!response.ok) {
|
||||
throw new Error('HTTP request failed')
|
||||
}
|
||||
params: {
|
||||
SID: 'firstup',
|
||||
T: 'Windows_chrome_118'
|
||||
},
|
||||
method: 'POST',
|
||||
data: '{"terminalid":"00:00:00:00:00:00","mac":"00:00:00:00:00:00","terminaltype":"WEBTV","utcEnable":1,"timezone":"Etc/GMT0","userType":3,"terminalvendor":"Unknown"}',
|
||||
})
|
||||
|
||||
// Extract the set-cookie header
|
||||
const setCookieHeader = response.headers.raw()['set-cookie']
|
||||
|
||||
// Extract the cookies specified in cookiesToExtract
|
||||
const setCookieHeader = response.headers['set-cookie'] || []
|
||||
let extractedCookies = []
|
||||
cookiesToExtract.forEach(cookieName => {
|
||||
const regex = new RegExp(`${cookieName}=(.+?)(;|$)`)
|
||||
const match = setCookieHeader.find(header => regex.test(header))
|
||||
|
||||
if (match) {
|
||||
const cookieValue = regex.exec(match)[1]
|
||||
extractedCookies[cookieName] = cookieValue
|
||||
const cookieString = regex.exec(match)[0]
|
||||
extractedCookies.push(cookieString)
|
||||
}
|
||||
})
|
||||
|
||||
return response.json()
|
||||
})
|
||||
.then(data => {
|
||||
if (data.csrfToken) {
|
||||
X_CSRFTOKEN = data.csrfToken
|
||||
COOKIE = `JSESSIONID=${extractedCookies.JSESSIONID}; CSESSIONID=${extractedCookies.CSESSIONID}; CSRFSESSION=${extractedCookies.CSRFSESSION}; JSESSIONID=${extractedCookies.JSESSIONID};`
|
||||
} else {
|
||||
|
||||
// check if we recieved a csrfToken only then store the values
|
||||
if (!response.data.csrfToken) {
|
||||
console.log('csrfToken not found in the response.')
|
||||
return
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
X_CSRFTOKEN = response.data.csrfToken
|
||||
COOKIE = extractedCookies.join(' ')
|
||||
|
||||
} catch(error) {
|
||||
console.error(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function setHeaders() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue