From 48561387b10370742f07c59eb4128b801f48d23d Mon Sep 17 00:00:00 2001 From: tim000x3 Date: Wed, 16 Apr 2025 15:25:38 -0400 Subject: [PATCH] Enhance program duration calculation and entry creation in channel services and guide --- src/services/channel-service.js | 20 ++++++++++++++++++-- src/services/tv-guide-service.js | 8 +++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/services/channel-service.js b/src/services/channel-service.js index cffcf70..4a0e392 100644 --- a/src/services/channel-service.js +++ b/src/services/channel-service.js @@ -59,8 +59,24 @@ class ChannelService extends events.EventEmitter { function cleanUpProgram(program) { - delete program.start - delete program.stop + // ▶ If the user set an End‑Position in the EPG modal, shrink duration + if (program.endPosition != null && program.endPosition !== '') { + const end = parseInt(program.endPosition, 10); + const start = program.startPosition != null && program.startPosition !== '' + ? parseInt(program.startPosition, 10) + : 0; + if (!Number.isNaN(end) && end > start) { + program.duration = end - start; + if (program.start) { + program.stop = new Date(new Date(program.start).getTime() + (end - start)).toISOString(); + } + } + } + + // ▶ Your manual ISO‑datetime override (if you ever wire up true start/stop) + if (program.start && program.stop) { + program.duration = new Date(program.stop) - new Date(program.start); + } delete program.streams; delete program.durationStr; delete program.commercials; diff --git a/src/services/tv-guide-service.js b/src/services/tv-guide-service.js index 1b33c54..2f96cd9 100644 --- a/src/services/tv-guide-service.js +++ b/src/services/tv-guide-service.js @@ -571,7 +571,7 @@ function makeEntry(channel, x) { title="."; } //what data is needed here? - return { + let entry = { start: (new Date(x.start)).toISOString(), stop: (new Date(x.start + x.program.duration)).toISOString(), summary: x.program.summary, @@ -581,6 +581,12 @@ function makeEntry(channel, x) { title: title, sub: sub, } + const seek = typeof x.program.seekPosition === 'number' ? x.program.seekPosition : 0; + const endPos = typeof x.program.endPosition === 'number' ? x.program.endPosition : x.program.duration; + const effectiveDuration = endPos - seek; + // use effectiveDuration instead of full duration + entry.stop = new Date(new Date(entry.start).getTime() + effectiveDuration).toISOString(); + return entry; } function formatDateYYYYMMDD(date) {