Create subfolders for commands
This commit is contained in:
66
scripts/commands/playlist/generate.js
Normal file
66
scripts/commands/playlist/generate.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const { db, generator, api, logger, file } = require('../../core')
|
||||
const _ = require('lodash')
|
||||
|
||||
async function main() {
|
||||
const streams = await loadStreams()
|
||||
|
||||
logger.info('generating categories/...')
|
||||
await generator.generate('categories', streams)
|
||||
logger.info('generating countries/...')
|
||||
await generator.generate('countries', streams)
|
||||
logger.info('generating languages/...')
|
||||
await generator.generate('languages', streams)
|
||||
logger.info('generating regions/...')
|
||||
await generator.generate('regions', streams)
|
||||
logger.info('generating index.category.m3u...')
|
||||
await generator.generate('index_category_m3u', streams)
|
||||
logger.info('generating index.country.m3u...')
|
||||
await generator.generate('index_country_m3u', streams)
|
||||
logger.info('generating index.language.m3u...')
|
||||
await generator.generate('index_language_m3u', streams)
|
||||
logger.info('generating index.m3u...')
|
||||
await generator.generate('index_m3u', streams)
|
||||
logger.info('generating index.nsfw.m3u...')
|
||||
await generator.generate('index_nsfw_m3u', streams)
|
||||
logger.info('generating index.region.m3u...')
|
||||
await generator.generate('index_region_m3u', streams)
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
async function loadStreams() {
|
||||
await db.streams.load()
|
||||
let streams = await db.streams.find({ is_broken: false })
|
||||
|
||||
await api.channels.load()
|
||||
let channels = await api.channels.all()
|
||||
channels = _.keyBy(channels, 'id')
|
||||
|
||||
await api.categories.load()
|
||||
let categories = await api.categories.all()
|
||||
categories = _.keyBy(categories, 'id')
|
||||
|
||||
await api.languages.load()
|
||||
let languages = await api.languages.all()
|
||||
languages = _.keyBy(languages, 'code')
|
||||
|
||||
await api.guides.load()
|
||||
let guides = await api.guides.all()
|
||||
guides = _.groupBy(guides, 'channel')
|
||||
|
||||
return streams.map(stream => {
|
||||
const channel = channels[stream.channel_id] || null
|
||||
const filename = file.getFilename(stream.filepath)
|
||||
const [_, code] = filename.match(/^([a-z]{2})(_|$)/) || [null, null]
|
||||
const defaultBroadcastArea = code ? [`c/${code.toUpperCase()}`] : []
|
||||
|
||||
stream.guides = channel && Array.isArray(guides[channel.id]) ? guides[channel.id] : []
|
||||
stream.categories = channel ? channel.categories.map(id => categories[id]) : []
|
||||
stream.languages = channel ? channel.languages.map(id => languages[id]) : []
|
||||
stream.broadcast_area = channel ? channel.broadcast_area : defaultBroadcastArea
|
||||
stream.is_nsfw = channel ? channel.is_nsfw : false
|
||||
stream.logo = channel ? channel.logo : null
|
||||
|
||||
return stream
|
||||
})
|
||||
}
|
21
scripts/commands/playlist/update.js
Normal file
21
scripts/commands/playlist/update.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const { create: createPlaylist } = require('../../core/playlist')
|
||||
const { db, logger, file } = require('../../core')
|
||||
const { orderBy } = require('natural-orderby')
|
||||
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')
|
||||
|
||||
for (const filepath in files) {
|
||||
let items = files[filepath]
|
||||
items = orderBy(items, ['channel_name'], ['asc'])
|
||||
const playlist = createPlaylist(items, { public: false })
|
||||
await file.create(filepath, playlist.toString())
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
67
scripts/commands/playlist/validate.js
Normal file
67
scripts/commands/playlist/validate.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const { file, logger, api, parser, blocklist } = require('../../core')
|
||||
const { program } = require('commander')
|
||||
const chalk = require('chalk')
|
||||
|
||||
program.argument('<filepath>', 'Path to file to validate').parse(process.argv)
|
||||
|
||||
async function main() {
|
||||
await api.channels.load()
|
||||
|
||||
let errors = []
|
||||
let warnings = []
|
||||
for (const filepath of program.args) {
|
||||
if (!filepath.endsWith('.m3u')) continue
|
||||
|
||||
const basename = file.basename(filepath)
|
||||
const [_, countryCode] = basename.match(/([a-z]{2})(|_.*)\.m3u/i) || [null, null]
|
||||
|
||||
const fileLog = []
|
||||
const streams = await parser.parsePlaylist(filepath)
|
||||
for (const stream of streams) {
|
||||
const found = blocklist.find(stream.name, countryCode.toUpperCase())
|
||||
if (found) {
|
||||
fileLog.push({
|
||||
type: 'error',
|
||||
line: stream.line,
|
||||
message: `"${found.name}" is on the blocklist due to claims of copyright holders (${found.reference})`
|
||||
})
|
||||
}
|
||||
|
||||
if (stream.tvg.id && !api.channels.find({ id: stream.tvg.id })) {
|
||||
fileLog.push({
|
||||
type: 'warning',
|
||||
line: stream.line,
|
||||
message: `"${stream.tvg.id}" is not in the database`
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (fileLog.length) {
|
||||
logger.info(`\n${chalk.underline(filepath)}`)
|
||||
|
||||
fileLog.forEach(err => {
|
||||
const position = err.line.toString().padEnd(6, ' ')
|
||||
const type = err.type.padEnd(9, ' ')
|
||||
const status = err.type === 'error' ? chalk.red(type) : chalk.yellow(type)
|
||||
logger.info(` ${chalk.gray(position)}${status}${err.message}`)
|
||||
})
|
||||
|
||||
errors = errors.concat(fileLog.filter(e => e.type === 'error'))
|
||||
warnings = warnings.concat(fileLog.filter(e => e.type === 'warning'))
|
||||
}
|
||||
}
|
||||
|
||||
logger.error(
|
||||
chalk.red(
|
||||
`\n${errors.length + warnings.length} problems (${errors.length} errors, ${
|
||||
warnings.length
|
||||
} warnings)`
|
||||
)
|
||||
)
|
||||
|
||||
if (errors.length) {
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
Reference in New Issue
Block a user