mirror of
https://github.com/iptv-org/epg
synced 2026-05-12 04:14:58 -04:00
Update scripts
This commit is contained in:
@@ -13,20 +13,23 @@ interface GuideData {
|
||||
channels: Collection<Channel>
|
||||
programs: Collection<Program>
|
||||
filepath: string
|
||||
gzip: boolean
|
||||
gzip: boolean | string
|
||||
json: boolean | string
|
||||
}
|
||||
|
||||
export class Guide {
|
||||
channels: Collection<Channel>
|
||||
programs: Collection<Program>
|
||||
filepath: string
|
||||
gzip: boolean
|
||||
gzip: boolean | string
|
||||
json: boolean | string
|
||||
|
||||
constructor(data: GuideData) {
|
||||
this.channels = data.channels
|
||||
this.programs = data.programs
|
||||
this.filepath = data.filepath
|
||||
this.gzip = data.gzip || false
|
||||
this.json = data.json || false
|
||||
}
|
||||
|
||||
addChannel(channel: Channel) {
|
||||
@@ -50,10 +53,21 @@ export class Guide {
|
||||
|
||||
if (this.gzip) {
|
||||
const compressed = pako.gzip(xmltv)
|
||||
const gzFilepath = `${this.filepath}.gz`
|
||||
const gzFilepath = typeof this.gzip === 'string' ? this.gzip : `${this.filepath}.gz`
|
||||
const gzFilename = path.basename(gzFilepath)
|
||||
logger.info(` saving to "${gzFilepath}"...`)
|
||||
await storage.save(gzFilename, compressed)
|
||||
}
|
||||
|
||||
if (this.json) {
|
||||
const filename = path.basename(this.filepath).split('.')[0]
|
||||
const jsonFilepath =
|
||||
typeof this.json === 'string' ? this.json : path.join(dir, `${filename}.json`)
|
||||
const channels = this.channels.map((channel: Channel) => channel.toObject()).all()
|
||||
const programs = this.programs.map((program: Program) => program.toObject()).all()
|
||||
const json = JSON.stringify({ channels, programs })
|
||||
logger.info(` saving to "${jsonFilepath}"...`)
|
||||
await storage.save(jsonFilepath, json)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user