Luig
09-20-2017, 02:15 AM
Instead of resolving the issues in the AutoIT version I have decided to scrap all that code and just start fresh in C#. The reason I started in AutoIt is because it's an easier language to get a grasp of and I'm incredibly rusty, up until recently I haven't really coded anything in about a year or two. To minimize errors I hard coded the link to the epg guide xml and the program now reads the m3u file directly from the link generated in your IPTV control panel. Since the program now requires more sensitive data to work I am releasing the source code with instructions on how to compile it for each operating system. That's right, this new version is compatible with Windows, Linux and Mac! I'm only releasing this basic CLI source code, all future releases will be closed source to keep script kiddies from stealing my work, renaming it and claiming it as their own work.
TL;DR: This EPG Fix CLI Tool
Source Code
using System;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Net;
namespace EPGFix
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine ("Please input m3u url and press enter");
string remoteUrl = Console.ReadLine();
WebClient myWebClient = new WebClient();
Console.WriteLine("Downloading " + remoteUrl);
byte[] myDataBuffer = myWebClient.DownloadData (remoteUrl);
Stream stream = new MemoryStream(myDataBuffer);
string line;
char delimiter = ',';
string[] substrings;
string[] names = {"",""};
string[] data = {"",""};
string[] url = {"",""};
int counter = 0;
System.IO.StreamReader file =
new System.IO.StreamReader(stream);
while((line = file.ReadLine()) != null)
{
if (line.StartsWith("#EXTINF:"))
{
if (counter > 0) {
Array.Resize (ref names, names.Length + 1);
Array.Resize (ref data, data.Length + 1);
Array.Resize (ref url, url.Length + 1);
}
substrings = line.Split (delimiter);
names [counter] = substrings [substrings.Length - 1];
data [counter] = line;
url [counter] = file.ReadLine();
counter++;
}
}
file.Close();
Console.WriteLine("Download successful.");
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
settings.ValidationType = ValidationType.DTD;
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
XmlReader xmlReader = XmlReader.Create("http://epg.euyulio.org/", settings);
XmlReader xmlReader2;
int strIndex;
string content;
bool continueloop = false;
string id;
while(xmlReader.Read())
{
if((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "channel"))
{
if (xmlReader.HasAttributes)
{
id = xmlReader.GetAttribute ("id");
xmlReader2 = xmlReader.ReadSubtree();
while (xmlReader2.Read())
{
if (continueloop) {
continueloop = false;
break;
}
if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "display-name")) {
content = xmlReader2.ReadElementContentAsString ();
for (int strNumber = 0; strNumber < names.Length-1; strNumber++)
{
strIndex = names[strNumber].IndexOf(content);
if (strIndex >= 0) {
if (data[strNumber].StartsWith("#EXTINF:-1 tvg-id=" + '"' + '"')) {
data[strNumber] = "#EXTINF:-1 tvg-id=" + '"' + id + data[strNumber].Substring(19);
continueloop = true;
break;
}
data[strNumber] = "#EXTINF:-1 tvg-id=" + '"' + id + data[strNumber].Substring (24);
continueloop = true;
break;
}
}
}
}
}
}
}
string path = Directory.GetCurrentDirectory();
Console.WriteLine ("Please input new M3U Playlist name");
System.IO.StreamWriter file2 = new System.IO.StreamWriter(path + @"/"+Console.ReadLine()+".m3u");
file2.WriteLine("#EXTM3U");
for (int strNumber = 0; strNumber < names.Length - 1; strNumber++) {
file2.WriteLine (data [strNumber]);
file2.WriteLine (url [strNumber]);
}
file.Close();
Console.WriteLine ("New M3U file generated press any key to exit");
Console.ReadKey();
}
private static void ValidationCallBack(object sender, ValidationEventArgs e) {
Console.WriteLine("Loaded EPG Guide", e.Message);
}
}
}
OS Specific Requirements
Windows: .NET Framework 4.5 must be installed
Linux: Mono must be installed (Follow install instructions Here (http://www.mono-project.com/download/#download-lin))
Mac: Mono must be installed (Follow install instructions Here (http://www.mono-project.com/download/#download-mac))
General Requirements
Link to M3U Playlist as generated by your IPTV control panel
A way to host the new generated m3u file with the updated channel parameters. I personally use 000webhost.com because it's free, fast and reliable but any webhost that offers direct linking should work.
Knowledge of using Kodi and Web Control Panels helps alot but not really needed
Last but not least my handy dandy App
Windows Instructions
1. Double click on epgfix.exe
2. Copy and paste M3U URL and press enter
3. Type the name of the new file and press enter
4. Press any key to exit
5. Upload M3U file to a webhost
Linux and Mac Instructions
1. Open Terminal
2. Type "cd location/of/epgfixfolder" I keep mine in documents so it would be "cd Documents"
2. Type "mono epgfix.exe" and press enter
3. Copy and paste M3U URL and press enter
4. Type the name of the new file and press enter
5. Press any key to exit
6. Upload M3U file to a webhost
Kodi Instructions
1. Open up Kodi's IPTV Simple Client Settings (My Addons -> PVR Clients-> PVR IPTV Simple Client -> Configure -> General Settings) Under: M3U Play List URL enter the url to where you uploaded your playlist, I would also disable "Cache m3u at local storage" as it can cause issues
2. In the same menu you should see another submenu or tab called EPG Settings. Under that tab you'll find XMLTV URL, you need to enter the following with out parenthesis "http://epg.euyulio.org" Also turn off "Cache XMLTV at local storage".
3. If you did everything you can disable and re-enable the IPTV Simple Client and you should start seeing that lonely EPG start populating. If that doesn't work you can either try restarting Kodi and/or clearing the old tv data in Kodi's TV settings
How to compile on Windows
1. Download and install Mono 32-bit from Here (http://www.mono-project.com/download/#download-win)
2. Open up Notepad and copy paste Source Code above into Notepad
3. Save As "epgfix.cs" make sure to "Save as type" is set to "All files (*.*)" and close Notepad
4. Open Mono x86 Command Prompt <--- It should appear in your start menu after you install Mono
5. Type "cd path\to\epgfix" and press enter (I keep my in documents so for me it's "cd C:\Users\Username\Documents" replace Username with your computer username)
6. Type "mcs epgfix.cs" and press enter
How to compile on Linux
1. Make sure if you have Mono installed, refer to Linux Requirement section.
2. Open up your text editor and copy paste Source Code above into it
3. Save As "epgfix.cs" make sure to "Save type" is set to "All files (*.*)" and close your text editor
4. Open Terminal
5. Type "cd path\to\epgfix" and press enter (I keep my in documents so for me it's "cd C:\Users\Username\Documents" replace Username with your computer username)
6. Type "mcs epgfix.cs" and press enter
How to compile on Mac
I'm gonna edit this later when I get access to a Mac computer but I'm sure it's roughly the same steps as Linux Instructions.
I'm still providing a download link to the compiled version below for the people that don't want to go through extra steps to compile it
Download EPG Fix CLI Tool (http://kodituts.000webhostapp.com/epgfix.Exe)
Credits for the EPG XML go to Euyulio and Viper8690 : GitHub (https://github.com/euyulio/epg)
I have personally tested this program in several different computers and it's working on both Linux and Windows. I currently don't have access to a Mac computer but it should work aswell. Please feel free to report any bugs you might encounter and I'm working on a GUI and to get the features I had in AutoIt back in the C# but I won't release it until thoroughly tested. I'll edit this post with video tutorials when I get around to making them.
TL;DR: This EPG Fix CLI Tool
Source Code
using System;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Net;
namespace EPGFix
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine ("Please input m3u url and press enter");
string remoteUrl = Console.ReadLine();
WebClient myWebClient = new WebClient();
Console.WriteLine("Downloading " + remoteUrl);
byte[] myDataBuffer = myWebClient.DownloadData (remoteUrl);
Stream stream = new MemoryStream(myDataBuffer);
string line;
char delimiter = ',';
string[] substrings;
string[] names = {"",""};
string[] data = {"",""};
string[] url = {"",""};
int counter = 0;
System.IO.StreamReader file =
new System.IO.StreamReader(stream);
while((line = file.ReadLine()) != null)
{
if (line.StartsWith("#EXTINF:"))
{
if (counter > 0) {
Array.Resize (ref names, names.Length + 1);
Array.Resize (ref data, data.Length + 1);
Array.Resize (ref url, url.Length + 1);
}
substrings = line.Split (delimiter);
names [counter] = substrings [substrings.Length - 1];
data [counter] = line;
url [counter] = file.ReadLine();
counter++;
}
}
file.Close();
Console.WriteLine("Download successful.");
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Ignore;
settings.ValidationType = ValidationType.DTD;
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
XmlReader xmlReader = XmlReader.Create("http://epg.euyulio.org/", settings);
XmlReader xmlReader2;
int strIndex;
string content;
bool continueloop = false;
string id;
while(xmlReader.Read())
{
if((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "channel"))
{
if (xmlReader.HasAttributes)
{
id = xmlReader.GetAttribute ("id");
xmlReader2 = xmlReader.ReadSubtree();
while (xmlReader2.Read())
{
if (continueloop) {
continueloop = false;
break;
}
if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "display-name")) {
content = xmlReader2.ReadElementContentAsString ();
for (int strNumber = 0; strNumber < names.Length-1; strNumber++)
{
strIndex = names[strNumber].IndexOf(content);
if (strIndex >= 0) {
if (data[strNumber].StartsWith("#EXTINF:-1 tvg-id=" + '"' + '"')) {
data[strNumber] = "#EXTINF:-1 tvg-id=" + '"' + id + data[strNumber].Substring(19);
continueloop = true;
break;
}
data[strNumber] = "#EXTINF:-1 tvg-id=" + '"' + id + data[strNumber].Substring (24);
continueloop = true;
break;
}
}
}
}
}
}
}
string path = Directory.GetCurrentDirectory();
Console.WriteLine ("Please input new M3U Playlist name");
System.IO.StreamWriter file2 = new System.IO.StreamWriter(path + @"/"+Console.ReadLine()+".m3u");
file2.WriteLine("#EXTM3U");
for (int strNumber = 0; strNumber < names.Length - 1; strNumber++) {
file2.WriteLine (data [strNumber]);
file2.WriteLine (url [strNumber]);
}
file.Close();
Console.WriteLine ("New M3U file generated press any key to exit");
Console.ReadKey();
}
private static void ValidationCallBack(object sender, ValidationEventArgs e) {
Console.WriteLine("Loaded EPG Guide", e.Message);
}
}
}
OS Specific Requirements
Windows: .NET Framework 4.5 must be installed
Linux: Mono must be installed (Follow install instructions Here (http://www.mono-project.com/download/#download-lin))
Mac: Mono must be installed (Follow install instructions Here (http://www.mono-project.com/download/#download-mac))
General Requirements
Link to M3U Playlist as generated by your IPTV control panel
A way to host the new generated m3u file with the updated channel parameters. I personally use 000webhost.com because it's free, fast and reliable but any webhost that offers direct linking should work.
Knowledge of using Kodi and Web Control Panels helps alot but not really needed
Last but not least my handy dandy App
Windows Instructions
1. Double click on epgfix.exe
2. Copy and paste M3U URL and press enter
3. Type the name of the new file and press enter
4. Press any key to exit
5. Upload M3U file to a webhost
Linux and Mac Instructions
1. Open Terminal
2. Type "cd location/of/epgfixfolder" I keep mine in documents so it would be "cd Documents"
2. Type "mono epgfix.exe" and press enter
3. Copy and paste M3U URL and press enter
4. Type the name of the new file and press enter
5. Press any key to exit
6. Upload M3U file to a webhost
Kodi Instructions
1. Open up Kodi's IPTV Simple Client Settings (My Addons -> PVR Clients-> PVR IPTV Simple Client -> Configure -> General Settings) Under: M3U Play List URL enter the url to where you uploaded your playlist, I would also disable "Cache m3u at local storage" as it can cause issues
2. In the same menu you should see another submenu or tab called EPG Settings. Under that tab you'll find XMLTV URL, you need to enter the following with out parenthesis "http://epg.euyulio.org" Also turn off "Cache XMLTV at local storage".
3. If you did everything you can disable and re-enable the IPTV Simple Client and you should start seeing that lonely EPG start populating. If that doesn't work you can either try restarting Kodi and/or clearing the old tv data in Kodi's TV settings
How to compile on Windows
1. Download and install Mono 32-bit from Here (http://www.mono-project.com/download/#download-win)
2. Open up Notepad and copy paste Source Code above into Notepad
3. Save As "epgfix.cs" make sure to "Save as type" is set to "All files (*.*)" and close Notepad
4. Open Mono x86 Command Prompt <--- It should appear in your start menu after you install Mono
5. Type "cd path\to\epgfix" and press enter (I keep my in documents so for me it's "cd C:\Users\Username\Documents" replace Username with your computer username)
6. Type "mcs epgfix.cs" and press enter
How to compile on Linux
1. Make sure if you have Mono installed, refer to Linux Requirement section.
2. Open up your text editor and copy paste Source Code above into it
3. Save As "epgfix.cs" make sure to "Save type" is set to "All files (*.*)" and close your text editor
4. Open Terminal
5. Type "cd path\to\epgfix" and press enter (I keep my in documents so for me it's "cd C:\Users\Username\Documents" replace Username with your computer username)
6. Type "mcs epgfix.cs" and press enter
How to compile on Mac
I'm gonna edit this later when I get access to a Mac computer but I'm sure it's roughly the same steps as Linux Instructions.
I'm still providing a download link to the compiled version below for the people that don't want to go through extra steps to compile it
Download EPG Fix CLI Tool (http://kodituts.000webhostapp.com/epgfix.Exe)
Credits for the EPG XML go to Euyulio and Viper8690 : GitHub (https://github.com/euyulio/epg)
I have personally tested this program in several different computers and it's working on both Linux and Windows. I currently don't have access to a Mac computer but it should work aswell. Please feel free to report any bugs you might encounter and I'm working on a GUI and to get the features I had in AutoIt back in the C# but I won't release it until thoroughly tested. I'll edit this post with video tutorials when I get around to making them.