Update .forgejo/scripts/readme-m3u.js
somebody gonna hate me for sure, but i have edited this with ai for some part because i had no idea how to implement if else statement in this code... lmao
This commit is contained in:
parent
105cb93f65
commit
0b37740c66
1 changed files with 54 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function updateReadme(m3uPath) {
|
||||
function updateReadme(m3uPath, additionalM3uFiles = []) {
|
||||
// Get directories for both types of groups
|
||||
const countriesDir = path.join(path.dirname(m3uPath), 'countries');
|
||||
const culturalDir = path.join(path.dirname(m3uPath), 'cultural-groups');
|
||||
|
@ -24,6 +24,26 @@ function updateReadme(m3uPath) {
|
|||
}
|
||||
});
|
||||
|
||||
// Process additional M3U files
|
||||
const additionalPlaylists = [];
|
||||
additionalM3uFiles.forEach(filePath => {
|
||||
if (fs.existsSync(filePath)) {
|
||||
const additionalContent = fs.readFileSync(filePath, 'utf8');
|
||||
const additionalLines = additionalContent.split('\n');
|
||||
const channelCount = additionalLines.filter(line => line.startsWith('#EXTINF')).length;
|
||||
const fileName = path.basename(filePath);
|
||||
|
||||
additionalPlaylists.push({
|
||||
name: fileName,
|
||||
displayName: fileName.replace('.m3u', '').replace(/_/g, ' ').replace(/\b\w/g, l => l.toUpperCase()),
|
||||
channels: channelCount,
|
||||
path: fileName
|
||||
});
|
||||
} else {
|
||||
console.warn(`Warning: Additional M3U file not found: ${filePath}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Get cultural group counts
|
||||
if (fs.existsSync(culturalDir)) {
|
||||
fs.readdirSync(culturalDir)
|
||||
|
@ -48,12 +68,23 @@ function updateReadme(m3uPath) {
|
|||
// Add usage section
|
||||
readmeContent += '## Usage\n\n';
|
||||
readmeContent += '1. **Complete Playlist**: Use the main `mystique.m3u` file for access to all channels\n';
|
||||
if (additionalPlaylists.length > 0) {
|
||||
readmeContent += '2. **Additional Collections**: Specialized playlists for specific content types (Can be Radios, etc.)\n';
|
||||
readmeContent += '3. **Country-Specific**: Individual country playlists are available in the `countries/` directory\n';
|
||||
readmeContent += '4. **Cultural Groups**: Cultural/linguistic group playlists are available in the `cultural-groups/` directory\n';
|
||||
} else {
|
||||
readmeContent += '2. **Country-Specific**: Individual country playlists are available in the `countries/` directory\n';
|
||||
readmeContent += '3. **Cultural Groups**: Cultural/linguistic group playlists are available in the `cultural-groups/` directory\n\n';
|
||||
readmeContent += '3. **Cultural Groups**: Cultural/linguistic group playlists are available in the `cultural-groups/` directory\n';
|
||||
}
|
||||
readmeContent += '\n';
|
||||
|
||||
// Add statistics
|
||||
const totalAdditionalChannels = additionalPlaylists.reduce((sum, playlist) => sum + playlist.channels, 0);
|
||||
readmeContent += '## Statistics\n\n';
|
||||
readmeContent += `- Total Channels: ${totalChannels}\n`;
|
||||
if (totalAdditionalChannels > 0) {
|
||||
readmeContent += `- Additional Collections: ${totalAdditionalChannels} channels\n`;
|
||||
}
|
||||
readmeContent += `- Countries Available: ${Object.keys(groups.countries).length}\n`;
|
||||
readmeContent += `- Cultural Groups: ${Object.keys(groups.cultural).length}\n\n`;
|
||||
|
||||
|
@ -66,6 +97,14 @@ function updateReadme(m3uPath) {
|
|||
const mainPlaylistName = path.basename(m3uPath);
|
||||
readmeContent += `| **Complete (All channels)** | ${totalChannels} | [${mainPlaylistName}](${mainPlaylistName}) |\n`;
|
||||
|
||||
// Add additional playlists
|
||||
if (additionalPlaylists.length > 0) {
|
||||
readmeContent += '| **───────── Additional Collections ─────────** | | |\n';
|
||||
additionalPlaylists.forEach(playlist => {
|
||||
readmeContent += `| ${playlist.displayName} | ${playlist.channels} | [${playlist.name}](${playlist.path}) |\n`;
|
||||
});
|
||||
}
|
||||
|
||||
// Add countries
|
||||
readmeContent += '| **───────── Countries ─────────** | | |\n';
|
||||
const sortedCountryGroups = Object.entries(groups.countries).sort((a, b) => a[0].localeCompare(b[0]));
|
||||
|
@ -87,25 +126,34 @@ function updateReadme(m3uPath) {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
// Add note about legal usage
|
||||
readmeContent += '## Legal Notice\n\n';
|
||||
readmeContent += '\n## Legal Notice\n\n';
|
||||
readmeContent += 'This playlist is a collection of publicly available IPTV streams. ';
|
||||
readmeContent += 'Please check your local laws regarding IPTV streaming before using this playlist.\n';
|
||||
|
||||
const readmePath = path.join(path.dirname(m3uPath), 'README.md');
|
||||
fs.writeFileSync(readmePath, readmeContent);
|
||||
console.log('README.md has been updated with comprehensive playlist information');
|
||||
|
||||
if (additionalPlaylists.length > 0) {
|
||||
console.log(`Added ${additionalPlaylists.length} additional playlist(s):`);
|
||||
additionalPlaylists.forEach(playlist => {
|
||||
console.log(` - ${playlist.displayName}: ${playlist.channels} channels`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const filePath = process.argv[2];
|
||||
const additionalFiles = process.argv.slice(3); // Get all additional arguments
|
||||
|
||||
if (!filePath) {
|
||||
console.error('Please provide the path to mystique.m3u');
|
||||
console.error('Usage: node readme-m3u.js mystique.m3u [additional_file1.m3u] [additional_file2.m3u] ...');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
updateReadme(filePath);
|
||||
updateReadme(filePath, additionalFiles);
|
||||
} catch (error) {
|
||||
console.error('Error updating README:', error.message);
|
||||
process.exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue