mirror of
https://github.com/iptv-org/iptv.git
synced 2025-05-12 10:00:05 -04:00
wip
This commit is contained in:
parent
9a4a62fd10
commit
109deb476d
4 changed files with 36 additions and 46 deletions
|
@ -1,6 +1,9 @@
|
|||
const { create: createPlaylist } = require('./playlist')
|
||||
const logger = require('./logger')
|
||||
const file = require('./file')
|
||||
const generators = require('../generators')
|
||||
|
||||
const PUBLIC_DIR = process.env.PUBLIC_DIR || '.gh-pages'
|
||||
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/generators'
|
||||
|
||||
const generator = {}
|
||||
|
@ -8,8 +11,12 @@ const generator = {}
|
|||
generator.generate = async function (name, items = []) {
|
||||
if (typeof generators[name] === 'function') {
|
||||
try {
|
||||
const logs = await generators[name].bind()(items)
|
||||
await file.create(`${LOGS_DIR}/${name}.log`, logs.map(toJSON).join('\n'))
|
||||
const output = await generators[name].bind()(items)
|
||||
await file.create(`${LOGS_DIR}/${name}.log`, output.map(toJSON).join('\n'))
|
||||
for (const type of output) {
|
||||
const playlist = createPlaylist(type.items, { public: true })
|
||||
await file.create(`${PUBLIC_DIR}/${name}/${type.id}.m3u`, playlist.toString())
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`generators/${name}.js: ${error.message}`)
|
||||
}
|
||||
|
@ -18,6 +25,6 @@ generator.generate = async function (name, items = []) {
|
|||
|
||||
module.exports = generator
|
||||
|
||||
function toJSON(item) {
|
||||
return JSON.stringify(item)
|
||||
function toJSON(type) {
|
||||
return JSON.stringify({ id: type.id, count: type.items.length })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue