diff --git a/resources/lib/kodiutils.py b/resources/lib/kodiutils.py
index ce0696b..ce2cb10 100644
--- a/resources/lib/kodiutils.py
+++ b/resources/lib/kodiutils.py
@@ -5,6 +5,7 @@ from __future__ import absolute_import, division, unicode_literals
import logging
import os
+import re
import xbmc
import xbmcaddon
@@ -12,6 +13,12 @@ import xbmcgui
import xbmcplugin
import xbmcvfs
+try: # Python 3
+ from html import unescape
+except ImportError: # Python 2
+ from HTMLParser import HTMLParser
+ unescape = HTMLParser().unescape
+
ADDON = xbmcaddon.Addon()
SORT_METHODS = dict(
@@ -27,6 +34,19 @@ DEFAULT_SORT_METHODS = [
'unsorted', 'title'
]
+HTML_MAPPING = [
+ (re.compile(r'<(/?)i(|\s[^>]+)>', re.I), '[\\1I]'),
+ (re.compile(r'<(/?)b(|\s[^>]+)>', re.I), '[\\1B]'),
+ (re.compile(r']+)>', re.I), '[I]'),
+ (re.compile(r'', re.I), '[/I]'),
+ (re.compile(r'<(strong|h\d)>', re.I), '[B]'),
+ (re.compile(r'(strong|h\d)>', re.I), '[/B]'),
+ (re.compile(r'
', re.I), '- '),
+ (re.compile(r'?(li|ul|ol)(|\s[^>]+)>', re.I), '\n'),
+ (re.compile(r'?(code|div|p|pre|span)(|\s[^>]+)>', re.I), ''),
+ (re.compile('( \n){2,}', re.I), '\n'), # Remove repeating non-blocking spaced newlines
+]
+
STREAM_HLS = 'hls'
STREAM_DASH = 'mpd'
@@ -87,6 +107,15 @@ def from_unicode(text, encoding='utf-8', errors='strict'):
return text
+def html_to_kodi(text):
+ """Convert HTML content into Kodi formatted text"""
+ if not text:
+ return text
+ for key, val in HTML_MAPPING:
+ text = key.sub(val, text)
+ return unescape(text).strip()
+
+
def addon_icon():
"""Cache and return add-on icon"""
return get_addon_info('icon')
diff --git a/resources/lib/modules/catalog.py b/resources/lib/modules/catalog.py
index 91fd0b5..d91634c 100644
--- a/resources/lib/modules/catalog.py
+++ b/resources/lib/modules/catalog.py
@@ -110,7 +110,7 @@ class Catalog:
info_dict={
'tvshowtitle': program.title,
'title': kodiutils.localize(30205, season=season.number), # Season {season}
- 'plot': season.description,
+ 'plot': season.description or program.description,
'set': program.title,
}
)
diff --git a/resources/lib/viervijfzes/content.py b/resources/lib/viervijfzes/content.py
index 338b57e..a16af5d 100644
--- a/resources/lib/viervijfzes/content.py
+++ b/resources/lib/viervijfzes/content.py
@@ -12,7 +12,7 @@ from datetime import datetime
import requests
-from resources.lib.kodiutils import STREAM_DASH, STREAM_HLS
+from resources.lib.kodiutils import html_to_kodi, STREAM_DASH, STREAM_HLS
from resources.lib.viervijfzes import ResolvedStream
try: # Python 3
@@ -532,7 +532,7 @@ class ContentApi:
path=playlist['link'].lstrip('/'),
channel=playlist['pageInfo']['brand'],
title=playlist['title'],
- description=playlist['pageInfo']['description'],
+ description=html_to_kodi(playlist.get('description')),
number=playlist['episodes'][0]['seasonNumber'], # You did not see this
)
for key, playlist in enumerate(data['playlists']) if playlist['episodes']
@@ -572,7 +572,7 @@ class ContentApi:
channel=data.get('pageInfo', {}).get('site'),
program_title=data.get('program', {}).get('title') if data.get('program') else data.get('title'),
title=data.get('title'),
- description=data.get('pageInfo', {}).get('description'),
+ description=html_to_kodi(data.get('description')),
cover=data.get('image'),
background=data.get('image'),
duration=data.get('duration'),