mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
More detailed logs
This commit is contained in:
parent
16ca23efe5
commit
9367c061e9
9 changed files with 60 additions and 40 deletions
|
@ -56,7 +56,7 @@ async function createQueue() {
|
||||||
site_id: item.site_id,
|
site_id: item.site_id,
|
||||||
lang: item.lang,
|
lang: item.lang,
|
||||||
date: undefined,
|
date: undefined,
|
||||||
error: 'Wrong channel ID'
|
error: 'The channel has the wrong xmltv_id'
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,17 @@ main()
|
||||||
async function generateGuides() {
|
async function generateGuides() {
|
||||||
logger.info(`Generating guides/...`)
|
logger.info(`Generating guides/...`)
|
||||||
|
|
||||||
const grouped = groupByGroup(await loadQueue())
|
|
||||||
|
|
||||||
logger.info('Loading "database/programs.db"...')
|
logger.info('Loading "database/programs.db"...')
|
||||||
await db.programs.load()
|
await db.programs.load()
|
||||||
await api.channels.load()
|
await api.channels.load()
|
||||||
|
|
||||||
|
const grouped = groupByGroup(await loadQueue())
|
||||||
for (const key in grouped) {
|
for (const key in grouped) {
|
||||||
const [__, site] = key.split('/')
|
|
||||||
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
||||||
let items = grouped[key]
|
const criticalErrors = []
|
||||||
|
const channels = []
|
||||||
const errors = []
|
let programs = []
|
||||||
for (const item of items) {
|
for (const item of grouped[key]) {
|
||||||
if (item.error) {
|
if (item.error) {
|
||||||
const error = {
|
const error = {
|
||||||
xmltv_id: item.channel.xmltv_id,
|
xmltv_id: item.channel.xmltv_id,
|
||||||
|
@ -38,34 +36,52 @@ async function generateGuides() {
|
||||||
date: item.date,
|
date: item.date,
|
||||||
error: item.error
|
error: item.error
|
||||||
}
|
}
|
||||||
errors.push(error)
|
criticalErrors.push(error)
|
||||||
}
|
await logError(key, error)
|
||||||
}
|
} else {
|
||||||
await logErrors(key, errors)
|
const itemPrograms = await loadProgramsForItem(item)
|
||||||
|
if (!itemPrograms.length) {
|
||||||
|
await logError(key, {
|
||||||
|
xmltv_id: item.channel.xmltv_id,
|
||||||
|
site: item.channel.site,
|
||||||
|
site_id: item.channel.site_id,
|
||||||
|
lang: item.channel.lang,
|
||||||
|
date: item.date,
|
||||||
|
error: 'Programs not found'
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const programs = await loadProgramsForItems(items)
|
const channel = api.channels.find({ id: item.channel.xmltv_id })
|
||||||
let channels = Object.keys(_.groupBy(programs, 'channel'))
|
if (!channel) {
|
||||||
|
await logError(key, {
|
||||||
|
xmltv_id: item.channel.xmltv_id,
|
||||||
|
site: item.channel.site,
|
||||||
|
site_id: item.channel.site_id,
|
||||||
|
lang: item.channel.lang,
|
||||||
|
date: item.date,
|
||||||
|
error: 'The channel has the wrong xmltv_id'
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`Creating "${filepath}"...`)
|
channels.push({
|
||||||
channels = channels
|
|
||||||
.map(id => {
|
|
||||||
const channel = api.channels.find({ id })
|
|
||||||
if (!channel) return null
|
|
||||||
|
|
||||||
return {
|
|
||||||
xmltv_id: channel.id,
|
xmltv_id: channel.id,
|
||||||
name: channel.name,
|
name: channel.name,
|
||||||
logo: channel.logo,
|
logo: channel.logo,
|
||||||
site
|
site: item.channel.site
|
||||||
}
|
})
|
||||||
})
|
|
||||||
.filter(i => i)
|
|
||||||
|
|
||||||
|
programs = programs.concat(itemPrograms)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`Creating "${filepath}"...`)
|
||||||
const output = grabber.convertToXMLTV({ channels, programs })
|
const output = grabber.convertToXMLTV({ channels, programs })
|
||||||
await file.create(filepath, output)
|
await file.create(filepath, output)
|
||||||
|
|
||||||
let status = 0
|
let status = 0
|
||||||
if (errors.length > 0 || !channels.length) {
|
if (criticalErrors.length > 0 || !channels.length) {
|
||||||
status = 1
|
status = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +119,8 @@ async function loadQueue() {
|
||||||
return await db.queue.find({}).sort({ xmltv_id: 1 })
|
return await db.queue.find({}).sort({ xmltv_id: 1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadProgramsForItems(items = []) {
|
async function loadProgramsForItem(item) {
|
||||||
const qids = items.map(i => i._id)
|
return await db.programs.find({ _qid: item._id }).sort({ channel: 1, start: 1 })
|
||||||
|
|
||||||
return await db.programs.find({ _qid: { $in: qids } }).sort({ channel: 1, start: 1 })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setUp() {
|
async function setUp() {
|
||||||
|
@ -119,9 +133,11 @@ async function logGuide(data) {
|
||||||
await file.append(GUIDES_PATH, JSON.stringify(data) + '\r\n')
|
await file.append(GUIDES_PATH, JSON.stringify(data) + '\r\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function logErrors(key, errors) {
|
async function logError(key, data) {
|
||||||
if (!errors.length) return false
|
const filepath = `${LOGS_DIR}/errors/${key}.log`
|
||||||
errors = errors.map(e => JSON.stringify(e)).join('\r\n')
|
if (!(await file.exists(filepath))) {
|
||||||
|
await file.create(filepath)
|
||||||
|
}
|
||||||
|
|
||||||
await file.create(`${LOGS_DIR}/errors/${key}.log`, errors)
|
await file.append(filepath, JSON.stringify(data) + '\r\n')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
{"xmltv_id":"BravoEast.us","site":"directv.com","site_id":"237","lang":"en","date":"2022-01-21T00:00:00Z","error":"Invalid header value char"}
|
|
||||||
{"xmltv_id":"Perviykanal.ru","site":"yandex.ru","site_id":"1","lang":"ru","date":"2022-01-21T00:00:00Z","error":"Some error"}
|
|
|
@ -1 +1 @@
|
||||||
{"xmltv_id":"CNNInternationalEurope2.us","site":"example.com","site_id":"141","lang":"en","error":"Wrong channel ID"}
|
{"xmltv_id":"CNNInternationalEurope2.us","site":"example.com","site_id":"141","lang":"en","error":"The channel has the wrong xmltv_id"}
|
||||||
|
|
1
tests/__data__/expected/logs/errors/ge/magticom.ge.log
Normal file
1
tests/__data__/expected/logs/errors/ge/magticom.ge.log
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"xmltv_id":"CNNInternationalEurope.us","site":"magticom.ge","site_id":"140","lang":"ru","date":"2022-01-21T00:00:00Z","error":"Programs not found"}
|
|
@ -35,7 +35,7 @@ it('can create queue', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can create errors log', () => {
|
it('can log errors', () => {
|
||||||
let output = content('tests/__data__/output/logs/errors/ca-nl/example.com.log')
|
let output = content('tests/__data__/output/logs/errors/ca-nl/example.com.log')
|
||||||
let expected = content('tests/__data__/expected/logs/errors/ca-nl/example.com.log')
|
let expected = content('tests/__data__/expected/logs/errors/ca-nl/example.com.log')
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,11 @@ it('can log errors', () => {
|
||||||
const expected2 = content('tests/__data__/expected/logs/errors/us/directv.com.log')
|
const expected2 = content('tests/__data__/expected/logs/errors/us/directv.com.log')
|
||||||
|
|
||||||
expect(output2).toBe(expected2)
|
expect(output2).toBe(expected2)
|
||||||
|
|
||||||
|
const output3 = content('tests/__data__/output/logs/errors/ge/magticom.ge.log')
|
||||||
|
const expected3 = content('tests/__data__/expected/logs/errors/ge/magticom.ge.log')
|
||||||
|
|
||||||
|
expect(output3).toBe(expected3)
|
||||||
})
|
})
|
||||||
|
|
||||||
function content(filepath) {
|
function content(filepath) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue