Fix incomplete descriptions (#75)
* Fix incomplete descriptions This PR includes: - Use full description for episodes rather than cut-off description - Use the program description if the season description is missing * Update kodiutils.py Co-authored-by: Michaël Arnauts <michael.arnauts@gmail.com>
This commit is contained in:
parent
1a541552d7
commit
9ddc73094d
@ -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'<em(|\s[^>]+)>', re.I), '[I]'),
|
||||
(re.compile(r'</em>', re.I), '[/I]'),
|
||||
(re.compile(r'<(strong|h\d)>', re.I), '[B]'),
|
||||
(re.compile(r'</(strong|h\d)>', re.I), '[/B]'),
|
||||
(re.compile(r'<li>', 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')
|
||||
|
@ -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,
|
||||
}
|
||||
)
|
||||
|
@ -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'),
|
||||
|
Loading…
Reference in New Issue
Block a user