cabernetwork / cabernet

Cabernet allows control of IPTV streams. Plugins supports DaddyLive, Pluto TV, XUMO, M3U/XMLTV.XML files (SamsungTV, STIRR, DistroTV, Plex TV)
https://cabernetwork.github.io
MIT License
184 stars 25 forks source link

xmltv.xml missing document header. <originally issue #109> #135

Closed slippyC closed 8 months ago

slippyC commented 8 months ago

This issue went left by the wayside and went stale. I guess it isn't common knowledge that you can use Cabernet with Kodi. Actually, I'm a very recent user myself. Anyway I guess that's why there wasn't much interest in this issue.

Header information is missing in the xmltv.xml that Cabernet is sending back as response. Kodi/PVR IPTV Simple doesn't like that some of the schema/dtd info is missing at the top of the file to designate it as xml. It considers the schema malformed without that header.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tv SYSTEM "xmltv.dtd">

If you paste this schema info at the top of the returned xmltv.xml file then EPG data is then loaded into Kodi.

https://github.com/cabernetwork/cabernet/blob/76501a79db6ef6d2c93ab97233a24bbf8f167649/lib/clients/epg2xml.py#L351

This is where the setup of the file begins and where you could put the data. Of course there are multiple places you could append the data. I kinda looked at the code, but haven't got a complete grasp of it. I noticed some stripping out of the element tags <tv>/</tv> and possibly the xml header. So I'm not completely sure of what or why you are trying to accomplish that in that section currently. It's just another section of the code I looked at to possibly append the header information(before the data get's written out).

The simplest way looks to convert the current xml tree into a UTF-8 string and append a UTF-8 encoded header to the beginning of it before it is written out. The reason I say this is because ElementTree doesn't appear to have built-in functions to manipulate that part. So either you have to bring in another library to do it or just convert both parts to UTF-8 and combine them.

slippyC commented 8 months ago

For anyone wanting a quick fix for the issue in Kodi, you can use this. Yes, I'm sure there will be some that say, "that isn't the proper way to fix that, you should use an XML library". Not only is this an easier fix, but the code will execute faster since you won't be flip-flopping back and forth between libraries just to get the same outcome.

In file /lib/clients/epg2xml.py "add" the following contents: At line 152, insert this. DO NOT delete what is already there.

epg_dom = epg_dom.replace('<?xml version="1.0" ?>\n','<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tv SYSTEM "xmltv.dtd">\n',1)

At line 167, insert this code. Same rule applies, DO NOT delete code already there insert this as a new line.

self.webserver.wfile.write(('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tv SYSTEM "xmltv.dtd">').encode())

By default the server currently uses the second line of code. There is an option to "beautify" the output of the xml though. If that flag is set then the first line of code is used.