Update generate-playlists.js

This commit is contained in:
Aleksandr Statciuk 2022-02-08 01:11:47 +03:00
parent 96403d463e
commit 62ce78bbdf
32 changed files with 187 additions and 117 deletions

View file

@ -3,22 +3,23 @@ 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'
const generator = {}
generator.generate = async function (name, items = []) {
generator.generate = async function (name, streams = []) {
if (typeof generators[name] === 'function') {
try {
items = _.orderBy(
items,
streams = orderBy(
streams,
['channel_name', 'status.level', 'resolution.height'],
['asc', 'asc', 'desc']
)
items = _.uniqBy(items, s => s.channel_id || _.uniqueId())
let output = await generators[name].bind()(items)
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) {
const playlist = createPlaylist(type.items, { public: true })