// Path: src/main/java/com/github/segator/proxylive/config/ProxyLiveConfiguration.java
// @Configuration
// @ConfigurationProperties
// public class ProxyLiveConfiguration {
//     private final Logger logger = LoggerFactory.getLogger(DirectTranscodeTask.class);
//     private final JwtHelper jwtHelper;
//     private BufferingConfiguration buffers;
//     private FFMpegConfiguration ffmpeg;
//     private HttpLiveSource source;
//     private GEOIPDatasource geoIP;
//     private AuthenticationConfiguration authentication;
//     private String userAgent;
//     private int streamTimeout;
// 
//     public ProxyLiveConfiguration(JwtHelper jwtHelper) {
//         this.jwtHelper = jwtHelper;
//     }
// 
//     @PostConstruct
//     public void initializeBean() {
// 
//         //If tvheadend input is set complete configuration
//         if(source.getTvheadendURL()!=null){
//             if( source.getEpg().getUrl()==null) {
//                 source.getEpg().setUrl(source.getTvheadendURL() + "/xmltv/channels");
//             }
//             if(source.getChannels().getUrl()==null) {
//                 source.getChannels().setUrl(source.getTvheadendURL());
//             }
//         }
// 
// 
//     }
// 
//     public FFMpegConfiguration getFfmpeg() {
//         return ffmpeg;
//     }
// 
//     public void setFfmpeg(FFMpegConfiguration ffmpeg) {
//         this.ffmpeg = ffmpeg;
//     }
// 
//     public HttpLiveSource getSource() {
//         return source;
//     }
// 
//     public GEOIPDatasource getGeoIP() {
//         return geoIP;
//     }
// 
//     public void setGeoIP(GEOIPDatasource geoIP) {
//         this.geoIP = geoIP;
//     }
// 
//     public void setSource(HttpLiveSource source) {
//         this.source = source;
//     }
// 
//     public BufferingConfiguration getBuffers() {
//         return buffers;
//     }
// 
//     public void setBuffers(BufferingConfiguration buffers) {
//         this.buffers = buffers;
//     }
// 
//     public AuthenticationConfiguration getAuthentication() {
//         return authentication;
//     }
// 
//     public void setAuthentication(AuthenticationConfiguration authentication) {
//         this.authentication = authentication;
//     }
// 
//     public int getStreamTimeout() {
//         return streamTimeout;
//     }
//     public int getStreamTimeoutMilis() {
//         return streamTimeout*1000;
//     }
// 
//     public void setStreamTimeout(int streamTimeout) {
//         this.streamTimeout = streamTimeout;
//     }
// 
// 
//     public String getUserAgent() {
//         return userAgent;
//     }
// 
//     public void setUserAgent(String userAgent) {
//         this.userAgent = userAgent;
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/service/EPGService.java
// @Service
// public class EPGService {
//     private final Logger logger = LoggerFactory.getLogger(EPGService.class);
//     private File tempEPGFile;
// 
//     private final ProxyLiveConfiguration config;
//     private long lastUpdate=0;
// 
//     public EPGService(ProxyLiveConfiguration config) {
//         this.config = config;
//     }
// 
//     @Scheduled(fixedDelay = 600 * 1000) //Every 100 Minute
//     @PostConstruct
//     private void buildEPG() throws Exception {
//         if(config.getSource().getEpg()==null || config.getSource().getEpg().getUrl()==null ){
//             return;
//         }
//         if(new Date().getTime()-lastUpdate>+(config.getSource().getEpg().getRefresh()*1000)) {
//             logger.info("Refreshing EPG");
//             HttpURLConnection connection = getURLConnection(config.getSource().getEpg().getUrl());
//             if (connection.getResponseCode() != 200) {
//                 return;
//             }
//             InputStream channel = connection.getInputStream();
//             if(config.getSource().getEpg().getUrl().endsWith("gz")){
//                 channel = new GZIPInputStream(channel);
//             }
// 
//             File tempEPGFileRound = File.createTempFile("epg", "xml");
//             FileOutputStream fos = new FileOutputStream(tempEPGFileRound);
//             IOUtils.copy(channel, fos);
//             fos.flush();
//             channel.close();
//             fos.close();
//             connection.disconnect();
// 
//             if (tempEPGFile != null && tempEPGFile.exists()) {
//                 tempEPGFile.delete();
//             }
//             tempEPGFile = tempEPGFileRound;
//             lastUpdate=new Date().getTime();
//         }
//     }
// 
// 
//     public File getEPG() throws IOException {
//         return tempEPGFile;
//     }
// 
//     private HttpURLConnection getURLConnection(String url) throws MalformedURLException, IOException {
//         URL tvheadendURL = new URL(url);
//         HttpURLConnection connection = (HttpURLConnection) tvheadendURL.openConnection();
//         connection.setReadTimeout(10000);
//         if (tvheadendURL.getUserInfo() != null) {
//             String basicAuth = "Basic " + new String(Base64.getEncoder().encode(tvheadendURL.getUserInfo().getBytes()));
//             connection.setRequestProperty("Authorization", basicAuth);
//         }
//         connection.setRequestMethod("GET");
//         connection.connect();
//         return connection;
//     }
// 
//     public List<EPGProgram> getEPGFromChannelID(String epgID) {
//         List<EPGProgram> epgPrograms = new ArrayList<>();
//         return epgPrograms;
//     }
// }


import com.github.segator.proxylive.config.ProxyLiveConfiguration;
import com.github.segator.proxylive.service.EPGService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.regex.Pattern;
package com.github.segator.proxylive.stream;



public class UDPInputStream extends VideoInputStream {
    private final Logger logger = LoggerFactory.getLogger(UDPInputStream.class);
    private final InetAddress server;
    private final int port;
    private final byte[] buffer;
    private byte[] currentPacket;
    private int currentPacketSize;
    private int currentPacketPosition=0;
// Path: src/main/java/com/github/segator/proxylive/config/ProxyLiveConfiguration.java
// @Configuration
// @ConfigurationProperties
// public class ProxyLiveConfiguration {
//     private final Logger logger = LoggerFactory.getLogger(DirectTranscodeTask.class);
//     private final JwtHelper jwtHelper;
//     private BufferingConfiguration buffers;
//     private FFMpegConfiguration ffmpeg;
//     private HttpLiveSource source;
//     private GEOIPDatasource geoIP;
//     private AuthenticationConfiguration authentication;
//     private String userAgent;
//     private int streamTimeout;
// 
//     public ProxyLiveConfiguration(JwtHelper jwtHelper) {
//         this.jwtHelper = jwtHelper;
//     }
// 
//     @PostConstruct
//     public void initializeBean() {
// 
//         //If tvheadend input is set complete configuration
//         if(source.getTvheadendURL()!=null){
//             if( source.getEpg().getUrl()==null) {
//                 source.getEpg().setUrl(source.getTvheadendURL() + "/xmltv/channels");
//             }
//             if(source.getChannels().getUrl()==null) {
//                 source.getChannels().setUrl(source.getTvheadendURL());
//             }
//         }
// 
// 
//     }
// 
//     public FFMpegConfiguration getFfmpeg() {
//         return ffmpeg;
//     }
// 
//     public void setFfmpeg(FFMpegConfiguration ffmpeg) {
//         this.ffmpeg = ffmpeg;
//     }
// 
//     public HttpLiveSource getSource() {
//         return source;
//     }
// 
//     public GEOIPDatasource getGeoIP() {
//         return geoIP;
//     }
// 
//     public void setGeoIP(GEOIPDatasource geoIP) {
//         this.geoIP = geoIP;
//     }
// 
//     public void setSource(HttpLiveSource source) {
//         this.source = source;
//     }
// 
//     public BufferingConfiguration getBuffers() {
//         return buffers;
//     }
// 
//     public void setBuffers(BufferingConfiguration buffers) {
//         this.buffers = buffers;
//     }
// 
//     public AuthenticationConfiguration getAuthentication() {
//         return authentication;
//     }
// 
//     public void setAuthentication(AuthenticationConfiguration authentication) {
//         this.authentication = authentication;
//     }
// 
//     public int getStreamTimeout() {
//         return streamTimeout;
//     }
//     public int getStreamTimeoutMilis() {
//         return streamTimeout*1000;
//     }
// 
//     public void setStreamTimeout(int streamTimeout) {
//         this.streamTimeout = streamTimeout;
//     }
// 
// 
//     public String getUserAgent() {
//         return userAgent;
//     }
// 
//     public void setUserAgent(String userAgent) {
//         this.userAgent = userAgent;
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/service/EPGService.java
// @Service
// public class EPGService {
//     private final Logger logger = LoggerFactory.getLogger(EPGService.class);
//     private File tempEPGFile;
// 
//     private final ProxyLiveConfiguration config;
//     private long lastUpdate=0;
// 
//     public EPGService(ProxyLiveConfiguration config) {
//         this.config = config;
//     }
// 
//     @Scheduled(fixedDelay = 600 * 1000) //Every 100 Minute
//     @PostConstruct
//     private void buildEPG() throws Exception {
//         if(config.getSource().getEpg()==null || config.getSource().getEpg().getUrl()==null ){
//             return;
//         }
//         if(new Date().getTime()-lastUpdate>+(config.getSource().getEpg().getRefresh()*1000)) {
//             logger.info("Refreshing EPG");
//             HttpURLConnection connection = getURLConnection(config.getSource().getEpg().getUrl());
//             if (connection.getResponseCode() != 200) {
//                 return;
//             }
//             InputStream channel = connection.getInputStream();
//             if(config.getSource().getEpg().getUrl().endsWith("gz")){
//                 channel = new GZIPInputStream(channel);
//             }
// 
//             File tempEPGFileRound = File.createTempFile("epg", "xml");
//             FileOutputStream fos = new FileOutputStream(tempEPGFileRound);
//             IOUtils.copy(channel, fos);
//             fos.flush();
//             channel.close();
//             fos.close();
//             connection.disconnect();
// 
//             if (tempEPGFile != null && tempEPGFile.exists()) {
//                 tempEPGFile.delete();
//             }
//             tempEPGFile = tempEPGFileRound;
//             lastUpdate=new Date().getTime();
//         }
//     }
// 
// 
//     public File getEPG() throws IOException {
//         return tempEPGFile;
//     }
// 
//     private HttpURLConnection getURLConnection(String url) throws MalformedURLException, IOException {
//         URL tvheadendURL = new URL(url);
//         HttpURLConnection connection = (HttpURLConnection) tvheadendURL.openConnection();
//         connection.setReadTimeout(10000);
//         if (tvheadendURL.getUserInfo() != null) {
//             String basicAuth = "Basic " + new String(Base64.getEncoder().encode(tvheadendURL.getUserInfo().getBytes()));
//             connection.setRequestProperty("Authorization", basicAuth);
//         }
//         connection.setRequestMethod("GET");
//         connection.connect();
//         return connection;
//     }
// 
//     public List<EPGProgram> getEPGFromChannelID(String epgID) {
//         List<EPGProgram> epgPrograms = new ArrayList<>();
//         return epgPrograms;
//     }
// }


// Path: src/main/java/com/github/segator/proxylive/stream/UDPInputStream.java
import com.github.segator.proxylive.config.ProxyLiveConfiguration;
import com.github.segator.proxylive.service.EPGService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.regex.Pattern;

package com.github.segator.proxylive.stream;



public class UDPInputStream extends VideoInputStream {
    private final Logger logger = LoggerFactory.getLogger(UDPInputStream.class);
    private final InetAddress server;
    private final int port;
    private final byte[] buffer;
    private byte[] currentPacket;
    private int currentPacketSize;
    private int currentPacketPosition=0;
    private ProxyLiveConfiguration config;