Update scripts

This commit is contained in:
freearhey
2026-05-03 21:37:49 +03:00
parent 56ccf2ac1b
commit 56a228e9cb
5 changed files with 84 additions and 18 deletions

View File

@@ -54,7 +54,10 @@ program
.argParser(parseNumber)
.env('MAX_CONNECTIONS')
)
.addOption(new Option('--gzip', 'Create a compressed version of the guide as well').env('GZIP'))
.addOption(
new Option('--gzip [path]', 'Create a compressed version of the guide as well').env('GZIP')
)
.addOption(new Option('--json [path]', 'Create a JSON version of the guide as well').env('JSON'))
.addOption(new Option('--curl', 'Display each request as CURL').env('CURL'))
.addOption(new Option('--debug', 'Enable debug mode').env('DEBUG'))
.parse()
@@ -63,7 +66,8 @@ interface GrabOptions {
sites?: string[]
channels?: string
output?: string
gzip?: boolean
gzip?: boolean | string
json?: boolean | string
curl?: boolean
debug?: boolean
maxConnections?: number
@@ -109,7 +113,10 @@ async function main() {
if (typeof options.maxConnections === 'number')
globalConfig.maxConnections = options.maxConnections
if (typeof options.curl === 'boolean') globalConfig.curl = options.curl
if (typeof options.gzip === 'boolean') globalConfig.gzip = options.gzip
if (typeof options.gzip === 'boolean' || typeof options.gzip === 'string')
globalConfig.gzip = options.gzip
if (typeof options.json === 'boolean' || typeof options.json === 'string')
globalConfig.json = options.json
if (typeof options.debug === 'boolean') globalConfig.debug = options.debug
logger.debug(`config: ${JSON.stringify(globalConfig, null, 2)}`)
@@ -298,6 +305,7 @@ async function main() {
})
const gzip = globalConfig.gzip || defaultConfig.gzip
const json = globalConfig.json || defaultConfig.json
for (const groupKey of channelsGroupedByKey.keys()) {
const groupChannels = new Collection(channelsGroupedByKey.get(groupKey))
@@ -305,6 +313,7 @@ async function main() {
const guide = new Guide({
filepath: groupKey,
gzip,
json,
channels: groupChannels,
programs: groupPrograms
})

View File

@@ -61,7 +61,10 @@ async function main() {
}
worker.channelsPath = workerJson.channels
worker.guidePath = workerJson.guide
worker.guideXmlPath =
typeof workerJson.guide === 'string' ? workerJson.guide : workerJson?.guide?.xml
worker.guideGzipPath = workerJson?.guide?.gzip
worker.guideJsonPath = workerJson?.guide?.json
if (!worker.channelsPath) {
worker.status = 'MISSING_CHANNELS_PATH'
@@ -69,8 +72,8 @@ async function main() {
continue
}
if (!worker.guidePath) {
worker.status = 'MISSING_GUIDE_PATH'
if (!worker.guideXmlPath) {
worker.status = 'MISSING_GUIDE_XML_PATH'
logger.error('The "guide" property is missing from the workers config')
continue
}
@@ -91,7 +94,7 @@ async function main() {
)
const guideXml = await client
.get(worker.guidePath)
.get(worker.guideXmlPath)
.then(res => res.data)
.catch(err => {
worker.status = err.status
@@ -109,6 +112,7 @@ async function main() {
logger.info('creating guides table...')
const rows = new Collection<HTMLTableRow>()
workers.forEach((worker: Worker) => {
const links = worker.getLinks()
rows.add(
new Collection<HTMLTableDataItem>([
{ value: worker.host },
@@ -116,10 +120,9 @@ async function main() {
{ value: worker.getChannelsCount().toString(), align: 'right' },
{ value: worker.getLastUpdated(), align: 'left' },
{
value:
worker.status === 'OK'
? `<a href="${worker.getChannelsUrl()}">${worker.channelsPath}</a><br><a href="${worker.getGuideUrl()}">${worker.guidePath}</a>`
: ''
value: links.length
? links.map(link => `<a href="${link.url}">${link.label}</a>`).join(' | ')
: '-'
}
])
)