forked from Mystique/Mystique
Workflow improvements
This commit is contained in:
parent
8dee5cbec5
commit
133682c6b0
3 changed files with 84 additions and 2 deletions
59
.forgejo/scripts/readme-m3u.js
Normal file
59
.forgejo/scripts/readme-m3u.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function updateReadme(m3uPath) {
|
||||
// Get list of group files
|
||||
const groupsDir = path.join(path.dirname(m3uPath), 'countries');
|
||||
const groups = {};
|
||||
|
||||
// Read the main M3U to get original group names and channel counts
|
||||
const content = fs.readFileSync(m3uPath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
let totalChannels = 0;
|
||||
|
||||
lines.forEach(line => {
|
||||
if (line.startsWith('#EXTINF')) {
|
||||
totalChannels++;
|
||||
const groupMatch = line.match(/group-title="([^"]*)"/);
|
||||
const groupTitle = groupMatch ? groupMatch[1] : 'Unknown';
|
||||
groups[groupTitle] = (groups[groupTitle] || 0) + 1;
|
||||
}
|
||||
});
|
||||
|
||||
// Start building README content
|
||||
let readmeContent = '# Mystique IPTV\n\n';
|
||||
readmeContent += '## Available Playlists\n\n';
|
||||
readmeContent += '| Playlist | Channels | Link |\n';
|
||||
readmeContent += '|----------|-----------|------|\n';
|
||||
|
||||
// Add main playlist first
|
||||
const mainPlaylistName = path.basename(m3uPath);
|
||||
readmeContent += `| **Complete (All countries)** | ${totalChannels} | [${mainPlaylistName}](${mainPlaylistName}) |\n`;
|
||||
|
||||
// Sort groups alphabetically
|
||||
const sortedGroups = Object.entries(groups).sort((a, b) => a[0].localeCompare(b[0]));
|
||||
|
||||
// Add each group to the table
|
||||
sortedGroups.forEach(([groupName, channelCount]) => {
|
||||
const safeGroupName = groupName.replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
||||
readmeContent += `| ${groupName} | ${channelCount} | [${safeGroupName}.m3u](countries/${safeGroupName}.m3u) |\n`;
|
||||
});
|
||||
|
||||
const readmePath = path.join(path.dirname(m3uPath), 'README.md');
|
||||
|
||||
fs.writeFileSync(readmePath, readmeContent);
|
||||
console.log('README.md has been updated with playlist and group information');
|
||||
}
|
||||
|
||||
const filePath = process.argv[2];
|
||||
if (!filePath) {
|
||||
console.error('Please provide the path to mystique.m3u');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
updateReadme(filePath);
|
||||
} catch (error) {
|
||||
console.error('Error updating README:', error.message);
|
||||
process.exit(1);
|
||||
}
|
|
@ -11,6 +11,11 @@ function splitByGroup(filePath) {
|
|||
fs.mkdirSync(groupsDir);
|
||||
}
|
||||
|
||||
// Get existing country files
|
||||
const existingFiles = fs.readdirSync(groupsDir)
|
||||
.filter(file => file.endsWith('.m3u'))
|
||||
.map(file => file.toLowerCase());
|
||||
|
||||
const groups = {};
|
||||
let currentExtinf = null;
|
||||
|
||||
|
@ -43,12 +48,26 @@ function splitByGroup(filePath) {
|
|||
}
|
||||
});
|
||||
|
||||
// Get list of current group files that should exist
|
||||
const currentGroupFiles = Object.keys(groups).map(groupTitle =>
|
||||
`${groupTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase()}.m3u`
|
||||
);
|
||||
|
||||
// Remove files for groups that no longer exist
|
||||
existingFiles.forEach(existingFile => {
|
||||
if (!currentGroupFiles.includes(existingFile)) {
|
||||
const fileToRemove = path.join(groupsDir, existingFile);
|
||||
fs.unlinkSync(fileToRemove);
|
||||
console.log(`Removed obsolete group playlist: ${existingFile}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Write each group to a separate file
|
||||
Object.entries(groups).forEach(([groupTitle, groupLines]) => {
|
||||
const safeGroupTitle = groupTitle.replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
||||
const groupFilePath = path.join(groupsDir, `${safeGroupTitle}.m3u`);
|
||||
fs.writeFileSync(groupFilePath, groupLines.join('\n') + '\n');
|
||||
console.log(`Created group playlist: ${groupFilePath}`);
|
||||
console.log(`Created/updated group playlist: ${groupFilePath}`);
|
||||
});
|
||||
|
||||
// Create a summary of the split
|
||||
|
|
|
@ -32,10 +32,14 @@ jobs:
|
|||
- name: Split into group playlists
|
||||
run: node .forgejo/scripts/split-m3u.js mystique.m3u
|
||||
|
||||
- name: Update README
|
||||
run: node .forgejo/scripts/readme-m3u.js mystique.m3u
|
||||
|
||||
|
||||
- name: Commit changes to files
|
||||
run: |
|
||||
git config --global user.name 'Forgejo Actions Bot'
|
||||
git config --global user.email 'forgejo-actions[bot]@noreply.forgejo.org'
|
||||
git add .
|
||||
git add --all
|
||||
git diff --quiet && git diff --staged --quiet || (git commit -m "Automated updates of M3U Files" && git push)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue