From aa6bc59103031f328de6ea184aecbf7d1f1a1129 Mon Sep 17 00:00:00 2001 From: SpaceMonkey <> Date: Wed, 29 Jan 2025 18:21:16 +0000 Subject: [PATCH] Cleanup m3u file workflow --- .forgejo/scripts/cleanup-m3u.js | 50 ++++++++++++++++++++++++++++++++ .forgejo/workflows/validate.yaml | 5 +++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .forgejo/scripts/cleanup-m3u.js diff --git a/.forgejo/scripts/cleanup-m3u.js b/.forgejo/scripts/cleanup-m3u.js new file mode 100644 index 0000000..a5c4fce --- /dev/null +++ b/.forgejo/scripts/cleanup-m3u.js @@ -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); +} \ No newline at end of file diff --git a/.forgejo/workflows/validate.yaml b/.forgejo/workflows/validate.yaml index 44a1a7d..8792c01 100644 --- a/.forgejo/workflows/validate.yaml +++ b/.forgejo/workflows/validate.yaml @@ -19,6 +19,9 @@ jobs: - name: Install m3u-linter run: npm install -g m3u-linter + + - name: Basic M3U cleanup + run: node .forgejo/scripts/cleanup-m3u.js mystique.m3u - name: Sort M3U file run: node .forgejo/scripts/sort-m3u.js mystique.m3u @@ -31,4 +34,4 @@ jobs: git config --global user.name 'Forgejo Actions Bot' git config --global user.email 'forgejo-actions[bot]@noreply.forgejo.org' git add mystique.m3u - git diff --quiet && git diff --staged --quiet || (git commit -m "Sort M3U by group-title" && git push) + git diff --quiet && git diff --staged --quiet || (git commit -m "Auto-format and sort M3U file" && git push)