Update playlist/generate.js

This commit is contained in:
Aleksandr Statciuk 2022-02-12 03:11:55 +03:00
parent 0d1ab5dfe9
commit 081fcac929
17 changed files with 273 additions and 274 deletions

View file

@ -1,4 +1,5 @@
const { db, generator, api, logger, file } = require('../../core')
const { orderBy } = require('natural-orderby')
const _ = require('lodash')
async function main() {
@ -31,6 +32,12 @@ main()
async function loadStreams() {
await db.streams.load()
let streams = await db.streams.find({ is_broken: false })
streams = _.orderBy(
streams,
['channel_name', 'status.level', 'resolution.height', 'url'],
['asc', 'asc', 'desc', 'asc']
)
streams = _.uniqBy(streams, stream => stream.channel_id || _.uniqueId())
await api.channels.load()
let channels = await api.channels.all()

View file

@ -1,9 +1,7 @@
const { create: createPlaylist } = require('./playlist')
const generators = require('../generators')
const logger = require('./logger')
const file = require('./file')
const generators = require('../generators')
const _ = require('lodash')
const { orderBy } = require('natural-orderby')
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/generators'
@ -13,12 +11,6 @@ const generator = {}
generator.generate = async function (name, streams = []) {
if (typeof generators[name] === 'function') {
try {
streams = orderBy(
streams,
['channel_name', 'status.level', 'resolution.height'],
['asc', 'asc', 'desc']
)
streams = _.uniqBy(streams, stream => stream.channel_id || _.uniqueId())
let output = await generators[name].bind()(streams)
output = Array.isArray(output) ? output : [output]
for (const type of output) {