cvarelaruiz / owi2plex

Exporter of EPG from OpenWebif to XMLTV to use with Plex
Mozilla Public License 2.0
26 stars 6 forks source link

The description doesnt get parsed correctly #5

Closed Fuechslein closed 4 years ago

Fuechslein commented 5 years ago

Generating XMLTV payload. Traceback (most recent call last): File "/usr/local/bin/owi2plex", line 10, in <module> sys.exit(main()) File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python3.7/dist-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/usr/local/bin/owi2plex.py", line 370, in main xmltv = generateXMLTV(bouquets_services, epg, api_root_url, tzoffset) File "/usr/local/bin/owi2plex.py", line 338, in generateXMLTV xmltv = addEvents2XML(xmltv, epg, tzoffset) File "/usr/local/bin/owi2plex.py", line 299, in addEvents2XML programme_desc.text = unescape(event['longdesc']) File "src/lxml/etree.pyx", line 1018, in lxml.etree._Element.text.__set__ File "src/lxml/apihelpers.pxi", line 710, in lxml.etree._setNodeText File "src/lxml/apihelpers.pxi", line 698, in lxml.etree._createTextNode File "src/lxml/apihelpers.pxi", line 1493, in lxml.etree._utf8 ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

setting programme_desc.text = '' solves the problem, but removes all descriptions :D

blinddark commented 5 years ago

same issue here: ./owi2plex -b "SAT HD" -h 192.168.78.5 -o /volume1/public/plex.xml b'Getting EPG for Service 1.Das Erste HD (10301) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:283D:3FB:1:C00000:0:0:0:' b'Getting EPG for Service 2.ZDF HD (11110) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:2B66:3F3:1:C00000:0:0:0:' b'Getting EPG for Service 3.RTL HD (61200) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF10:421:1:C00000:0:0:0:' b'Getting EPG for Service 4.SAT.1 HD (61300) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF74:3F9:1:C00000:0:0:0:' b'Getting EPG for Service 5.VOX HD (61201) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF11:421:1:C00000:0:0:0:' b'Getting EPG for Service 6.ProSieben HD (61301) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF75:3F9:1:C00000:0:0:0:' b'Getting EPG for Service 7.kabel eins HD (61302) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF76:3F9:1:C00000:0:0:0:' b'Getting EPG for Service 8.RTL2 HD (61205) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF15:421:1:C00000:0:0:0:' b'Getting EPG for Service 9.SUPER RTL HD (11931) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:2E9B:411:1:C00000:0:0:0:' b'Getting EPG for Service 10.KiKA HD (11160) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:2B98:3F2:1:C00000:0:0:0:' b'Getting EPG for Service 11.TOGGO plus (12030) from http://192.168.78.5:80/api/epgservice?sRef=1:0:1:2EFE:441:1:C00000:0:0:0:' b'Getting EPG for Service 12.Comedy Central HD (21107) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:5273:41D:1:C00000:0:0:0:' b'Getting EPG for Service 13.WELT HD (21108) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:5274:41D:1:C00000:0:0:0:' b'Getting EPG for Service 14.n-tv HD (61204) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:EF14:421:1:C00000:0:0:0:' b'Getting EPG for Service 15.TELE 5 HD (5401) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:1519:455:1:C00000:0:0:0:' b'Getting EPG for Service 16.Welt der Wunder (13103) from http://192.168.78.5:80/api/epgservice?sRef=1:0:1:332F:45B:1:C00000:0:0:0:' b'Getting EPG for Service 17.3sat HD (11150) from http://192.168.78.5:80/api/epgservice?sRef=1:0:19:2B8E:3F2:1:C00000:0:0:0:' Setting TZ Offset from UTC to +0200 Generating XMLTV payload. Traceback (most recent call last): File "./owi2plex", line 10, in sys.exit(main()) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/click/core.py", line 764, in call return self.main(args, kwargs) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/click/core.py", line 555, in invoke return callback(args, **kwargs) File "/volume1/@appstore/py3k/usr/local/bin/owi2plex.py", line 370, in main xmltv = generateXMLTV(bouquets_services, epg, api_root_url, tzoffset) File "/volume1/@appstore/py3k/usr/local/bin/owi2plex.py", line 338, in generateXMLTV xmltv = addEvents2XML(xmltv, epg, tzoffset) File "/volume1/@appstore/py3k/usr/local/bin/owi2plex.py", line 299, in addEvents2XML programme_desc.text = unescape(event['longdesc']) File "src/lxml/etree.pyx", line 1018, in lxml.etree._Element.text.set File "src/lxml/apihelpers.pxi", line 710, in lxml.etree._setNodeText File "src/lxml/apihelpers.pxi", line 698, in lxml.etree._createTextNode File "src/lxml/apihelpers.pxi", line 1493, in lxml.etree._utf8 ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

Fuechslein commented 5 years ago

You can just set the descriptions blank as dirty band-aid fix. Just look for lines with "programme_desc.text =" and replace the text afterwards with apostrophs '' to set it blank.

It seems the unescape function doesnt properly parse some of the description text returned by the box.

awsmfab commented 5 years ago

Add these function:

def valid_xml_char_ordinal(c):
    """
    Determine whether the given character is valid for xml.
    """
    codepoint = ord(c)
    return (
        0x20 <= codepoint <= 0xD7FF or
        codepoint in (0x9, 0xA, 0xD) or
        0xE000 <= codepoint <= 0xFFFD or
        0x10000 <= codepoint <= 0x10FFFF
        )

and update unescape function from:

return html.unescape(text)

to

return ''.join(c for c in html.unescape(text) if valid_xml_char_ordinal(c))

Works fine.

alturismo commented 5 years ago

Hi, may also an idea how to solve this "datetime" thing ?

for an Tipp, thanks ahead

...... Getting EPG for Service 10.RTL UHD (12410) from http://user:pass@192.168.1.103:80/api/epgservice?sRef=1:0:1F:307A:3F5:1:C00000:0:0:0: Traceback (most recent call last): File "/usr/bin/owi2plex", line 11, in sys.exit(main()) File "/usr/lib64/python2.7/site-packages/click/core.py", line 764, in call return self.main(args, kwargs) File "/usr/lib64/python2.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/usr/lib64/python2.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/lib64/python2.7/site-packages/click/core.py", line 555, in invoke return callback(args, **kwargs) File "/usr/bin/owi2plex.py", line 380, in main tzoffset = getOffset(api_root_url=api_root_url) File "/usr/bin/owi2plex.py", line 139, in getOffset now = datetime.timestamp(datetime.now()) AttributeError: type object 'datetime.datetime' has no attribute 'timestamp'

awsmfab commented 5 years ago

Of course, try to install with pip3. See https://github.com/cvarelaruiz/owi2plex/issues/6#issuecomment-493752695

alturismo commented 5 years ago

Of course, try to install with pip3. See #6 (comment)

perfect, including the upper fixes works as it should, thanks you

alturismo commented 5 years ago

may one more thing ;)

your fix currently also converts äöü in ... codes, just as note, they dont stay as plain text