const fs = require('fs'); let code = fs.readFileSync('index.js', 'utf8'); // Patch 1: PUBLIC_URL support code = code.replace( 'function getLocalBaseUrl() {\n return `http://${httpHost}:${port}`;\n}', 'function getLocalBaseUrl() {\n if (process.env.PUBLIC_URL) return process.env.PUBLIC_URL;\n return `http://${httpHost}:${port}`;\n}' ); // Patch 2: EPG header code = code.replace( "const output = ['#EXTM3U'];", "const output = ['#EXTM3U url-tvg=\"http://www.epg-guide.com/it.gz\" x-tvg-url=\"http://www.epg-guide.com/it.gz\"'];" ); // Patch 3: insert epgId variable and use it in EXTINF const oldLine = "output.push(`#EXTINF:-1 tvg-name=\"${channel.name}\" group-title=\"${channel.country}\" tvg-logo=\"${channel.logo}\" tvg-id=\"${channel.name}\",${channel.name}`);"; const newLine = "const epgId = channel.name.toLowerCase().replace(/ \\.[cs]$/, '').trim();\n output.push(`#EXTINF:-1 tvg-name=\"${channel.name}\" group-title=\"${channel.country}\" tvg-logo=\"${channel.logo}\" tvg-id=\"${epgId}\",${channel.name}`);"; if (code.includes(oldLine)) { code = code.replace(oldLine, newLine); console.log('Patch 3 OK'); } else { console.log('Patch 3 FAILED - line not found'); } fs.writeFileSync('index.js', code);