From 7a9ece8e59d5e605676ce5dfcbf28b88aea12d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:52:45 +0100 Subject: [PATCH 1/7] Update i24news.tv.channels.xml --- sites/i24news.tv/i24news.tv.channels.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sites/i24news.tv/i24news.tv.channels.xml b/sites/i24news.tv/i24news.tv.channels.xml index b8957434..3f6b355a 100644 --- a/sites/i24news.tv/i24news.tv.channels.xml +++ b/sites/i24news.tv/i24news.tv.channels.xml @@ -1,7 +1,7 @@ - I24NEWS عربى - I24NEWS English (USA) - I24NEWS English (World) - I24NEWS Français + I24NEWS عربى + I24NEWS English (USA) + I24NEWS Français + I24NEWS עברית From ed3ede914c99d12e004bc5484ea459ed7ea88428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:52:56 +0100 Subject: [PATCH 2/7] Update i24news.tv.config.js --- sites/i24news.tv/i24news.tv.config.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sites/i24news.tv/i24news.tv.config.js b/sites/i24news.tv/i24news.tv.config.js index 556bea40..b8539910 100644 --- a/sites/i24news.tv/i24news.tv.config.js +++ b/sites/i24news.tv/i24news.tv.config.js @@ -11,9 +11,7 @@ module.exports = { site: 'i24news.tv', days: 2, url: function ({ channel }) { - const [lang, region] = channel.site_id.split('#') - - return `https://api.i24news.tv/v2/${lang}/schedules/${region}` + return `https://api.i24news.tv/v2/${channel.site_id}/schedules` }, parser: function ({ content, date }) { let programs = [] From 38ab58d03ac2654f08e900f6878f3dc336d37c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:53:07 +0100 Subject: [PATCH 3/7] Update i24news.tv.test.js --- sites/i24news.tv/i24news.tv.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sites/i24news.tv/i24news.tv.test.js b/sites/i24news.tv/i24news.tv.test.js index 54c05f7a..2525cdd8 100644 --- a/sites/i24news.tv/i24news.tv.test.js +++ b/sites/i24news.tv/i24news.tv.test.js @@ -7,12 +7,12 @@ dayjs.extend(utc) const date = dayjs.utc('2022-03-06', 'YYYY-MM-DD').startOf('d') const channel = { - site_id: 'ar#', + site_id: 'ar', xmltv_id: 'I24NewsArabic.il' } it('can generate valid url', () => { - expect(url({ channel })).toBe('https://api.i24news.tv/v2/ar/schedules/world') + expect(url({ channel })).toBe('https://api.i24news.tv/v2/ar/schedules') }) it('can parse response', () => { From 8374cd588584391dbedb9b80f429cdd694ec9c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:55:23 +0100 Subject: [PATCH 4/7] Update pickx.be.config.js --- sites/pickx.be/pickx.be.config.js | 92 ++++++++++++------------------- 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/sites/pickx.be/pickx.be.config.js b/sites/pickx.be/pickx.be.config.js index 3fc67e31..38d1ac21 100644 --- a/sites/pickx.be/pickx.be.config.js +++ b/sites/pickx.be/pickx.be.config.js @@ -3,29 +3,22 @@ const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') let apiVersion -let isApiVersionFetched = false - -;(async () => { - try { - await fetchApiVersion() - isApiVersionFetched = true - } catch (error) { - console.error('Error during script initialization:', error) - } -})() dayjs.extend(utc) module.exports = { site: 'pickx.be', days: 2, - apiVersion: function () { + setApiVersion: function (version) { + apiVersion = version + }, + getApiVersion: function () { return apiVersion }, - fetchApiVersion: fetchApiVersion, // Export fetchApiVersion + fetchApiVersion: fetchApiVersion, url: async function ({ channel, date }) { - while (!isApiVersionFetched) { - await new Promise(resolve => setTimeout(resolve, 100)) // Wait for 100 milliseconds + if (!apiVersion) { + await fetchApiVersion() } return `https://px-epg.azureedge.net/airings/${apiVersion}/${date.format( 'YYYY-MM-DD' @@ -116,7 +109,7 @@ module.exports = { }` } const result = await axios - .post('https://api.proximusmwc.be/tiams/v2/graphql', query) + .post('https://api.proximusmwc.be/tiams/v3/graphql', query) .then(r => r.data) .catch(console.error) @@ -140,53 +133,38 @@ function fetchApiVersion() { return new Promise(async (resolve, reject) => { try { // you'll never find what happened here :) - // load pickx bundle and get react version hash (regex). + // load the pickx page and get the hash from the MWC configuration. // it's not the best way to get the version but it's the only way to get it. - // find bundle version - const minBundleVer = "https://www.pickx.be/minimal-bundle-version" - const bundleVerData = await axios.get(minBundleVer, { - headers: { - Origin: 'https://www.pickx.be', - Referer: 'https://www.pickx.be/' - } + const hashUrl = 'https://www.pickx.be/nl/televisie/tv-gids'; + + const hashData = await axios.get(hashUrl) + .then(r => { + const re = /"hashes":\["(.*)"\]/ + const match = r.data.match(re) + if (match && match[1]) { + return match[1] + } else { + throw new Error('React app version hash not found') + } + }) + .catch(console.error); + + const versionUrl = `https://www.pickx.be/api/s-${hashData}` + + const response = await axios.get(versionUrl, { + headers: { + Origin: 'https://www.pickx.be', + Referer: 'https://www.pickx.be/' + } }) - if (bundleVerData.status !== 200) { - console.error(`Failed to fetch bundle version. Status: ${bundleVerData.status}`) - reject(`Failed to fetch bundle version. Status: ${bundleVerData.status}`) + if (response.status === 200) { + apiVersion = response.data.version + resolve() } else { - const bundleVer = bundleVerData.data.version - // get the minified JS app bundle - const bundleUrl = `https://components.pickx.be/pxReactPlayer/${bundleVer}/bundle.min.js` - - // now, find the react hash inside the bundle URL - const bundle = await axios.get(bundleUrl).then(r => { - const re = /REACT_APP_VERSION_HASH:"([^"]+)"/ - const match = r.data.match(re) - if (match && match[1]) { - return match[1] - } else { - throw new Error('React app version hash not found') - } - }).catch(console.error) - - const versionUrl = `https://www.pickx.be/api/s-${bundle.replace('/REACT_APP_VERSION_HASH:"', '')}` - - const response = await axios.get(versionUrl, { - headers: { - Origin: 'https://www.pickx.be', - Referer: 'https://www.pickx.be/' - } - }) - - if (response.status === 200) { - apiVersion = response.data.version - resolve() - } else { - console.error(`Failed to fetch API version. Status: ${response.status}`) - reject(`Failed to fetch API version. Status: ${response.status}`) - } + console.error(`Failed to fetch API version. Status: ${response.status}`) + reject(`Failed to fetch API version. Status: ${response.status}`) } } catch (error) { console.error('Error during fetchApiVersion:', error) From 782f911d3e5653e06d62fa37778627de903bce17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 15:55:39 +0100 Subject: [PATCH 5/7] Update pickx.be.test.js --- sites/pickx.be/pickx.be.test.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/sites/pickx.be/pickx.be.test.js b/sites/pickx.be/pickx.be.test.js index eef0a82f..aa89f09c 100644 --- a/sites/pickx.be/pickx.be.test.js +++ b/sites/pickx.be/pickx.be.test.js @@ -1,4 +1,20 @@ -const { parser, url, request, fetchApiVersion, apiVersion } = require('./pickx.be.config.js') +jest.mock('./pickx.be.config.js', () => { + const originalModule = jest.requireActual('./pickx.be.config.js') + return { + ...originalModule, + fetchApiVersion: jest.fn(() => Promise.resolve()) + } +}) + +const { + parser, + url, + request, + fetchApiVersion, + setApiVersion, + getApiVersion +} = require('./pickx.be.config.js') + const fs = require('fs') const path = require('path') const dayjs = require('dayjs') @@ -13,12 +29,14 @@ const channel = { xmltv_id: 'Vedia.be' } +beforeEach(() => { + setApiVersion('mockedApiVersion') +}) + it('can generate valid url', async () => { - await fetchApiVersion() const generatedUrl = await url({ channel, date }) - const resolvedApiVersion = apiVersion() expect(generatedUrl).toBe( - `https://px-epg.azureedge.net/airings/${resolvedApiVersion}/2023-12-13/channel/UID0118?timezone=Europe%2FBrussels` + `https://px-epg.azureedge.net/airings/mockedApiVersion/2023-12-13/channel/UID0118?timezone=Europe%2FBrussels` ) }) From 67e7f13c02283464059c0167607bc3a8734e4919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:03:48 +0100 Subject: [PATCH 6/7] Update iltalehti.fi.test.js --- sites/iltalehti.fi/iltalehti.fi.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/iltalehti.fi/iltalehti.fi.test.js b/sites/iltalehti.fi/iltalehti.fi.test.js index b117e3d0..954eb422 100644 --- a/sites/iltalehti.fi/iltalehti.fi.test.js +++ b/sites/iltalehti.fi/iltalehti.fi.test.js @@ -9,7 +9,7 @@ dayjs.extend(utc) const date = dayjs.utc('2022-10-29', 'YYYY-MM-DD').startOf('d') const channel = { - site_id: 'default_builtin_channelgroup1#yle-tv1', + site_id: '1#yle-tv1', xmltv_id: 'YleTV1.fi' } From e00efc77b9c88bdb3eb7668dd54a74ee2ee5b07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Moret?= <30985701+BellezaEmporium@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:04:03 +0100 Subject: [PATCH 7/7] Update iltalehti.fi.config.js