Fix playback not starting in some circumstances

- Fixes #330
This commit is contained in:
tomkat83 2017-08-10 21:05:46 +02:00
parent 3d58b93107
commit 73d6bfde89
2 changed files with 19 additions and 4 deletions

View file

@ -49,7 +49,7 @@ from xbmcvfs import exists
import clientinfo as client import clientinfo as client
from downloadutils import DownloadUtils from downloadutils import DownloadUtils
from utils import window, settings, language as lang, tryDecode, tryEncode, \ from utils import window, settings, language as lang, tryDecode, tryEncode, \
DateToKodi, exists_dir DateToKodi, exists_dir, slugify
from PlexFunctions import PMSHttpsEnabled from PlexFunctions import PMSHttpsEnabled
import plexdb_functions as plexdb import plexdb_functions as plexdb
import variables as v import variables as v
@ -2395,9 +2395,14 @@ class API():
log.error('Could not temporarily download subtitle %s' % url) log.error('Could not temporarily download subtitle %s' % url)
return return
else: else:
r.encoding = 'utf-8' log.debug('Writing temp subtitle to %s' % path)
try:
with open(path, 'wb') as f: with open(path, 'wb') as f:
f.write(r.content) f.write(r.content)
except UnicodeEncodeError:
log.debug('Need to slugify the filename %s' % path)
with open(slugify(path), 'wb') as f:
f.write(r.content)
return path return path
def GetKodiPremierDate(self): def GetKodiPremierDate(self):

View file

@ -221,6 +221,16 @@ def tryDecode(string, encoding='utf-8'):
return string return string
def slugify(text):
"""
Normalizes text (in unicode or string) to e.g. enable safe filenames.
Returns unicode
"""
if not isinstance(text, unicode):
text = unicode(text)
return unicode(normalize('NFKD', text).encode('ascii', 'ignore'))
def escape_html(string): def escape_html(string):
""" """
Escapes the following: Escapes the following: