From 0456c5b9fa9d03eb9327bfba5092e9539561cb4e Mon Sep 17 00:00:00 2001 From: williamwscode Date: Wed, 27 Aug 2025 23:23:45 -0400 Subject: [PATCH 1/6] Add categories testing Add testing for categories tag with provided filter information in API response --- src/xmltv.test.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/xmltv.test.ts b/src/xmltv.test.ts index c324d9b..2350dc0 100644 --- a/src/xmltv.test.ts +++ b/src/xmltv.test.ts @@ -24,7 +24,7 @@ const mockData: GridApiResponse = { endTime: "2025-07-18T20:00:00Z", thumbnail: "p30687311_b_v13_aa", channelNo: "4.1", - filter: ["filter-news"], + filter: ["filter-news", "filter-sports"], seriesId: "SH05918266", rating: "TV-PG", flag: ["New"], @@ -85,6 +85,12 @@ describe("buildXmltv", () => { ); }); + it("should include category information", () => { + const result = buildXmltv(mockData); + expect(result).toContain('news'); + expect(result).toContain('sports'); + }); + it("should include rating information", () => { const result = buildXmltv(mockData); expect(result).toContain( @@ -173,7 +179,7 @@ describe("buildXmltv", () => { expect(result).not.toContain(""); expect(result).not.toContain(""); expect(result).not.toContain(""); - expect(result).not.toContain(""); + expect(result).not.toContain(''); expect(result).not.toContain(" { expect(result).toContain( "BIA performs; comic Zarna Garg; lifestyle contributor Lori Bergamotto; ABC News chief medical correspondent Dr. Tara Narula.", ); + expect(result).toContain('news'); + expect(result).toContain('sports'); expect(result).toContain( 'TV-PG', ); @@ -336,7 +344,7 @@ describe("buildProgramsXml", () => { expect(result).not.toContain(""); expect(result).not.toContain(""); expect(result).not.toContain(""); - expect(result).not.toContain(""); + expect(result).not.toContain(''); expect(result).not.toContain(" Date: Wed, 27 Aug 2025 23:28:54 -0400 Subject: [PATCH 2/6] Added category functionality Added ability to create category XML tags within program based upon filter tags in API response. Includes removal of 'filter-' from the filter parameter provided. --- src/xmltv.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/xmltv.ts b/src/xmltv.ts index c2d1ca8..128d40a 100644 --- a/src/xmltv.ts +++ b/src/xmltv.ts @@ -78,6 +78,15 @@ export function buildProgramsXml(data: GridApiResponse): string { xml += ` ${escapeXml(event.program.shortDesc)}\n`; } + if (event.filter && event.filter.length > 0) { + for (let i = 0; i < event.filter.length; i++) { + const category = event.filter[i].match(/^(filter)-(.*?)$/); + if (category) { + xml += ` ${category[2]}`; + } + } + } + if (event.rating) { xml += ` ${escapeXml( event.rating, From 87274a27f66326b5ff7f189bb99ad27738a33482 Mon Sep 17 00:00:00 2001 From: williamwscode Date: Mon, 8 Sep 2025 18:14:43 -0400 Subject: [PATCH 3/6] Update xmltv.ts Fixed typographic error with bracket --- src/xmltv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmltv.ts b/src/xmltv.ts index 128d40a..f6684e0 100644 --- a/src/xmltv.ts +++ b/src/xmltv.ts @@ -80,7 +80,7 @@ export function buildProgramsXml(data: GridApiResponse): string { if (event.filter && event.filter.length > 0) { for (let i = 0; i < event.filter.length; i++) { - const category = event.filter[i].match(/^(filter)-(.*?)$/); + const category = event.filter(i).match(/^(filter)-(.*?)$/); if (category) { xml += ` ${category[2]}`; } From c8a9b4d8b5bb3ea657f520ba15426c35909829ca Mon Sep 17 00:00:00 2001 From: williamwscode Date: Mon, 8 Sep 2025 18:19:51 -0400 Subject: [PATCH 4/6] Update xmltv.test.ts Fixed typographical error --- src/xmltv.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmltv.test.ts b/src/xmltv.test.ts index 2350dc0..b9e8187 100644 --- a/src/xmltv.test.ts +++ b/src/xmltv.test.ts @@ -344,7 +344,7 @@ describe("buildProgramsXml", () => { expect(result).not.toContain(""); expect(result).not.toContain(""); expect(result).not.toContain(""); - expect(result).not.toContain(''); + expect(result).not.toContain(''); expect(result).not.toContain(" Date: Thu, 11 Sep 2025 21:03:16 -0400 Subject: [PATCH 5/6] Refactored Category Code Refactored code to avoid Build tool thinking there might be an off chance that a filter would be an Undefined Object. Both removed indexing and filtered out any undefined or null values before the loop begins. --- src/xmltv.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/xmltv.ts b/src/xmltv.ts index f6684e0..0958489 100644 --- a/src/xmltv.ts +++ b/src/xmltv.ts @@ -78,11 +78,12 @@ export function buildProgramsXml(data: GridApiResponse): string { xml += ` ${escapeXml(event.program.shortDesc)}\n`; } - if (event.filter && event.filter.length > 0) { - for (let i = 0; i < event.filter.length; i++) { - const category = event.filter(i).match(/^(filter)-(.*?)$/); + const filters = event.filter?.filter(item => item); + if (filters?.length) { + for (const filter of filters) { + const category = filter.match(/^(filter)-(.*?)$/); if (category) { - xml += ` ${category[2]}`; + xml += ' ${category[2]}`; } } } From 62764aaa5b60d8e815bb7cfc476fb0a86f5afd46 Mon Sep 17 00:00:00 2001 From: williamwscode Date: Thu, 11 Sep 2025 21:06:28 -0400 Subject: [PATCH 6/6] Fixed grave symbol Fixed usage of grave instead of single quote to maintain consistency. --- src/xmltv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xmltv.ts b/src/xmltv.ts index 0958489..4d0f3a8 100644 --- a/src/xmltv.ts +++ b/src/xmltv.ts @@ -83,7 +83,7 @@ export function buildProgramsXml(data: GridApiResponse): string { for (const filter of filters) { const category = filter.match(/^(filter)-(.*?)$/); if (category) { - xml += ' ${category[2]}`; + xml += ` ${category[2]}`; } } }