diff --git a/fixes/pickx.be/pickx.be.config.js b/fixes/pickx.be/pickx.be.config.js index 048ada3..ab4757e 100644 --- a/fixes/pickx.be/pickx.be.config.js +++ b/fixes/pickx.be/pickx.be.config.js @@ -2,26 +2,17 @@ const axios = require('axios') const dayjs = require('dayjs') -const utc = require('dayjs/plugin/utc') let apiVersion -dayjs.extend(utc) - module.exports = { site: 'pickx.be', days: 2, - setApiVersion: function (version) { - apiVersion = version - }, - getApiVersion: function () { - return apiVersion - }, - fetchApiVersion: fetchApiVersion, - url: async function ({ channel, date }) { + async url({ channel, date }) { if (!apiVersion) { await fetchApiVersion() } + return `https://px-epg.azureedge.net/airings/${apiVersion}/${date.format( 'YYYY-MM-DD' )}/channel/${channel.site_id}?timezone=Europe%2FBrussels` @@ -51,19 +42,21 @@ module.exports = { episode: item.program.episodeNumber, actors: item.program.actors, director: item.program.director ? [item.program.director] : null, - start: dayjs.utc(item.programScheduleStart), - stop: dayjs.utc(item.programScheduleEnd) + start: dayjs(item.programScheduleStart), + stop: dayjs(item.programScheduleEnd) }) }) } return programs }, - async channels({ lang = '' }) { + async channels() { + let channels = [] + const query = { operationName: 'getChannels', variables: { - language: lang, + language: 'fr', queryParams: {}, id: '0', params: { @@ -71,96 +64,60 @@ module.exports = { } }, query: `query getChannels($language: String!, $queryParams: ChannelQueryParams, $id: String, $params: ChannelParams) { - channels(language: $language, queryParams: $queryParams, id: $id, params: $params) { - id - channelReferenceNumber - name - callLetter - number - logo { - key - url - __typename - } - language - hd - radio - replayable - ottReplayable - playable - ottPlayable - recordable - subscribed - cloudRecordable - catchUpWindowInHours - isOttNPVREnabled - ottNPVRStart - subscription { - channelRef - subscribed - upselling { - upsellable - packages - __typename - } - __typename - } - packages - __typename - } - }` + channels(language: $language, queryParams: $queryParams, id: $id, params: $params) { + id + name + language + radio + } + }` } - const result = await axios + + const data = await axios .post('https://api.proximusmwc.be/tiams/v3/graphql', query) .then(r => r.data) .catch(console.error) - return ( - result?.data?.channels - .filter( - channel => - !channel.radio && (!lang || channel.language === (lang === 'de' ? 'ger' : lang)) - ) - .map(channel => { - return { - lang: channel.language === 'ger' ? 'de' : channel.language, - site_id: channel.id, - name: channel.name - } - }) || [] - ) + data.data.channels.forEach(channel => { + let lang = channel.language || 'fr' + if (channel.language === 'ger') lang = 'de' + + channels.push({ + lang, + site_id: channel.id, + name: channel.name + }) + }) + + return channels } } -function fetchApiVersion() { - return new Promise(async (resolve, reject) => { + +async function fetchApiVersion() { + 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/' + } + }) + + return new Promise((resolve, reject) => { try { - // you'll never find what happened here :) - // 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. - - 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 (response.status === 200) { apiVersion = response.data.version resolve()