1
sites/tvmusor.hu/__data__/content.json
Normal file
1
sites/tvmusor.hu/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
const FormData = require('form-data')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const _ = require('lodash')
|
||||
|
||||
module.exports = {
|
||||
site: 'tvmusor.hu',
|
||||
@@ -26,13 +26,20 @@ module.exports = {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel, date)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
let start = dayjs(item.e)
|
||||
let stop = dayjs(item.f)
|
||||
if (prev) {
|
||||
start = prev.stop
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title: item.j,
|
||||
category: item.h,
|
||||
description: item.c,
|
||||
icon: parseIcon(item),
|
||||
start: dayjs(item.e),
|
||||
stop: dayjs(item.f)
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
@@ -67,6 +74,7 @@ function parseItems(content, channel, date) {
|
||||
if (!data || !data.data || !data.data.loadedBlocks) return []
|
||||
const blocks = data.data.loadedBlocks
|
||||
const blockId = `${channel.site_id}_${date.format('YYYY-MM-DD')}`
|
||||
if (!Array.isArray(blocks[blockId])) return []
|
||||
|
||||
return Array.isArray(blocks[blockId]) ? blocks[blockId] : []
|
||||
return _.uniqBy(_.uniqBy(blocks[blockId], 'e'), 'b')
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
// node ./scripts/channels.js --config=./sites/tvmusor.hu/tvmusor.hu.config.js --output=./sites/tvmusor.hu/tvmusor.hu_hu.channels.xml
|
||||
// npm run channels:parse -- --config=./sites/tvmusor.hu/tvmusor.hu.config.js --output=./sites/tvmusor.hu/tvmusor.hu_hu.channels.xml
|
||||
// npx epg-grabber --config=sites/tvmusor.hu/tvmusor.hu.config.js --channels=sites/tvmusor.hu/tvmusor.hu_hu.channels.xml --output=guide.xml --days=2
|
||||
|
||||
const { parser, url, request } = require('./tvmusor.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('2021-11-24', 'YYYY-MM-DD').startOf('d')
|
||||
const date = dayjs.utc('2022-11-19', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '139',
|
||||
xmltv_id: 'AMCHungary.hu'
|
||||
site_id: '290',
|
||||
xmltv_id: 'M4Sport.hu'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
@@ -30,27 +32,33 @@ it('can generate valid request headers', () => {
|
||||
|
||||
it('can generate valid request data', () => {
|
||||
const result = request.data({ channel, date })
|
||||
expect(result.get('data')).toBe('{"blocks":["139|2021-11-24"]}')
|
||||
expect(result.get('data')).toBe('{"blocks":["290|2022-11-19"]}')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `{"status":"success","data":{"time":0.00033187866210938,"loadedBlocks":{"139_2021-11-24":[{"a":903037163,"b":167085,"c":"Milyen volt a vil\\u00e1g, amikor elkezdett \\u00e1talakulni azz\\u00e1 a horrorisztikus apokalipsziss\\u00e9, amelyet a The Walking Dead festett le? A Los Angeles-ben j\\u00e1tsz\\u00f3d\\u00f3 t\\u00e1rs-sorozat pontosan erre a k\\u00e9rd\\u00e9sre v\\u00e1laszol.","d":65,"e":1637712900000,"f":1637716800000,"g":2021,"h":"filmsorozat","i":"1:15","j":"Fear the Walking Dead","l":"18","n":"fear-the-walking-dead","z":"d6310651d2be559cc4e49498a21edd7477c19244_6345563D34F3542B1649E80.jpg"}]}}}`
|
||||
const result = parser({ content, channel, date }).map(p => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
let results = parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-24T00:15:00.000Z',
|
||||
stop: '2021-11-24T01:20:00.000Z',
|
||||
title: `Fear the Walking Dead`,
|
||||
category: 'filmsorozat',
|
||||
description: `Milyen volt a világ, amikor elkezdett átalakulni azzá a horrorisztikus apokalipszissé, amelyet a The Walking Dead festett le? A Los Angeles-ben játszódó társ-sorozat pontosan erre a kérdésre válaszol.`,
|
||||
icon: 'http://www.tvmusor.hu/images/events/408/d6310651d2be559cc4e49498a21edd7477c19244_6345563D34F3542B1649E80.jpg'
|
||||
}
|
||||
])
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-18T23:30:00.000Z',
|
||||
stop: '2022-11-19T00:55:00.000Z',
|
||||
title: `Rövidpályás Úszó Országos Bajnokság`,
|
||||
category: 'sportműsor',
|
||||
description: 'Forma-1 magazin. Hírek, információk, érdekességek a Forma-1 világából.',
|
||||
icon: 'http://www.tvmusor.hu/images/events/408/f1e45193930943d9ee29769e0afa902aff0e4a90-better-call-saul.jpg'
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2022-11-19T00:55:00.000Z',
|
||||
stop: '2022-11-19T01:10:00.000Z',
|
||||
title: `Sportlövészet`,
|
||||
category: 'sportműsor'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
<channel lang="hu" xmltv_id="Eurosport1.fr" site_id="94">Eurosport 1</channel>
|
||||
<channel lang="hu" xmltv_id="Eurosport2.fr" site_id="37">Eurosport 2</channel>
|
||||
<channel lang="hu" xmltv_id="FEM3.hu" site_id="307">Fem 3</channel>
|
||||
<!-- <channel lang="hu" xmltv_id="FilmBoxCentralEurope.us" site_id="226">FilmBox</channel> -->
|
||||
<channel lang="hu" xmltv_id="FilmCafeHungary.hu" site_id="89">Film Café</channel>
|
||||
<channel lang="hu" xmltv_id="FilmMania.hu" site_id="95">Film Mánia</channel>
|
||||
<channel lang="hu" xmltv_id="FilmNowHungary.hu" site_id="245">Film Now</channel>
|
||||
@@ -91,5 +90,6 @@
|
||||
<channel lang="hu" xmltv_id="ViasatExplore.se" site_id="65">Viasat Explore</channel>
|
||||
<channel lang="hu" xmltv_id="ViasatHistory.se" site_id="66">Viasat History</channel>
|
||||
<channel lang="hu" xmltv_id="ViasatNature.se" site_id="223">Viasat Nature</channel>
|
||||
<!-- <channel lang="hu" xmltv_id="" site_id="226">FilmBox</channel> -->
|
||||
</channels>
|
||||
</site>
|
||||
Reference in New Issue
Block a user