mirror of
https://github.com/iptv-org/epg
synced 2026-04-28 21:46:58 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,97 +1,97 @@
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'tvprofil.com',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
const parts = channel.site_id.split('#')
|
||||
const query = buildQuery(parts[1], date)
|
||||
|
||||
return `https://tvprofil.com/${parts[0]}/program/?${query}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'x-requested-with': 'XMLHttpRequest'
|
||||
}
|
||||
},
|
||||
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 icon = parseIcon($item)
|
||||
|
||||
programs.push({ title, category, start, stop, icon })
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item(':root').data('image')
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
return $item(':root').data('len')
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const timestamp = $item(':root').data('ts')
|
||||
|
||||
return dayjs.unix(timestamp)
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.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()
|
||||
|
||||
return title.replace('®', '').trim().replace(/,$/, '')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
let data = (content.match(/cb\((.*)\)/) || [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()
|
||||
}
|
||||
|
||||
function buildQuery(site_id, date) {
|
||||
const query = {
|
||||
datum: date.format('YYYY-MM-DD'),
|
||||
kanal: site_id,
|
||||
callback: 'cb'
|
||||
}
|
||||
|
||||
const a = query.datum + query.kanal
|
||||
const ua = query.kanal + query.datum
|
||||
|
||||
let i = a.length,
|
||||
b = 2,
|
||||
c = 2
|
||||
|
||||
for (var j = 0; j < ua.length; j++) c += ua.charCodeAt(j)
|
||||
while (i--) {
|
||||
b += (a.charCodeAt(i) + c * 2) * i
|
||||
}
|
||||
|
||||
const key = 'b' + b.toString().charCodeAt(2)
|
||||
|
||||
query[key] = b
|
||||
|
||||
return new URLSearchParams(query).toString()
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'tvprofil.com',
|
||||
days: 2,
|
||||
url: function ({ channel, date }) {
|
||||
const parts = channel.site_id.split('#')
|
||||
const query = buildQuery(parts[1], date)
|
||||
|
||||
return `https://tvprofil.com/${parts[0]}/program/?${query}`
|
||||
},
|
||||
request: {
|
||||
headers: {
|
||||
'x-requested-with': 'XMLHttpRequest'
|
||||
}
|
||||
},
|
||||
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 icon = parseIcon($item)
|
||||
|
||||
programs.push({ title, category, start, stop, icon })
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item(':root').data('image')
|
||||
}
|
||||
|
||||
function parseDuration($item) {
|
||||
return $item(':root').data('len')
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const timestamp = $item(':root').data('ts')
|
||||
|
||||
return dayjs.unix(timestamp)
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.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()
|
||||
|
||||
return title.replace('®', '').trim().replace(/,$/, '')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
let data = (content.match(/cb\((.*)\)/) || [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()
|
||||
}
|
||||
|
||||
function buildQuery(site_id, date) {
|
||||
const query = {
|
||||
datum: date.format('YYYY-MM-DD'),
|
||||
kanal: site_id,
|
||||
callback: 'cb'
|
||||
}
|
||||
|
||||
const a = query.datum + query.kanal
|
||||
const ua = query.kanal + query.datum
|
||||
|
||||
let i = a.length,
|
||||
b = 2,
|
||||
c = 2
|
||||
|
||||
for (var j = 0; j < ua.length; j++) c += ua.charCodeAt(j)
|
||||
while (i--) {
|
||||
b += (a.charCodeAt(i) + c * 2) * i
|
||||
}
|
||||
|
||||
const key = 'b' + b.toString().charCodeAt(2)
|
||||
|
||||
query[key] = b
|
||||
|
||||
return new URLSearchParams(query).toString()
|
||||
}
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
// npm run grab -- --site=tvprofil.com
|
||||
|
||||
const { parser, url, request } = require('./tvprofil.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'bg/tv-programa#24kitchen-bg',
|
||||
xmltv_id: '24KitchenBulgaria.bg'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://tvprofil.com/bg/tv-programa/program/?datum=2023-01-12&kanal=24kitchen-bg&callback=cb&b55=747917'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-requested-with': 'XMLHttpRequest'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.txt'), 'utf8')
|
||||
const results = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
title: 'Мексиканска кухня с Пати 10, еп. 9',
|
||||
start: '2023-01-12T04:00:00.000Z',
|
||||
stop: '2023-01-12T04:30:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.txt'), 'utf8')
|
||||
|
||||
expect(parser({ content })).toMatchObject([])
|
||||
})
|
||||
// npm run grab -- --site=tvprofil.com
|
||||
|
||||
const { parser, url, request } = require('./tvprofil.com.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-12', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: 'bg/tv-programa#24kitchen-bg',
|
||||
xmltv_id: '24KitchenBulgaria.bg'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ channel, date })).toBe(
|
||||
'https://tvprofil.com/bg/tv-programa/program/?datum=2023-01-12&kanal=24kitchen-bg&callback=cb&b55=747917'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'x-requested-with': 'XMLHttpRequest'
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.txt'), 'utf8')
|
||||
const results = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
title: 'Мексиканска кухня с Пати 10, еп. 9',
|
||||
start: '2023-01-12T04:00:00.000Z',
|
||||
stop: '2023-01-12T04:30:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.txt'), 'utf8')
|
||||
|
||||
expect(parser({ content })).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user