2022-01-09 18:15:38 +03:00
|
|
|
const { db, logger, file, parser } = require('../core')
|
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
2022-01-09 20:14:41 +03:00
|
|
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs'
|
2022-01-09 18:15:38 +03:00
|
|
|
|
|
|
|
|
async function main() {
|
2022-01-21 19:42:27 +03:00
|
|
|
const errorsLog = `${LOGS_DIR}/errors.log`
|
|
|
|
|
await file.create(errorsLog)
|
2022-01-30 02:36:40 +03:00
|
|
|
await db.queue.load()
|
2022-01-15 18:21:51 +03:00
|
|
|
await db.programs.load()
|
2022-01-10 15:00:35 +03:00
|
|
|
await db.programs.reset()
|
2022-01-09 20:14:41 +03:00
|
|
|
const files = await file.list(`${LOGS_DIR}/load-cluster/cluster_*.log`)
|
2022-01-09 18:15:38 +03:00
|
|
|
for (const filepath of files) {
|
2022-01-15 16:59:03 +03:00
|
|
|
logger.info(`Parsing "${filepath}"...`)
|
2022-01-09 18:15:38 +03:00
|
|
|
const results = await parser.parseLogs(filepath)
|
2022-01-15 16:59:03 +03:00
|
|
|
for (const result of results) {
|
2022-01-12 13:27:27 +03:00
|
|
|
const programs = result.programs.map(program => {
|
2022-01-19 02:41:56 +03:00
|
|
|
return {
|
|
|
|
|
title: program.title,
|
|
|
|
|
description: program.description || null,
|
2022-01-21 00:01:07 +03:00
|
|
|
category: program.category || null,
|
2022-01-19 02:41:56 +03:00
|
|
|
season: program.season || null,
|
|
|
|
|
episode: program.episode || null,
|
|
|
|
|
icon: program.icon || null,
|
|
|
|
|
channel: program.channel,
|
|
|
|
|
lang: program.lang,
|
|
|
|
|
start: program.start,
|
|
|
|
|
stop: program.stop,
|
2022-01-21 23:31:37 +03:00
|
|
|
site: result.channel.site,
|
2022-01-21 19:42:27 +03:00
|
|
|
_cid: result.channel._id
|
2022-01-19 02:41:56 +03:00
|
|
|
}
|
2022-01-09 18:15:38 +03:00
|
|
|
})
|
2022-01-15 16:59:03 +03:00
|
|
|
await db.programs.insert(programs)
|
2022-01-21 19:42:27 +03:00
|
|
|
|
2022-01-30 02:36:40 +03:00
|
|
|
await db.queue.update(
|
|
|
|
|
{ _id: result.channel._id },
|
|
|
|
|
{ $set: { programCount: result.programs.length } }
|
|
|
|
|
)
|
2022-01-21 19:42:27 +03:00
|
|
|
|
|
|
|
|
if (result.error) {
|
|
|
|
|
await file.append(
|
|
|
|
|
errorsLog,
|
|
|
|
|
JSON.stringify({ ...result.channel, date: result.date, error: result.error }) + '\n'
|
|
|
|
|
)
|
|
|
|
|
}
|
2022-01-15 16:59:03 +03:00
|
|
|
}
|
2022-01-09 18:15:38 +03:00
|
|
|
}
|
2022-01-16 15:31:06 +03:00
|
|
|
|
2022-01-30 02:36:40 +03:00
|
|
|
await db.queue.compact()
|
2022-01-09 18:15:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main()
|