feat: run full refresh with EPG rematching
Run full live catalog refreshes through live source sync, complete channel analysis, EPG source refresh, and persisted EPG rematching while keeping check-new incremental. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -58,4 +58,54 @@ function findBestMatch(database, channel, epgSources, now = Date.now()) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { candidateScore, chooseBestMatch, findBestMatch, normalize };
|
||||
function rebuildPersistedEpgMatches(database, epgSources, now = Date.now()) {
|
||||
const rows = database.prepare(`
|
||||
SELECT p.*, l.display_name, c.name AS category_name
|
||||
FROM playlist_items p
|
||||
JOIN logical_channels l ON l.id = p.logical_channel_id
|
||||
LEFT JOIN categories c ON c.source_id = p.source_id AND c.type = 'live' AND c.category_id = p.category_id
|
||||
WHERE p.type = 'live' AND p.logical_channel_id IS NOT NULL
|
||||
ORDER BY p.logical_channel_id, p.language_code, p.variant_rank
|
||||
`).all();
|
||||
const groups = new Map();
|
||||
for (const row of rows) {
|
||||
const languageCode = row.language_code || 'und';
|
||||
const key = `${row.logical_channel_id}\0${languageCode}`;
|
||||
if (!groups.has(key)) groups.set(key, {
|
||||
logicalChannelId: row.logical_channel_id,
|
||||
displayName: row.display_name,
|
||||
standardName: row.display_name,
|
||||
language: { code: languageCode },
|
||||
variants: []
|
||||
});
|
||||
let data = {};
|
||||
try { data = row.data ? JSON.parse(row.data) : {}; } catch {}
|
||||
groups.get(key).variants.push({
|
||||
name: row.name,
|
||||
tvgId: data.tvgId || data.tvg_id || null,
|
||||
epg_channel_id: data.epg_channel_id || null
|
||||
});
|
||||
}
|
||||
const replace = database.prepare(`
|
||||
INSERT INTO live_epg_matches
|
||||
(logical_channel_id, language_code, source_id, channel_id, match_confidence, data, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(logical_channel_id, language_code) DO UPDATE SET
|
||||
source_id = excluded.source_id, channel_id = excluded.channel_id,
|
||||
match_confidence = excluded.match_confidence, data = excluded.data,
|
||||
updated_at = excluded.updated_at
|
||||
`);
|
||||
const persist = database.transaction(() => {
|
||||
database.prepare('DELETE FROM live_epg_matches').run();
|
||||
for (const channel of groups.values()) {
|
||||
const match = findBestMatch(database, channel, epgSources, now);
|
||||
replace.run(channel.logicalChannelId, channel.language.code,
|
||||
match?.sourceId ?? null, match?.channelId ?? null,
|
||||
match?.matchConfidence ?? 0, match ? JSON.stringify(match) : null, now);
|
||||
}
|
||||
});
|
||||
persist();
|
||||
return { matched: [...groups.values()].length };
|
||||
}
|
||||
|
||||
module.exports = { candidateScore, chooseBestMatch, findBestMatch, normalize, rebuildPersistedEpgMatches };
|
||||
|
||||
Reference in New Issue
Block a user