From 7e811f4c33402cd7a97c90a7a10b6a1d213d8c25 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 16 Sep 2021 04:26:25 +0300 Subject: [PATCH] Update db.js --- scripts/helpers/db.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/db.js b/scripts/helpers/db.js index 859a41576d..20c8ff7f12 100644 --- a/scripts/helpers/db.js +++ b/scripts/helpers/db.js @@ -2,15 +2,22 @@ const categories = require('../data/categories') const parser = require('./parser') const utils = require('./utils') const file = require('./file') +const epg = require('./epg') const db = {} db.load = async function () { - let files = await file.list() + const files = await file.list() + const codes = await epg.codes.load() for (const file of files) { const playlist = await parser.parsePlaylist(file) - db.playlists.add(playlist) + let guides = [] for (const channel of playlist.channels) { + const code = codes.find(ch => ch['tvg_id'] === channel.tvg.id) + if (code && Array.isArray(code.guides)) { + guides = [...guides, ...code.guides] + } + db.channels.add(channel) for (const country of channel.countries) { @@ -25,6 +32,10 @@ db.load = async function () { } } } + + if (guides.length) playlist.header.attrs['url-tvg'] = guides.join(',') + + db.playlists.add(playlist) } }