From 7285887f01b356edc8689b9f22f186bc639cc3bc Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 30 Apr 2023 05:48:21 +0300 Subject: [PATCH] Update format.js --- scripts/commands/playlist/format.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/commands/playlist/format.js b/scripts/commands/playlist/format.js index 08f3ec921..557a77a66 100644 --- a/scripts/commands/playlist/format.js +++ b/scripts/commands/playlist/format.js @@ -1,5 +1,5 @@ const { create: createPlaylist } = require('../../core/playlist') -const { db, logger, file } = require('../../core') +const { db, api, logger, file } = require('../../core') const { orderBy } = require('natural-orderby') const _ = require('lodash') @@ -8,6 +8,21 @@ async function main() { await db.streams.load() let streams = await db.streams.find({}) + logger.info(`loading channels...`) + await api.channels.load() + const channels = _.keyBy(await api.channels.all(), 'id') + + logger.info('removing invalid tvg-id...') + streams = streams.map(stream => { + const channel = channels[stream.channel] + + if (!channel) { + stream.channel = null + } + + return stream + }) + logger.info('sorting links...') streams = orderBy( streams,