mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #2525 from iptv-org/bellezaemporium/fixes/pickx
[Fix] pickx.be
This commit is contained in:
commit
fd91a9c532
2 changed files with 57 additions and 61 deletions
|
@ -3,29 +3,22 @@ const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
|
||||||
let apiVersion
|
let apiVersion
|
||||||
let isApiVersionFetched = false
|
|
||||||
|
|
||||||
;(async () => {
|
|
||||||
try {
|
|
||||||
await fetchApiVersion()
|
|
||||||
isApiVersionFetched = true
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error during script initialization:', error)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'pickx.be',
|
site: 'pickx.be',
|
||||||
days: 2,
|
days: 2,
|
||||||
apiVersion: function () {
|
setApiVersion: function (version) {
|
||||||
|
apiVersion = version
|
||||||
|
},
|
||||||
|
getApiVersion: function () {
|
||||||
return apiVersion
|
return apiVersion
|
||||||
},
|
},
|
||||||
fetchApiVersion: fetchApiVersion, // Export fetchApiVersion
|
fetchApiVersion: fetchApiVersion,
|
||||||
url: async function ({ channel, date }) {
|
url: async function ({ channel, date }) {
|
||||||
while (!isApiVersionFetched) {
|
if (!apiVersion) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 100)) // Wait for 100 milliseconds
|
await fetchApiVersion()
|
||||||
}
|
}
|
||||||
return `https://px-epg.azureedge.net/airings/${apiVersion}/${date.format(
|
return `https://px-epg.azureedge.net/airings/${apiVersion}/${date.format(
|
||||||
'YYYY-MM-DD'
|
'YYYY-MM-DD'
|
||||||
|
@ -116,7 +109,7 @@ module.exports = {
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
const result = await axios
|
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)
|
.then(r => r.data)
|
||||||
.catch(console.error)
|
.catch(console.error)
|
||||||
|
|
||||||
|
@ -140,38 +133,24 @@ function fetchApiVersion() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
// you'll never find what happened here :)
|
// 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.
|
// it's not the best way to get the version but it's the only way to get it.
|
||||||
|
|
||||||
// find bundle version
|
const hashUrl = 'https://www.pickx.be/nl/televisie/tv-gids';
|
||||||
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/'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (bundleVerData.status !== 200) {
|
const hashData = await axios.get(hashUrl)
|
||||||
console.error(`Failed to fetch bundle version. Status: ${bundleVerData.status}`)
|
.then(r => {
|
||||||
reject(`Failed to fetch bundle version. Status: ${bundleVerData.status}`)
|
const re = /"hashes":\["(.*)"\]/
|
||||||
} 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)
|
const match = r.data.match(re)
|
||||||
if (match && match[1]) {
|
if (match && match[1]) {
|
||||||
return match[1]
|
return match[1]
|
||||||
} else {
|
} else {
|
||||||
throw new Error('React app version hash not found')
|
throw new Error('React app version hash not found')
|
||||||
}
|
}
|
||||||
}).catch(console.error)
|
})
|
||||||
|
.catch(console.error);
|
||||||
|
|
||||||
const versionUrl = `https://www.pickx.be/api/s-${bundle.replace('/REACT_APP_VERSION_HASH:"', '')}`
|
const versionUrl = `https://www.pickx.be/api/s-${hashData}`
|
||||||
|
|
||||||
const response = await axios.get(versionUrl, {
|
const response = await axios.get(versionUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -187,7 +166,6 @@ function fetchApiVersion() {
|
||||||
console.error(`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}`)
|
reject(`Failed to fetch API version. Status: ${response.status}`)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error during fetchApiVersion:', error)
|
console.error('Error during fetchApiVersion:', error)
|
||||||
reject(error)
|
reject(error)
|
||||||
|
|
|
@ -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 fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
|
@ -13,12 +29,14 @@ const channel = {
|
||||||
xmltv_id: 'Vedia.be'
|
xmltv_id: 'Vedia.be'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
setApiVersion('mockedApiVersion')
|
||||||
|
})
|
||||||
|
|
||||||
it('can generate valid url', async () => {
|
it('can generate valid url', async () => {
|
||||||
await fetchApiVersion()
|
|
||||||
const generatedUrl = await url({ channel, date })
|
const generatedUrl = await url({ channel, date })
|
||||||
const resolvedApiVersion = apiVersion()
|
|
||||||
expect(generatedUrl).toBe(
|
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`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue