From 6e2cc42bc68cd1c27dfe4b73b74204104afa2ab5 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:25:55 +0300 Subject: [PATCH] Fixes channels:editor script --- scripts/commands/channels/editor.ts | 3 +-- scripts/commands/channels/parse.ts | 7 ++++++- scripts/core/xml.ts | 6 ++---- .../sites/channels-editor/channels-editor.channels.xml | 4 ++++ tests/commands/channels/editor.test.ts | 10 ++++++++++ 5 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml diff --git a/scripts/commands/channels/editor.ts b/scripts/commands/channels/editor.ts index 0867ecf7..dada24c9 100644 --- a/scripts/commands/channels/editor.ts +++ b/scripts/commands/channels/editor.ts @@ -17,7 +17,6 @@ const programOptions = program.opts() const defaultCountry = programOptions.country.toLowerCase() const newLabel = ` [new]` -let site: string let options = new Collection() async function main() { @@ -119,7 +118,7 @@ function save() { .filter((option: { channel: Channel; delete: boolean }) => !option.delete) .map((option: { channel: Channel; delete: boolean }) => option.channel) - const xml = new XML(channels, site) + const xml = new XML(channels) storage.saveSync(filepath, xml.toString()) diff --git a/scripts/commands/channels/parse.ts b/scripts/commands/channels/parse.ts index 63223673..31f80125 100644 --- a/scripts/commands/channels/parse.ts +++ b/scripts/commands/channels/parse.ts @@ -50,6 +50,11 @@ async function main() { if (isPromise(parsedChannels)) { parsedChannels = await parsedChannels } + parsedChannels = parsedChannels.map((channel: Channel) => { + channel.site = config.site + + return channel + }) channels = channels .mergeBy( @@ -62,7 +67,7 @@ async function main() { (channel: Channel) => channel.site_id ]) - const xml = new XML(channels, config.site) + const xml = new XML(channels) await storage.save(outputFilepath, xml.toString()) diff --git a/scripts/core/xml.ts b/scripts/core/xml.ts index 1d7710b1..8c644fa2 100644 --- a/scripts/core/xml.ts +++ b/scripts/core/xml.ts @@ -3,11 +3,9 @@ import { Channel } from 'epg-grabber' export class XML { items: Collection - site: string - constructor(items: Collection, site: string) { + constructor(items: Collection) { this.items = items - this.site = site } toString() { @@ -18,7 +16,7 @@ export class XML { const xmltv_id = channel.xmltv_id || '' const lang = channel.lang || '' const site_id = channel.site_id || '' - output += ` ${escapeString(channel.name)}\r\n` }) diff --git a/tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml b/tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml new file mode 100644 index 00000000..b06024fc --- /dev/null +++ b/tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml @@ -0,0 +1,4 @@ + + + CNN International + diff --git a/tests/commands/channels/editor.test.ts b/tests/commands/channels/editor.test.ts index 2db6ebd3..4482475a 100644 --- a/tests/commands/channels/editor.test.ts +++ b/tests/commands/channels/editor.test.ts @@ -1,6 +1,7 @@ import fs from 'fs-extra' import { execSync } from 'child_process' import os from 'os' +import path from 'path' beforeEach(() => { fs.emptyDirSync('tests/__data__/output') @@ -25,5 +26,14 @@ describe('channels:editor', () => { expect(stdout).toContain('Overwrite') expect(stdout).toContain('Skip') expect(stdout).toContain("File 'tests/__data__/output/channels.xml' successfully saved") + expect(content('tests/__data__/output/channels.xml')).toEqual( + content('tests/__data__/expected/sites/channels-editor/channels-editor.channels.xml') + ) }) }) + +function content(filepath: string) { + return fs.readFileSync(path.resolve(filepath), { + encoding: 'utf8' + }) +}