refactor: use Xtream API endpoints for M3U channel loading

This commit is contained in:
Trevor Mears
2026-01-12 00:02:16 -08:00
parent a86f9ca878
commit 04fcabda84
+18 -14
View File
@@ -812,6 +812,7 @@ class ChannelList {
/** /**
* Load M3U channels * Load M3U channels
* Now uses unified Xtream-style API endpoints (backend supports both source types)
*/ */
async loadM3uChannels(sourceId, append = false) { async loadM3uChannels(sourceId, append = false) {
if (!append) { if (!append) {
@@ -819,27 +820,30 @@ class ChannelList {
this.groups = []; this.groups = [];
} }
const data = await API.proxy.m3u.get(sourceId); // Use Xtream API endpoints - backend now supports M3U sources too
const categories = await API.proxy.xtream.liveCategories(sourceId);
const streams = await API.proxy.xtream.liveStreams(sourceId);
// Add groups // Map categories to groups (keeping m3u sourceType for downstream compatibility)
const m3uGroups = data.groups.map(g => ({ const m3uGroups = categories.map(cat => ({
...g, id: `m3u_${sourceId}_${cat.category_id}`,
id: `m3u_${sourceId}_${g.id}`, name: cat.category_name,
sourceId, sourceId,
sourceType: 'm3u' sourceType: 'm3u'
})); }));
this.groups = this.groups.concat(m3uGroups); this.groups = this.groups.concat(m3uGroups);
// Add channels - use the stable id from the server // Map streams to channels
const channelList = data.channels.map(ch => ({ const channelList = streams.map(stream => ({
...ch, id: `m3u_${sourceId}_${stream.stream_id}`,
// Use the stable id provided by the server (from tvgId or hash) streamId: stream.stream_id,
// Prefix with sourceId to ensure global uniqueness across multiple M3U sources name: stream.name,
id: `m3u_${sourceId}_${ch.id}`, tvgId: stream.epg_channel_id,
// Keep original ID as streamId if needed (or just use original ID for reference) tvgLogo: stream.stream_icon,
streamId: ch.id, url: stream.stream_url, // M3U has direct URLs
groupId: `m3u_${sourceId}_group_${data.groups.findIndex(g => g.name === ch.groupTitle)}`, groupId: `m3u_${sourceId}_${stream.category_id}`,
groupTitle: categories.find(c => String(c.category_id) === String(stream.category_id))?.category_name || 'Uncategorized',
sourceId, sourceId,
sourceType: 'm3u' sourceType: 'm3u'
})); }));