From 4a8afcc0ebc7184aacb05d62a9105233e6fd5579 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 30 Apr 2023 05:17:54 +0300 Subject: [PATCH] Create format.js --- scripts/commands/playlist/format.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 scripts/commands/playlist/format.js diff --git a/scripts/commands/playlist/format.js b/scripts/commands/playlist/format.js new file mode 100644 index 000000000..08f3ec921 --- /dev/null +++ b/scripts/commands/playlist/format.js @@ -0,0 +1,26 @@ +const { create: createPlaylist } = require('../../core/playlist') +const { db, logger, file } = require('../../core') +const { orderBy } = require('natural-orderby') +const _ = require('lodash') + +async function main() { + logger.info('loading streams...') + await db.streams.load() + let streams = await db.streams.find({}) + + logger.info('sorting links...') + streams = orderBy( + streams, + ['channel', s => (s.channel ? '' : s.title), 'url'], + ['asc', 'asc', 'asc'] + ) + + logger.info('saving...') + const files = _.groupBy(streams, 'filepath') + for (const filepath in files) { + const playlist = createPlaylist(files[filepath], { public: false }) + await file.create(filepath, playlist.toString()) + } +} + +main()