Initial Commit
This commit is contained in:
1501
sites/mediaklikk.hu/__data__/content.html
Normal file
1501
sites/mediaklikk.hu/__data__/content.html
Normal file
File diff suppressed because it is too large
Load Diff
13
sites/mediaklikk.hu/mediaklikk.hu.channels.xml
Normal file
13
sites/mediaklikk.hu/mediaklikk.hu.channels.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="mediaklikk.hu">
|
||||
<channels>
|
||||
<channel lang="hu" xmltv_id="DunaTV.hu" site_id="3">Duna</channel>
|
||||
<channel lang="hu" xmltv_id="DunaWorld.hu" site_id="4">Duna World</channel>
|
||||
<channel lang="hu" xmltv_id="M1.hu" site_id="1">M1</channel>
|
||||
<channel lang="hu" xmltv_id="M2.hu" site_id="2">M2</channel>
|
||||
<channel lang="hu" xmltv_id="M3.hu" site_id="26">M3</channel>
|
||||
<channel lang="hu" xmltv_id="M4Sport.hu" site_id="30">M4 Sport</channel>
|
||||
<channel lang="hu" xmltv_id="M4SportPlus.hu" site_id="34">M4 Sport +</channel>
|
||||
<channel lang="hu" xmltv_id="M5.hu" site_id="33">M5</channel>
|
||||
</channels>
|
||||
</site>
|
||||
85
sites/mediaklikk.hu/mediaklikk.hu.config.js
Normal file
85
sites/mediaklikk.hu/mediaklikk.hu.config.js
Normal file
@@ -0,0 +1,85 @@
|
||||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'mediaklikk.hu',
|
||||
days: 2,
|
||||
url: 'https://mediaklikk.hu/wp-content/plugins/hms-global-widgets/widgets/programGuide/programGuideInterface.php',
|
||||
request: {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data: function ({ date, channel }) {
|
||||
const params = new URLSearchParams()
|
||||
params.append('ChannelIds', `${channel.site_id},`)
|
||||
params.append('Date', date.format('YYYY-MM-DD'))
|
||||
|
||||
return params
|
||||
}
|
||||
},
|
||||
parser: function ({ content }) {
|
||||
const programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
const start = parseStart($item)
|
||||
let stop = parseStop($item)
|
||||
if (!stop) stop = start.add(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item) {
|
||||
const timeString = $item('*').data('from')
|
||||
|
||||
return dayjs(timeString, 'YYYY-MM-DD HH:mm:ssZZ')
|
||||
}
|
||||
|
||||
function parseStop($item) {
|
||||
const timeString = $item('*').data('till')
|
||||
if (!timeString || /^\+/.test(timeString)) return null
|
||||
|
||||
try {
|
||||
return dayjs(timeString, 'YYYY-MM-DD HH:mm:ssZZ')
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.program_info > h1').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.program_about > .program_description > p').text().trim()
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
const backgroundImage = $item('.program_about > .program_photo').css('background-image')
|
||||
if (!backgroundImage) return null
|
||||
const [_, icon] = backgroundImage.match(/url\(\'(.*)'\)/) || [null, null]
|
||||
if (!icon) return null
|
||||
|
||||
return `https:${icon}`
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('li.program_body').toArray()
|
||||
}
|
||||
73
sites/mediaklikk.hu/mediaklikk.hu.test.js
Normal file
73
sites/mediaklikk.hu/mediaklikk.hu.test.js
Normal file
@@ -0,0 +1,73 @@
|
||||
// npx epg-grabber --config=sites/mediaklikk.hu/mediaklikk.hu.config.js --channels=sites/mediaklikk.hu/mediaklikk.hu.channels.xml --output=guide.xml --days=2
|
||||
|
||||
const { parser, url, request } = require('./mediaklikk.hu.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('2022-03-10', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '3',
|
||||
xmltv_id: 'DuneTV.hu'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url).toBe(
|
||||
'https://mediaklikk.hu/wp-content/plugins/hms-global-widgets/widgets/programGuide/programGuideInterface.php'
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid request method', () => {
|
||||
expect(request.method).toBe('POST')
|
||||
})
|
||||
|
||||
it('can generate valid request headers', () => {
|
||||
expect(request.headers).toMatchObject({
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
})
|
||||
})
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const result = request.data({ date, channel })
|
||||
expect(result.get('ChannelIds')).toBe('3,')
|
||||
expect(result.get('Date')).toBe('2022-03-10')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-10-27T22:00:46.000Z',
|
||||
stop: '2022-10-27T22:54:00.000Z',
|
||||
title: `A hegyi doktor - I. évad`,
|
||||
description:
|
||||
'Maxl iskolatársának, Vroninak az anyja egy autóbalesetben meghal. A 20 éves testvér, Vinzenz magához szeretné venni a lányt, ám a gyámüggyel problémái akadnak, ezért megpróbálja elszöktetni.(Eredeti hang digitálisan.)',
|
||||
icon: 'https://mediaklikk.hu/wp-content/uploads/sites/4/2019/10/A-hegyi-doktor-I-évad-e1571318391226-150x150.jpg'
|
||||
})
|
||||
|
||||
expect(results[56]).toMatchObject({
|
||||
start: '2022-10-28T20:35:05.000Z',
|
||||
stop: '2022-10-28T21:05:05.000Z',
|
||||
title: `Szemtől szemben (1967)`,
|
||||
description:
|
||||
'Brad Fletcher bostoni történelemtanár, aki a délnyugati határvidéken kúrálja tüdőbetegségét, egy véletlen folytán összeakad Beauregard Bennett körözött útonállóval, akit végül maga segít a menekülésben. A tanárt lenyűgözi a törvényen kívüliek világa és felismeri, hogy értelmi felsőbbrendűségével bámulatosan tudja irányítani az embereket. Bennett csakhamar azt veszi észre, hogy a peremre szorult saját bandájában. Eközben a Pinkerton ügynökség beépített embere is csapdába igyekszik csalni mindnyájukat.'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
Reference in New Issue
Block a user