forked from Mystique-Play/Mystique
Add support for multiline streams
This commit is contained in:
parent
37abcc31ec
commit
5d24fc69fc
1 changed files with 33 additions and 22 deletions
|
@ -124,7 +124,6 @@ function splitByCulturalGroup(filePath) {
|
||||||
.map(file => file.toLowerCase());
|
.map(file => file.toLowerCase());
|
||||||
|
|
||||||
const groups = {};
|
const groups = {};
|
||||||
let currentExtinf = null;
|
|
||||||
|
|
||||||
// Verify M3U header
|
// Verify M3U header
|
||||||
const header = lines[0];
|
const header = lines[0];
|
||||||
|
@ -132,31 +131,43 @@ function splitByCulturalGroup(filePath) {
|
||||||
throw new Error('Invalid M3U file: Missing #EXTM3U header');
|
throw new Error('Invalid M3U file: Missing #EXTM3U header');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process lines
|
// Process the file line by line to handle multi-line entries
|
||||||
lines.forEach(line => {
|
let currentCulturalGroup = null;
|
||||||
line = line.trim();
|
let currentEntry = [];
|
||||||
if (!line) return;
|
let isInEntry = false;
|
||||||
|
|
||||||
|
for (let i = 1; i < lines.length; i++) {
|
||||||
|
const line = lines[i].trim();
|
||||||
|
if (!line) continue;
|
||||||
|
|
||||||
if (line.startsWith('#EXTINF')) {
|
if (line.startsWith('#EXTINF')) {
|
||||||
currentExtinf = line;
|
// Start of a new entry
|
||||||
const culturalGroup = getCulturalGroup(line);
|
isInEntry = true;
|
||||||
|
currentEntry = [line];
|
||||||
|
|
||||||
// Only add to a group if there's a match
|
// Determine cultural group
|
||||||
if (culturalGroup) {
|
currentCulturalGroup = getCulturalGroup(line);
|
||||||
if (!groups[culturalGroup]) {
|
} else if (isInEntry) {
|
||||||
groups[culturalGroup] = ['#EXTM3U'];
|
// Add the line to the current entry
|
||||||
|
currentEntry.push(line);
|
||||||
|
|
||||||
|
// If this is a URL line (doesn't start with #), this completes the entry
|
||||||
|
if (!line.startsWith('#')) {
|
||||||
|
// Add all lines of the entry to the appropriate cultural group
|
||||||
|
if (currentCulturalGroup) {
|
||||||
|
if (!groups[currentCulturalGroup]) {
|
||||||
|
groups[currentCulturalGroup] = ['#EXTM3U'];
|
||||||
}
|
}
|
||||||
groups[culturalGroup].push(line);
|
groups[currentCulturalGroup].push(...currentEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset for the next entry
|
||||||
|
isInEntry = false;
|
||||||
|
currentEntry = [];
|
||||||
|
currentCulturalGroup = null;
|
||||||
}
|
}
|
||||||
} else if (currentExtinf && !line.startsWith('#')) {
|
|
||||||
const culturalGroup = getCulturalGroup(currentExtinf);
|
|
||||||
// Only add the URL line if the channel belonged to a group
|
|
||||||
if (culturalGroup) {
|
|
||||||
groups[culturalGroup].push(line);
|
|
||||||
}
|
}
|
||||||
currentExtinf = null;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Get list of current cultural group files
|
// Get list of current cultural group files
|
||||||
const currentGroupFiles = Object.keys(groups).map(groupTitle =>
|
const currentGroupFiles = Object.keys(groups).map(groupTitle =>
|
||||||
|
@ -179,9 +190,9 @@ function splitByCulturalGroup(filePath) {
|
||||||
console.log(`Created/updated cultural group playlist: ${groupFilePath}`);
|
console.log(`Created/updated cultural group playlist: ${groupFilePath}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Generate summary
|
// Generate summary - count entries properly by counting #EXTINF lines
|
||||||
const summary = Object.entries(groups).map(([group, lines]) => {
|
const summary = Object.entries(groups).map(([group, lines]) => {
|
||||||
const channelCount = (lines.length - 1) / 2; // Subtract header and divide by 2 (EXTINF + URL)
|
const channelCount = lines.filter(line => line.startsWith('#EXTINF')).length;
|
||||||
return `${group}: ${channelCount} channels`;
|
return `${group}: ${channelCount} channels`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue