Enhance program duration calculation and entry creation in channel services and guide

This commit is contained in:
tim000x3 2025-04-16 15:25:38 -04:00
parent 120b966555
commit 48561387b1
2 changed files with 25 additions and 3 deletions

View File

@ -59,8 +59,24 @@ class ChannelService extends events.EventEmitter {
function cleanUpProgram(program) {
delete program.start
delete program.stop
// ▶ If the user set an EndPosition 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 ISOdatetime 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;

View File

@ -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) {