mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Fixes incorrect date when loading the guide
This commit is contained in:
parent
daf0cb03b4
commit
7237ba0f1e
4 changed files with 31 additions and 31 deletions
|
@ -77,41 +77,41 @@ async function main() {
|
||||||
if (options.lang) {
|
if (options.lang) {
|
||||||
parsedChannels = parsedChannels.filter((channel: Channel) => channel.lang === options.lang)
|
parsedChannels = parsedChannels.filter((channel: Channel) => channel.lang === options.lang)
|
||||||
}
|
}
|
||||||
logger.info(` found ${parsedChannels.count()} channels`)
|
logger.info(` found ${parsedChannels.count()} channel(s)`)
|
||||||
|
|
||||||
|
let runIndex = 1
|
||||||
|
if (options.cron) {
|
||||||
|
const cronJob = new CronJob(options.cron, async () => {
|
||||||
|
logger.info(`run #${runIndex}:`)
|
||||||
|
await runJob({ logger, parsedChannels })
|
||||||
|
runIndex++
|
||||||
|
})
|
||||||
|
cronJob.start()
|
||||||
|
} else {
|
||||||
|
logger.info(`run #${runIndex}:`)
|
||||||
|
runJob({ logger, parsedChannels })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
||||||
|
async function runJob({ logger, parsedChannels }: { logger: Logger; parsedChannels: Collection }) {
|
||||||
|
const timer = new Timer()
|
||||||
|
timer.start()
|
||||||
|
|
||||||
logger.info('creating queue...')
|
|
||||||
const queueCreator = new QueueCreator({
|
const queueCreator = new QueueCreator({
|
||||||
parsedChannels,
|
parsedChannels,
|
||||||
logger,
|
logger,
|
||||||
options
|
options
|
||||||
})
|
})
|
||||||
const queue = await queueCreator.create()
|
const queue = await queueCreator.create()
|
||||||
logger.info(` added ${queue.size()} items`)
|
|
||||||
|
|
||||||
const job = new Job({
|
const job = new Job({
|
||||||
queue,
|
queue,
|
||||||
logger,
|
logger,
|
||||||
options
|
options
|
||||||
})
|
})
|
||||||
|
|
||||||
let runIndex = 1
|
await job.run()
|
||||||
if (options.cron) {
|
|
||||||
const cronJob = new CronJob(options.cron, async () => {
|
|
||||||
logger.info(`run #${runIndex}:`)
|
|
||||||
const timer = new Timer()
|
|
||||||
timer.start()
|
|
||||||
await job.run()
|
|
||||||
runIndex++
|
|
||||||
logger.success(` done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
|
||||||
})
|
|
||||||
cronJob.start()
|
|
||||||
} else {
|
|
||||||
logger.info(`run #${runIndex}:`)
|
|
||||||
const timer = new Timer()
|
|
||||||
timer.start()
|
|
||||||
await job.run()
|
|
||||||
logger.success(` done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
logger.success(` done in ${timer.format('HH[h] mm[m] ss[s]')}`)
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
export const SITES_DIR = process.env.SITES_DIR || './sites'
|
export const SITES_DIR = process.env.SITES_DIR || './sites'
|
||||||
export const GUIDES_DIR = process.env.GUIDES_DIR || './guides'
|
export const GUIDES_DIR = process.env.GUIDES_DIR || './guides'
|
||||||
export const DATA_DIR = process.env.DATA_DIR || './temp/data'
|
export const DATA_DIR = process.env.DATA_DIR || './temp/data'
|
||||||
export const CURR_DATE = process.env.CURR_DATE || new Date().toISOString()
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Collection, Logger, DateTime, Storage, Zip } from '@freearhey/core'
|
import { Collection, Logger, DateTime, Storage, Zip } from '@freearhey/core'
|
||||||
import { Channel } from 'epg-grabber'
|
import { Channel } from 'epg-grabber'
|
||||||
import { XMLTV } from '../core'
|
import { XMLTV } from '../core'
|
||||||
import { CURR_DATE } from '../constants'
|
|
||||||
|
|
||||||
type GuideProps = {
|
type GuideProps = {
|
||||||
channels: Collection
|
channels: Collection
|
||||||
|
@ -34,10 +33,13 @@ export class Guide {
|
||||||
)
|
)
|
||||||
const programs = this.programs
|
const programs = this.programs
|
||||||
|
|
||||||
|
const currDate = new DateTime(process.env.CURR_DATE || new Date().toISOString(), {
|
||||||
|
zone: 'UTC'
|
||||||
|
})
|
||||||
const xmltv = new XMLTV({
|
const xmltv = new XMLTV({
|
||||||
channels,
|
channels,
|
||||||
programs,
|
programs,
|
||||||
date: new DateTime(CURR_DATE, { zone: 'UTC' })
|
date: currDate
|
||||||
})
|
})
|
||||||
|
|
||||||
const xmlFilepath = this.filepath
|
const xmlFilepath = this.filepath
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Storage, Collection, DateTime, Logger } from '@freearhey/core'
|
import { Storage, Collection, DateTime, Logger } from '@freearhey/core'
|
||||||
import { ChannelsParser, ConfigLoader, ApiChannel, Queue } from './'
|
import { ChannelsParser, ConfigLoader, ApiChannel, Queue } from './'
|
||||||
import { SITES_DIR, DATA_DIR, CURR_DATE } from '../constants'
|
import { SITES_DIR, DATA_DIR } from '../constants'
|
||||||
import { SiteConfig } from 'epg-grabber'
|
import { SiteConfig } from 'epg-grabber'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { GrabOptions } from '../commands/epg/grab'
|
import { GrabOptions } from '../commands/epg/grab'
|
||||||
|
@ -19,7 +19,6 @@ export class QueueCreator {
|
||||||
parser: ChannelsParser
|
parser: ChannelsParser
|
||||||
parsedChannels: Collection
|
parsedChannels: Collection
|
||||||
options: GrabOptions
|
options: GrabOptions
|
||||||
date: DateTime
|
|
||||||
|
|
||||||
constructor({ parsedChannels, logger, options }: QueueCreatorProps) {
|
constructor({ parsedChannels, logger, options }: QueueCreatorProps) {
|
||||||
this.parsedChannels = parsedChannels
|
this.parsedChannels = parsedChannels
|
||||||
|
@ -27,7 +26,6 @@ export class QueueCreator {
|
||||||
this.sitesStorage = new Storage()
|
this.sitesStorage = new Storage()
|
||||||
this.dataStorage = new Storage(DATA_DIR)
|
this.dataStorage = new Storage(DATA_DIR)
|
||||||
this.parser = new ChannelsParser({ storage: new Storage() })
|
this.parser = new ChannelsParser({ storage: new Storage() })
|
||||||
this.date = new DateTime(CURR_DATE)
|
|
||||||
this.options = options
|
this.options = options
|
||||||
this.configLoader = new ConfigLoader()
|
this.configLoader = new ConfigLoader()
|
||||||
}
|
}
|
||||||
|
@ -52,7 +50,8 @@ export class QueueCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
const days = this.options.days || config.days || 1
|
const days = this.options.days || config.days || 1
|
||||||
const dates = Array.from({ length: days }, (_, day) => this.date.add(day, 'd'))
|
const currDate = new DateTime(process.env.CURR_DATE || new Date().toISOString())
|
||||||
|
const dates = Array.from({ length: days }, (_, day) => currDate.add(day, 'd'))
|
||||||
dates.forEach((date: DateTime) => {
|
dates.forEach((date: DateTime) => {
|
||||||
const dateString = date.toJSON()
|
const dateString = date.toJSON()
|
||||||
const key = `${channel.site}:${channel.lang}:${channel.xmltv_id}:${dateString}`
|
const key = `${channel.site}:${channel.lang}:${channel.xmltv_id}:${dateString}`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue