<?php
error_reporting(0);
set_time_limit(0);
ini_set("memory_limit", "1024M");
header("Content-Type: application/xml; charset=utf-8");

$arquivo_fonte = "epg_source.txt";

if (file_exists($arquivo_fonte)) {
    $url = trim(file_get_contents($arquivo_fonte));
    if (!empty($url)) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // O SEGREDO: Aceita GZIP
        curl_setopt($ch, CURLOPT_ENCODING, ""); 
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
        $data = curl_exec($ch);
        curl_close($ch);

        if ($data) {
            echo $data;
            exit;
        }
    }
}
// XML Vazio para não dar erro
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><tv></tv>";
?>