Skip to content

Commit 584a751

Browse files
authored
Merge pull request #2898 from iptv-org/be-tvpassport-fix
tvpassport.com : dynamic cookie handling
2 parents 8beebc0 + a5ab514 commit 584a751

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

sites/tvpassport.com/tvpassport.com.config.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ module.exports = {
1919
'YYYY-MM-DD'
2020
)}`
2121
},
22-
request: {
23-
timeout: 30000,
24-
headers: {
25-
Cookie: 'cisession=e49ff13191d6875887193cae9e324b44ef85768d;'
22+
async request() {
23+
return {
24+
timeout: 30000,
25+
headers: {
26+
Cookie: await getCookie()
27+
}
2628
}
2729
},
2830
parser: function ({ content }) {
@@ -106,6 +108,14 @@ module.exports = {
106108
}
107109
}
108110

111+
async function getCookie() {
112+
const res = await axios.get('https://www.tvpassport.com/tv-listings')
113+
const setCookie = res.headers['set-cookie']
114+
if (!setCookie || setCookie.length === 0) return ''
115+
const cookies = setCookie.map(cookie => cookie.split(';')[0])
116+
return cookies.join('; ')
117+
}
118+
109119
function parseDescription($item) {
110120
return $item('*').data('description')
111121
}

sites/tvpassport.com/tvpassport.com.test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { parser, url, request } = require('./tvpassport.com.config.js')
1+
const { parser, url } = require('./tvpassport.com.config.js')
22
const fs = require('fs')
33
const path = require('path')
44
const dayjs = require('dayjs')
@@ -19,12 +19,6 @@ it('can generate valid url', () => {
1919
)
2020
})
2121

22-
it('can generate valid request headers', () => {
23-
expect(request.headers).toMatchObject({
24-
Cookie: 'cisession=e49ff13191d6875887193cae9e324b44ef85768d;'
25-
})
26-
})
27-
2822
it('can parse response', () => {
2923
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
3024

0 commit comments

Comments
 (0)