MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / mapProgramsByChannel

Function mapProgramsByChannel

frontend/src/utils/guideUtils.js:63–105  ·  view source on GitHub ↗
(programs, channelIdByTvgId)

Source from the content-addressed store, hash-verified

61}
62
63export const mapProgramsByChannel = (programs, channelIdByTvgId) => {
64 if (!programs?.length || !channelIdByTvgId?.size) {
65 return new Map();
66 }
67
68 const map = new Map();
69 const nowMs = getNowMs();
70
71 programs.forEach((program) => {
72 const channelIds = channelIdByTvgId.get(String(program.tvg_id));
73 if (!channelIds || channelIds.length === 0) {
74 return;
75 }
76
77 const startMs = program.startMs ?? convertToMs(program.start_time);
78 const endMs = program.endMs ?? convertToMs(program.end_time);
79
80 const programData = {
81 ...program,
82 startMs,
83 endMs,
84 programStart: initializeTime(startMs),
85 programEnd: initializeTime(endMs),
86 // Precompute live/past status
87 isLive: nowMs >= startMs && nowMs < endMs,
88 isPast: nowMs >= endMs,
89 };
90
91 // Add this program to all channels that share the same TVG ID
92 channelIds.forEach((channelId) => {
93 if (!map.has(channelId)) {
94 map.set(channelId, []);
95 }
96 map.get(channelId).push(programData);
97 });
98 });
99
100 map.forEach((list) => {
101 list.sort((a, b) => a.startMs - b.startMs);
102 });
103
104 return map;
105};
106
107export function computeRowHeights(
108 filteredChannels,

Callers 1

TVChannelGuideFunction · 0.90

Calls 5

getNowMsFunction · 0.90
convertToMsFunction · 0.90
initializeTimeFunction · 0.90
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected