Files
Nodecast/server/services/builtinEpgRegistry.js
blomios afe91089e5 feat(epg): order EPG sources by priority (#24)
Add persistent EPG priority ordering, source reorder validation, and priority-aware EPG matching for live channels.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-06 11:58:50 +02:00

24 lines
1.4 KiB
JavaScript

const BUILTIN_EPG_SOURCES = Object.freeze([
Object.freeze({ builtinKey: 'epgpw-fr', type: 'epg', name: 'EPG.PW France', url: 'https://epg.pw/xmltv/epg_FR.xml.gz', provider: 'EPG.PW', language: 'fr', country: 'FR' }),
Object.freeze({ builtinKey: 'epgpw-us', type: 'epg', name: 'EPG.PW United States', url: 'https://epg.pw/xmltv/epg_US.xml.gz', provider: 'EPG.PW', language: 'en', country: 'US' })
]);
function protectedFields(source) {
return source?.builtinKey ? { readonly: true, removable: false } : { readonly: false, removable: true };
}
function ensureBuiltinSources(database) {
database.sources ||= [];
const { migrateEpgPriorities, nextEpgPriority } = require('./epgSourceOrdering');
migrateEpgPriorities(database);
for (const definition of BUILTIN_EPG_SOURCES) {
const existing = database.sources.find(source => source.builtinKey === definition.builtinKey);
if (existing) Object.assign(existing, definition, protectedFields(definition));
else database.sources.push({ id: database.nextId++, ...definition, epgPriority: nextEpgPriority(database.sources), ...protectedFields(definition), enabled: false, created_at: new Date().toISOString(), updated_at: new Date().toISOString() });
}
migrateEpgPriorities(database);
return database;
}
module.exports = { BUILTIN_EPG_SOURCES, ensureBuiltinSources, protectedFields };