mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #2194 from Sicilykill/issue_2193
Update magentatv.de.config.js
This commit is contained in:
commit
85263c71f0
2 changed files with 90 additions and 23 deletions
|
@ -2,10 +2,13 @@ const axios = require('axios')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
const X_CSRFTOKEN = '6da89c6b271b8c0fabd133b2722ee9e1ddba9564010af8e3'
|
|
||||||
const COOKIE =
|
let X_CSRFTOKEN;
|
||||||
'JSESSIONID=CDE7D4E5E7C05900BBEAD7DF8FB1DBB0; CSESSIONID=D36E1BF69875141F63B3240B86AFB9B7; CSRFSESSION=6da89c6b271b8c0fabd133b2722ee9e1ddba9564010af8e3; JSESSIONID=CDE7D4E5E7C05900BBEAD7DF8FB1DBB0'
|
let COOKIE;
|
||||||
|
const cookiesToExtract = ['JSESSIONID', 'CSESSIONID', 'CSRFSESSION'];
|
||||||
|
const extractedCookies = {};
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
@ -16,10 +19,8 @@ module.exports = {
|
||||||
url: 'https://api.prod.sngtv.magentatv.de/EPG/JSON/PlayBillList',
|
url: 'https://api.prod.sngtv.magentatv.de/EPG/JSON/PlayBillList',
|
||||||
request: {
|
request: {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: function () {
|
||||||
X_CSRFToken: X_CSRFTOKEN,
|
return setHeaders();
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Cookie: COOKIE
|
|
||||||
},
|
},
|
||||||
|
|
||||||
data({ channel, date }) {
|
data({ channel, date }) {
|
||||||
|
@ -97,6 +98,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function parseCategory(item) {
|
function parseCategory(item) {
|
||||||
return item.genres
|
return item.genres
|
||||||
? item.genres
|
? item.genres
|
||||||
|
@ -113,7 +115,7 @@ function parseIcon(item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item) {
|
function parseStart(item) {
|
||||||
return dayjs(item.starttime, 'YYYY-MM-DD HH:mm:ss')
|
return dayjs.utc(item.starttime, 'YYYY-MM-DD HH:mm:ss')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStop(item) {
|
function parseStop(item) {
|
||||||
|
@ -126,3 +128,64 @@ function parseItems(content) {
|
||||||
|
|
||||||
return data.playbilllist
|
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", {
|
||||||
|
"headers": {
|
||||||
|
"accept": "application/json, text/javascript, */*; q=0.01",
|
||||||
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
||||||
|
"sec-fetch-dest": "empty",
|
||||||
|
"sec-fetch-mode": "cors",
|
||||||
|
"sec-fetch-site": "same-origin",
|
||||||
|
"x-requested-with": "XMLHttpRequest",
|
||||||
|
"Referer": "https://api.prod.sngtv.magentatv.de/EPG/",
|
||||||
|
"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');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the set-cookie header
|
||||||
|
const setCookieHeader = response.headers.raw()['set-cookie'];
|
||||||
|
|
||||||
|
// Extract the cookies specified in cookiesToExtract
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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 {
|
||||||
|
console.log('csrfToken not found in the response.');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHeaders() {
|
||||||
|
return fetchCookieAndToken()
|
||||||
|
.then(() => {
|
||||||
|
return {
|
||||||
|
X_CSRFTOKEN: X_CSRFTOKEN,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Cookie: COOKIE,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -22,14 +22,18 @@ it('can generate valid request method', () => {
|
||||||
expect(request.method).toBe('POST')
|
expect(request.method).toBe('POST')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can generate valid request headers', () => {
|
it('can generate valid request headers', async () => {
|
||||||
expect(request.headers).toMatchObject({
|
const headers = await request.headers();
|
||||||
X_CSRFToken: 'e0a032d1c9df6c3fb8c8352399d32c40ddb17ccceb5142fe',
|
|
||||||
'Content-Type': 'application/json',
|
expect(headers).toHaveProperty('Cookie');
|
||||||
Cookie:
|
expect(headers).toHaveProperty('X_CSRFTOKEN');
|
||||||
'JSESSIONID=93892A98DBCCEBD83EDC4C23EBEB23B6; CSESSIONID=4A36799EF09D80539BBA8E8211FA80D3; CSRFSESSION=e0a032d1c9df6c3fb8c8352399d32c40ddb17ccceb5142fe; JSESSIONID=93892A98DBCCEBD83EDC4C23EBEB23B6'
|
|
||||||
})
|
expect(headers.Cookie).toMatch(/JSESSIONID=[\dA-F]+;/i);
|
||||||
})
|
expect(headers.Cookie).toMatch(/CSESSIONID=[\dA-F]+;/i);
|
||||||
|
expect(headers.Cookie).toMatch(/CSRFSESSION=[\dA-F]+;/i);
|
||||||
|
expect(headers.Cookie).toMatch(/JSESSIONID=[\dA-F]+;/i);
|
||||||
|
expect(headers.X_CSRFTOKEN).toMatch(/[\dA-F]/i);
|
||||||
|
});
|
||||||
|
|
||||||
it('can generate valid request data', () => {
|
it('can generate valid request data', () => {
|
||||||
expect(request.data({ channel, date })).toMatchObject({
|
expect(request.data({ channel, date })).toMatchObject({
|
||||||
|
@ -51,7 +55,7 @@ it('can generate valid request data', () => {
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content =
|
const content =
|
||||||
'{"playbilllist":[{"id":"30021745","name":"FBI: Special Crime Unit","introduce":"Nachdem ein Mann von einem Sprengstoffpaket getötet wurde, das zu ihm nach Hause geschickt wurde, versucht das Team, den Absender zu fassen und sein neuestes tödliches Paket abzufangen. Maggie hat Mühe, ihrer jüngeren Schwester zu vertrauen.","channelid":"255","starttime":"2022-03-09 01:00:00 UTC+01:00","endtime":"2022-03-09 01:45:00 UTC+01:00","genres":"Wissen,Natur und Tiere","pictures":[{"rel":"image","href":"http://ngiss.t-online.de/sweetprogrammanager/media/gracenote/1/9/p19740197_e_h9_af.jpg","description":"Brother\'s Keeper","imageType":"1","copyrightNotice":"(c) ProSiebenSat.1","mimeType":"image/jpeg","resolution":["1440","1080"]},{"rel":"image","href":"http://ngiss.t-online.de/sweetprogrammanager/media/gracenote/1/5/p15528073_i_h9_ae.jpg","description":"FBI","imageType":"13","copyrightNotice":"(c) ProSiebenSat.1","mimeType":"image/jpeg","resolution":["1440","1080"]},{"rel":"image","href":"http://ngiss.t-online.de/sweetprogrammanager/media/gracenote/1/9/p19740197_e_h8_af.jpg","description":"Brother\'s Keeper","imageType":"17","copyrightNotice":"(c) ProSiebenSat.1","mimeType":"image/jpeg","resolution":["1920","1080"]},{"rel":"image","href":"http://ngiss.t-online.de/sweetprogrammanager/media/gracenote/1/5/p15528073_i_h10_af.jpg","description":"FBI","imageType":"18","copyrightNotice":"(c) ProSiebenSat.1","mimeType":"image/jpeg","resolution":["1920","1080"]}]}]}'
|
'{"playbilllist":[{"id":"39328203","name":"Twenty Foot Plus","introduce":"Die besten Big-Wave-Surfer werden bei ihrer Suche nach der nächsten großen Welle begleitet.","channelid":"5027","starttime":"2023-10-23 23:58:55 UTC+00:00","endtime":"2023-10-24 00:11:05 UTC+00:00","genres":"Sport","pictures":[{"rel":"image","href":"http://ngiss.t-online.de/cm1s/media/gracenote/2/4/p24832950_e_h9_aa_2023-06-22T10_12_01.jpg","imageType":"1","mimeType":"image/jpeg","resolution":["1440","1080"]}]}]}'
|
||||||
const result = parser({ content }).map(p => {
|
const result = parser({ content }).map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
|
@ -60,13 +64,13 @@ it('can parse response', () => {
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(result).toMatchObject([
|
||||||
{
|
{
|
||||||
start: '2022-03-09T00:00:00.000Z',
|
start: '2023-10-23T23:58:55.000Z',
|
||||||
stop: '2022-03-09T00:45:00.000Z',
|
stop: '2023-10-24T00:11:05.000Z',
|
||||||
title: 'FBI: Special Crime Unit',
|
title: 'Twenty Foot Plus',
|
||||||
description:
|
description:
|
||||||
'Nachdem ein Mann von einem Sprengstoffpaket getötet wurde, das zu ihm nach Hause geschickt wurde, versucht das Team, den Absender zu fassen und sein neuestes tödliches Paket abzufangen. Maggie hat Mühe, ihrer jüngeren Schwester zu vertrauen.',
|
'Die besten Big-Wave-Surfer werden bei ihrer Suche nach der nächsten großen Welle begleitet.',
|
||||||
icon: 'http://ngiss.t-online.de/sweetprogrammanager/media/gracenote/1/9/p19740197_e_h9_af.jpg',
|
icon: 'http://ngiss.t-online.de/cm1s/media/gracenote/2/4/p24832950_e_h9_aa_2023-06-22T10_12_01.jpg',
|
||||||
category: ['Wissen', 'Natur', 'Tiere']
|
category: ['Sport']
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue