mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 02:16:40 -05:00
fix tvprofil.com
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -12,22 +12,28 @@ module.exports = {
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'x-requested-with': 'XMLHttpRequest'
|
||||
'x-requested-with': 'XMLHttpRequest',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36',
|
||||
'referer': 'https://tvprofil.com/tvprogram/',
|
||||
'accept': 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01'
|
||||
}
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const title = parseTitle($item)
|
||||
const category = parseCategory($item)
|
||||
const start = parseStart($item)
|
||||
const duration = parseDuration($item)
|
||||
const stop = start.add(duration, 's')
|
||||
const image = parseImage($item)
|
||||
const $ = cheerio.load(item)
|
||||
$('div.row').each((_, el) => {
|
||||
const $item = $(el)
|
||||
const title = parseTitle($item)
|
||||
const category = parseCategory($item)
|
||||
const start = parseStart($item)
|
||||
const duration = parseDuration($item)
|
||||
const stop = start.add(duration, 's')
|
||||
const icon = parseImage($item)
|
||||
|
||||
programs.push({ title, category, start, stop, image })
|
||||
programs.push({ title, category, start, stop, icon })
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
@@ -102,64 +108,73 @@ module.exports = {
|
||||
}
|
||||
|
||||
function parseImage($item) {
|
||||
return $item(':root').data('image')
|
||||
return $item.attr('data-image') || null
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
return $item(':root').data('len')
|
||||
return parseInt($item.attr('data-len'))
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const timestamp = $item(':root').data('ts')
|
||||
|
||||
const timestamp = parseInt($item.attr('data-ts'))
|
||||
return dayjs.unix(timestamp)
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.col:nth-child(2) > small').text() || null
|
||||
return $item.find('.col:nth-child(2) > small').text() || null
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
let title = $item('.col:nth-child(2) > a').text()
|
||||
title += $item('.col:nth-child(2)').clone().children().remove().end().text()
|
||||
let title = $item.find('.col:nth-child(2) > a').text()
|
||||
title += $item.find('.col:nth-child(2)').clone().children().remove().end().text()
|
||||
|
||||
return title.replace('®', '').trim().replace(/,$/, '')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
let data = (content.match(/cb\((.*)\)/) || [null, null])[1]
|
||||
let data = (content.match(/^[^(]+\(([\s\S]*)\)$/) || [null, null])[1]
|
||||
if (!data) return []
|
||||
let json = JSON.parse(data)
|
||||
if (!json || !json.data || !json.data.program) return []
|
||||
|
||||
const $ = cheerio.load(json.data.program)
|
||||
|
||||
return $('.row').toArray()
|
||||
return [json.data.program]
|
||||
}
|
||||
|
||||
function buildQuery(site_id, date) {
|
||||
const query = {
|
||||
datum: date.format('YYYY-MM-DD'),
|
||||
kanal: site_id,
|
||||
callback: 'cb'
|
||||
kanal: site_id
|
||||
// callback: 'cb' // possibly still working
|
||||
}
|
||||
|
||||
let c = 4
|
||||
const a = query.datum + query.kanal + c
|
||||
const ua = query.kanal + query.datum
|
||||
let a = query.datum + query.kanal + c
|
||||
let ua = query.kanal + query.datum
|
||||
|
||||
let i = a.length,
|
||||
b = 2
|
||||
if (
|
||||
typeof ua === 'undefined' ||
|
||||
ua === null ||
|
||||
ua === '' ||
|
||||
ua === 0 ||
|
||||
ua === '0' ||
|
||||
ua !== ua
|
||||
) {
|
||||
ua = 'none'
|
||||
}
|
||||
|
||||
for (let j = 0; j < ua.length; j++) c += ua.charCodeAt(j)
|
||||
|
||||
let i = a.length
|
||||
let b = 2
|
||||
while (i--) {
|
||||
b += (a.charCodeAt(i) + c * 2) * i
|
||||
}
|
||||
|
||||
b = b.toString()
|
||||
const key = 'b' + b.charCodeAt(b.length - 1)
|
||||
|
||||
const lastCharCode = b.charCodeAt(b.length - 1)
|
||||
const key = 'b' + lastCharCode
|
||||
query['callback'] = `tvprogramit${lastCharCode}`
|
||||
query[key] = b
|
||||
|
||||
return new URLSearchParams(query).toString()
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2025-01-19', 'YYYY-MM-DD').startOf('d')
|
||||
const date = dayjs.utc('2025-07-29', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'bg/tv-programa#24kitchen-bg',
|
||||
xmltv_id: '24KitchenBulgaria.bg'
|
||||
@@ -15,13 +15,14 @@ const channel = {
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://tvprofil.com/bg/tv-programa/program/?datum=2025-01-19&kanal=24kitchen-bg&callback=cb&b52=824084'
|
||||
'https://tvprofil.com/bg/tv-programa/program/?datum=2025-07-29&kanal=24kitchen-bg&callback=tvprogramit48&b48=827670'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-requested-with': 'XMLHttpRequest'
|
||||
'x-requested-with': 'XMLHttpRequest',
|
||||
'referer': 'https://tvprofil.com/tvprogram/',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -34,9 +35,9 @@ it('can parse response', () => {
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
title: 'Мексиканска кухня с Пати 10, еп. 9',
|
||||
start: '2023-01-12T04:00:00.000Z',
|
||||
stop: '2023-01-12T04:30:00.000Z'
|
||||
title: 'Save with Jamie 1, ep. 2',
|
||||
start: '2025-07-29T05:00:00.000Z',
|
||||
stop: '2025-07-29T06:00:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user