mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Add support for absolute output path
Resolves https://github.com/iptv-org/epg/issues/2342
This commit is contained in:
parent
28c8e3d74f
commit
2a0d7cf004
2 changed files with 12 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
||||||
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 path from 'path'
|
||||||
|
|
||||||
type GuideProps = {
|
type GuideProps = {
|
||||||
channels: Collection
|
channels: Collection
|
||||||
|
@ -22,7 +23,7 @@ export class Guide {
|
||||||
this.channels = channels
|
this.channels = channels
|
||||||
this.programs = programs
|
this.programs = programs
|
||||||
this.logger = logger
|
this.logger = logger
|
||||||
this.storage = new Storage()
|
this.storage = new Storage(path.dirname(filepath))
|
||||||
this.filepath = filepath
|
this.filepath = filepath
|
||||||
this.gzip = gzip || false
|
this.gzip = gzip || false
|
||||||
}
|
}
|
||||||
|
@ -43,15 +44,17 @@ export class Guide {
|
||||||
})
|
})
|
||||||
|
|
||||||
const xmlFilepath = this.filepath
|
const xmlFilepath = this.filepath
|
||||||
|
const xmlFilename = path.basename(xmlFilepath)
|
||||||
this.logger.info(` saving to "${xmlFilepath}"...`)
|
this.logger.info(` saving to "${xmlFilepath}"...`)
|
||||||
await this.storage.save(xmlFilepath, xmltv.toString())
|
await this.storage.save(xmlFilename, xmltv.toString())
|
||||||
|
|
||||||
if (this.gzip) {
|
if (this.gzip) {
|
||||||
const zip = new Zip()
|
const zip = new Zip()
|
||||||
const compressed = await zip.compress(xmltv.toString())
|
const compressed = await zip.compress(xmltv.toString())
|
||||||
const gzFilepath = `${this.filepath}.gz`
|
const gzFilepath = `${this.filepath}.gz`
|
||||||
|
const gzFilename = path.basename(gzFilepath)
|
||||||
this.logger.info(` saving to "${gzFilepath}"...`)
|
this.logger.info(` saving to "${gzFilepath}"...`)
|
||||||
await this.storage.save(gzFilepath, compressed)
|
await this.storage.save(gzFilename, compressed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@ beforeEach(() => {
|
||||||
|
|
||||||
describe('epg:grab', () => {
|
describe('epg:grab', () => {
|
||||||
it('can grab epg by site name', () => {
|
it('can grab epg by site name', () => {
|
||||||
const cmd = `${ENV_VAR} npm run grab --- --site=example.com --output=tests/__data__/output/guide.xml`
|
const cmd = `${ENV_VAR} npm run grab --- --site=example.com --output=${path.resolve(
|
||||||
|
'tests/__data__/output/guide.xml'
|
||||||
|
)}`
|
||||||
execSync(cmd, { encoding: 'utf8' })
|
execSync(cmd, { encoding: 'utf8' })
|
||||||
|
|
||||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||||
|
@ -35,7 +37,9 @@ describe('epg:grab', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can grab epg with gzip option enabled', async () => {
|
it('can grab epg with gzip option enabled', async () => {
|
||||||
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=tests/__data__/output/guide.xml --gzip`
|
const cmd = `${ENV_VAR} npm run grab --- --channels=tests/__data__/input/epg-grab/sites/**/*.channels.xml --output=${path.resolve(
|
||||||
|
'tests/__data__/output/guide.xml'
|
||||||
|
)} --gzip`
|
||||||
execSync(cmd, { encoding: 'utf8' })
|
execSync(cmd, { encoding: 'utf8' })
|
||||||
|
|
||||||
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
expect(content('tests/__data__/output/guide.xml')).toEqual(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue