forked from Mystique-Play/Mystique
Cleanup m3u file workflow
This commit is contained in:
parent
d1e92ec28c
commit
aa6bc59103
2 changed files with 54 additions and 1 deletions
50
.forgejo/scripts/cleanup-m3u.js
Normal file
50
.forgejo/scripts/cleanup-m3u.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
const fs = require('fs');
|
||||
|
||||
function cleanM3u(filePath) {
|
||||
let content = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
// Split into lines and process each line
|
||||
content = content.split('\n')
|
||||
.map(line => {
|
||||
// Trim any whitespace
|
||||
line = line.trim();
|
||||
|
||||
if (line.startsWith('#EXTINF')) {
|
||||
// Replace multiple spaces with single space
|
||||
line = line.replace(/\s+/g, ' ');
|
||||
|
||||
// Remove space before the title (after the comma)
|
||||
line = line.replace(/,\s+/, ',');
|
||||
|
||||
// Remove any extra commas in the line
|
||||
const [extinf, title] = line.split(',');
|
||||
return `${extinf},${title}`;
|
||||
} else {
|
||||
// For non-EXTINF lines, just replace multiple spaces with single space
|
||||
line = line.replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
return line;
|
||||
})
|
||||
.filter(line => line) // Remove empty lines
|
||||
.join('\n');
|
||||
|
||||
// Ensure single newline at end of file
|
||||
content = content.trim() + '\n';
|
||||
|
||||
fs.writeFileSync(filePath, content);
|
||||
console.log('Basic cleanup of mystique.m3u completed');
|
||||
}
|
||||
|
||||
const filePath = process.argv[2];
|
||||
if (!filePath) {
|
||||
console.error('Please provide the path to mystique.m3u');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
cleanM3u(filePath);
|
||||
} catch (error) {
|
||||
console.error('Error cleaning mystique.m3u:', error.message);
|
||||
process.exit(1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue