@@ -3,29 +3,22 @@ const dayjs = require('dayjs')
3
3
const utc = require ( 'dayjs/plugin/utc' )
4
4
5
5
let apiVersion
6
- let isApiVersionFetched = false
7
-
8
- ; ( async ( ) => {
9
- try {
10
- await fetchApiVersion ( )
11
- isApiVersionFetched = true
12
- } catch ( error ) {
13
- console . error ( 'Error during script initialization:' , error )
14
- }
15
- } ) ( )
16
6
17
7
dayjs . extend ( utc )
18
8
19
9
module . exports = {
20
10
site : 'pickx.be' ,
21
11
days : 2 ,
22
- apiVersion : function ( ) {
12
+ setApiVersion : function ( version ) {
13
+ apiVersion = version
14
+ } ,
15
+ getApiVersion : function ( ) {
23
16
return apiVersion
24
17
} ,
25
- fetchApiVersion : fetchApiVersion , // Export fetchApiVersion
18
+ fetchApiVersion : fetchApiVersion ,
26
19
url : async function ( { channel, date } ) {
27
- while ( ! isApiVersionFetched ) {
28
- await new Promise ( resolve => setTimeout ( resolve , 100 ) ) // Wait for 100 milliseconds
20
+ if ( ! apiVersion ) {
21
+ await fetchApiVersion ( )
29
22
}
30
23
return `https://px-epg.azureedge.net/airings/${ apiVersion } /${ date . format (
31
24
'YYYY-MM-DD'
@@ -116,7 +109,7 @@ module.exports = {
116
109
}`
117
110
}
118
111
const result = await axios
119
- . post ( 'https://api.proximusmwc.be/tiams/v2 /graphql' , query )
112
+ . post ( 'https://api.proximusmwc.be/tiams/v3 /graphql' , query )
120
113
. then ( r => r . data )
121
114
. catch ( console . error )
122
115
@@ -140,53 +133,38 @@ function fetchApiVersion() {
140
133
return new Promise ( async ( resolve , reject ) => {
141
134
try {
142
135
// you'll never find what happened here :)
143
- // load pickx bundle and get react version hash (regex) .
136
+ // load the pickx page and get the hash from the MWC configuration .
144
137
// it's not the best way to get the version but it's the only way to get it.
145
138
146
- // find bundle version
147
- const minBundleVer = "https://www.pickx.be/minimal-bundle-version"
148
- const bundleVerData = await axios . get ( minBundleVer , {
149
- headers : {
150
- Origin : 'https://www.pickx.be' ,
151
- Referer : 'https://www.pickx.be/'
152
- }
153
- } )
154
-
155
- if ( bundleVerData . status !== 200 ) {
156
- console . error ( `Failed to fetch bundle version. Status: ${ bundleVerData . status } ` )
157
- reject ( `Failed to fetch bundle version. Status: ${ bundleVerData . status } ` )
158
- } else {
159
- const bundleVer = bundleVerData . data . version
160
- // get the minified JS app bundle
161
- const bundleUrl = `https://components.pickx.be/pxReactPlayer/${ bundleVer } /bundle.min.js`
162
-
163
- // now, find the react hash inside the bundle URL
164
- const bundle = await axios . get ( bundleUrl ) . then ( r => {
165
- const re = / R E A C T _ A P P _ V E R S I O N _ H A S H : " ( [ ^ " ] + ) " /
166
- const match = r . data . match ( re )
167
- if ( match && match [ 1 ] ) {
168
- return match [ 1 ]
169
- } else {
170
- throw new Error ( 'React app version hash not found' )
171
- }
172
- } ) . catch ( console . error )
173
-
174
- const versionUrl = `https://www.pickx.be/api/s-${ bundle . replace ( '/REACT_APP_VERSION_HASH:"' , '' ) } `
139
+ const hashUrl = 'https://www.pickx.be/nl/televisie/tv-gids' ;
175
140
176
- const response = await axios . get ( versionUrl , {
177
- headers : {
178
- Origin : 'https://www.pickx.be' ,
179
- Referer : 'https://www.pickx.be/'
180
- }
181
- } )
182
-
183
- if ( response . status === 200 ) {
184
- apiVersion = response . data . version
185
- resolve ( )
141
+ const hashData = await axios . get ( hashUrl )
142
+ . then ( r => {
143
+ const re = / " h a s h e s " : \[ " ( .* ) " \] /
144
+ const match = r . data . match ( re )
145
+ if ( match && match [ 1 ] ) {
146
+ return match [ 1 ]
186
147
} else {
187
- console . error ( `Failed to fetch API version. Status: ${ response . status } ` )
188
- reject ( `Failed to fetch API version. Status: ${ response . status } ` )
148
+ throw new Error ( 'React app version hash not found' )
189
149
}
150
+ } )
151
+ . catch ( console . error ) ;
152
+
153
+ const versionUrl = `https://www.pickx.be/api/s-${ hashData } `
154
+
155
+ const response = await axios . get ( versionUrl , {
156
+ headers : {
157
+ Origin : 'https://www.pickx.be' ,
158
+ Referer : 'https://www.pickx.be/'
159
+ }
160
+ } )
161
+
162
+ if ( response . status === 200 ) {
163
+ apiVersion = response . data . version
164
+ resolve ( )
165
+ } else {
166
+ console . error ( `Failed to fetch API version. Status: ${ response . status } ` )
167
+ reject ( `Failed to fetch API version. Status: ${ response . status } ` )
190
168
}
191
169
} catch ( error ) {
192
170
console . error ( 'Error during fetchApiVersion:' , error )
0 commit comments