forked from Mystique-Play/Mystique
Update .forgejo/scripts/cleanup-m3u.js
This commit is contained in:
parent
f0244a685a
commit
69e15a2d20
1 changed files with 42 additions and 37 deletions
|
@ -13,12 +13,16 @@ function cleanM3u(filePath) {
|
||||||
// Replace multiple spaces with single space
|
// Replace multiple spaces with single space
|
||||||
line = line.replace(/\s+/g, ' ');
|
line = line.replace(/\s+/g, ' ');
|
||||||
|
|
||||||
// Remove space before the title (after the comma)
|
// Instead of splitting by comma, find the position of the first comma
|
||||||
line = line.replace(/,\s+/, ',');
|
// This preserves the channel name and any commas it might contain
|
||||||
|
const firstCommaPos = line.indexOf(',');
|
||||||
|
|
||||||
|
if (firstCommaPos !== -1) {
|
||||||
|
const extinf = line.substring(0, firstCommaPos);
|
||||||
|
const title = line.substring(firstCommaPos + 1).trim(); // Trim space after comma
|
||||||
|
|
||||||
// Remove any extra commas in the line
|
|
||||||
const [extinf, title] = line.split(',');
|
|
||||||
return `${extinf},${title}`;
|
return `${extinf},${title}`;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// For non-EXTINF lines, just replace multiple spaces with single space
|
// For non-EXTINF lines, just replace multiple spaces with single space
|
||||||
line = line.replace(/\s+/g, ' ');
|
line = line.replace(/\s+/g, ' ');
|
||||||
|
@ -37,6 +41,7 @@ function cleanM3u(filePath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const filePath = process.argv[2];
|
const filePath = process.argv[2];
|
||||||
|
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
console.error('Please provide the path to mystique.m3u');
|
console.error('Please provide the path to mystique.m3u');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue