(channels, tvgsById, epgs = {})
| 26 | export const PROGRAM_GAP_PX = 2; |
| 27 | |
| 28 | export function buildChannelIdMap(channels, tvgsById, epgs = {}) { |
| 29 | const map = new Map(); |
| 30 | channels.forEach((channel) => { |
| 31 | const tvgRecord = channel.epg_data_id |
| 32 | ? tvgsById[channel.epg_data_id] |
| 33 | : null; |
| 34 | |
| 35 | // For dummy EPG sources, ALWAYS use channel UUID to ensure unique programs per channel |
| 36 | // This prevents multiple channels with the same dummy EPG from showing identical data |
| 37 | let tvgId; |
| 38 | if (tvgRecord?.epg_source) { |
| 39 | const epgSource = epgs[tvgRecord.epg_source]; |
| 40 | if (epgSource?.source_type === 'dummy') { |
| 41 | // Dummy EPG: use channel UUID for uniqueness |
| 42 | tvgId = channel.uuid; |
| 43 | } else { |
| 44 | // Regular EPG: use tvg_id from EPG data, or fall back to channel UUID |
| 45 | tvgId = tvgRecord.tvg_id ?? channel.uuid; |
| 46 | } |
| 47 | } else { |
| 48 | // No EPG data: use channel UUID |
| 49 | tvgId = channel.uuid; |
| 50 | } |
| 51 | |
| 52 | if (tvgId) { |
| 53 | const tvgKey = String(tvgId); |
| 54 | if (!map.has(tvgKey)) { |
| 55 | map.set(tvgKey, []); |
| 56 | } |
| 57 | map.get(tvgKey).push(channel.id); |
| 58 | } |
| 59 | }); |
| 60 | return map; |
| 61 | } |
| 62 | |
| 63 | export const mapProgramsByChannel = (programs, channelIdByTvgId) => { |
| 64 | if (!programs?.length || !channelIdByTvgId?.size) { |
no test coverage detected