forked from Mystique-Play/Mystique
M3U order sorting & house keeping
This commit is contained in:
parent
026b25aa2d
commit
52da7a17be
3 changed files with 80 additions and 3 deletions
17
.forgejo/scripts/m3u-linter.config.json
Normal file
17
.forgejo/scripts/m3u-linter.config.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"files": ["mystique.m3u"],
|
||||
"rules": {
|
||||
"no-empty-lines": true,
|
||||
"require-header": true,
|
||||
"attribute-quotes": true,
|
||||
"require-info": true,
|
||||
"require-title": true,
|
||||
"no-trailing-spaces": true,
|
||||
"no-whitespace-before-title": true,
|
||||
"no-multi-spaces": true,
|
||||
"no-extra-comma": true,
|
||||
"space-before-paren": true,
|
||||
"no-dash": true,
|
||||
"require-link": true
|
||||
}
|
||||
}
|
67
.forgejo/scripts/sort-m3u.js
Normal file
67
.forgejo/scripts/sort-m3u.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
const fs = require('fs');
|
||||
|
||||
function sortM3uByGroupTitle(filePath) {
|
||||
// Read the file
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
|
||||
// First line should be #EXTM3U
|
||||
const header = lines[0];
|
||||
if (!header.startsWith('#EXTM3U')) {
|
||||
throw new Error('Invalid M3U file: Missing #EXTM3U header');
|
||||
}
|
||||
|
||||
// Group the entries
|
||||
const entries = [];
|
||||
let currentEntry = [];
|
||||
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
const line = lines[i].trim();
|
||||
if (!line) continue;
|
||||
|
||||
if (line.startsWith('#EXTINF')) {
|
||||
if (currentEntry.length === 2) {
|
||||
entries.push(currentEntry);
|
||||
}
|
||||
currentEntry = [line];
|
||||
} else if (currentEntry.length === 1) {
|
||||
currentEntry.push(line);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the last entry if exists
|
||||
if (currentEntry.length === 2) {
|
||||
entries.push(currentEntry);
|
||||
}
|
||||
|
||||
// Sort entries by group-title
|
||||
entries.sort((a, b) => {
|
||||
const groupTitleA = (a[0].match(/group-title="([^"]*)"/) || [])[1] || '';
|
||||
const groupTitleB = (b[0].match(/group-title="([^"]*)"/) || [])[1] || '';
|
||||
return groupTitleA.localeCompare(groupTitleB);
|
||||
});
|
||||
|
||||
// Rebuild the file content
|
||||
const sortedContent = [
|
||||
header,
|
||||
...entries.flatMap(entry => entry)
|
||||
].join('\n');
|
||||
|
||||
// Write back to file
|
||||
fs.writeFileSync(filePath, sortedContent);
|
||||
console.log('M3U file has been sorted by group-title');
|
||||
}
|
||||
|
||||
// Get file path from command line argument
|
||||
const filePath = process.argv[2];
|
||||
if (!filePath) {
|
||||
console.error('Please provide a file path');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
sortM3uByGroupTitle(filePath);
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message);
|
||||
process.exit(1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue