MystiquePlus/.forgejo/scripts/readme-m3u.js
2025-01-30 22:47:58 +00:00

59 lines
No EOL
2.1 KiB
JavaScript

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);
}