From e2046899e98c652b88cd4f3ce670376031b6f607 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 12 Feb 2022 04:05:31 +0300 Subject: [PATCH] Update playlist/update.js --- scripts/commands/playlist/update.js | 15 ++++++++------- tests/__data__/expected/channels/uk.m3u | 6 +++--- tests/commands/playlist/update.test.js | 9 ++++++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/commands/playlist/update.js b/scripts/commands/playlist/update.js index d613eb5f5..a5ebf2a52 100644 --- a/scripts/commands/playlist/update.js +++ b/scripts/commands/playlist/update.js @@ -5,15 +5,16 @@ const _ = require('lodash') async function main() { await db.streams.load() - let items = await db.streams - .find({}) - .sort({ name: 1, 'status.level': 1, 'resolution.height': -1, url: 1 }) - const files = _.groupBy(items, 'filepath') + let streams = await db.streams.find({}) + streams = orderBy( + streams, + ['channel_name', i => i.status.level, i => i.resolution.height, 'url'], + ['asc', 'asc', 'desc', 'asc'] + ) + const files = _.groupBy(streams, 'filepath') for (const filepath in files) { - let items = files[filepath] - items = orderBy(items, ['channel_name'], ['asc']) - const playlist = createPlaylist(items, { public: false }) + const playlist = createPlaylist(files[filepath], { public: false }) await file.create(filepath, playlist.toString()) } } diff --git a/tests/__data__/expected/channels/uk.m3u b/tests/__data__/expected/channels/uk.m3u index bf1dc35a0..6bd67a0d7 100644 --- a/tests/__data__/expected/channels/uk.m3u +++ b/tests/__data__/expected/channels/uk.m3u @@ -1,5 +1,5 @@ #EXTM3U -#EXTINF:-1 tvg-id="AndorraTV.ad",Andorra TV (720p) [Not 24/7] -http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8 +#EXTINF:-1 tvg-id="BBCNews.uk",BBC News HD (480p) [Geo-blocked] +http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/playlist.m3u8 #EXTINF:-1 tvg-id="BBCNews.uk",BBC News HD (720p) [Not 24/7] -https://query-streamlink.herokuapp.com/iptv-query?streaming-ip=https://www.twitch.tv/absliveantigua3/ +http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8 diff --git a/tests/commands/playlist/update.test.js b/tests/commands/playlist/update.test.js index 3ed52ad64..65cd8d96b 100644 --- a/tests/commands/playlist/update.test.js +++ b/tests/commands/playlist/update.test.js @@ -1,13 +1,16 @@ +const { execSync } = require('child_process') const fs = require('fs-extra') const path = require('path') const glob = require('glob') -const { execSync } = require('child_process') beforeEach(() => { fs.emptyDirSync('tests/__data__/output') - fs.copyFileSync('tests/__data__/input/database/streams.db', 'tests/__data__/output/streams.db') + fs.copyFileSync( + 'tests/__data__/input/database/playlist_update.streams.db', + 'tests/__data__/output/streams.db' + ) - const stdout = execSync('DB_DIR=tests/__data__/output node scripts/commands/playlist/update.js', { + const stdout = execSync('DB_DIR=tests/__data__/output npm run playlist:update', { encoding: 'utf8' }) })