Fix UnicodeDecodeError for non-ASCII filenames

- Fixes #222
This commit is contained in:
tomkat83 2017-02-13 19:27:14 +01:00
parent ef63b7b650
commit cd7b509248

View file

@ -8,7 +8,7 @@ import xbmc
import xbmcgui import xbmcgui
from utils import window, settings, language as lang, DateToKodi, \ from utils import window, settings, language as lang, DateToKodi, \
getUnixTimestamp getUnixTimestamp, tryDecode, tryEncode
import downloadutils import downloadutils
import plexdb_functions as plexdb import plexdb_functions as plexdb
import kodidb_functions as kodidb import kodidb_functions as kodidb
@ -48,7 +48,7 @@ class Player(xbmc.Player):
# Get current file (in utf-8!) # Get current file (in utf-8!)
try: try:
currentFile = self.getPlayingFile() currentFile = tryDecode(self.getPlayingFile())
xbmc.sleep(300) xbmc.sleep(300)
except: except:
currentFile = "" currentFile = ""
@ -56,7 +56,7 @@ class Player(xbmc.Player):
while not currentFile: while not currentFile:
xbmc.sleep(100) xbmc.sleep(100)
try: try:
currentFile = self.getPlayingFile() currentFile = tryDecode(self.getPlayingFile())
except: except:
pass pass
if count == 20: if count == 20:
@ -69,13 +69,13 @@ class Player(xbmc.Player):
# Save currentFile for cleanup later and for references # Save currentFile for cleanup later and for references
self.currentFile = currentFile self.currentFile = currentFile
window('plex_lastPlayedFiled', value=currentFile) window('plex_lastPlayedFiled', value=tryEncode(currentFile))
# We may need to wait for info to be set in kodi monitor # We may need to wait for info to be set in kodi monitor
itemId = window("plex_%s.itemid" % currentFile) itemId = window("plex_%s.itemid" % tryEncode(currentFile))
count = 0 count = 0
while not itemId: while not itemId:
xbmc.sleep(200) xbmc.sleep(200)
itemId = window("plex_%s.itemid" % currentFile) itemId = window("plex_%s.itemid" % tryEncode(currentFile))
if count == 5: if count == 5:
log.warn("Could not find itemId, cancelling playback report!") log.warn("Could not find itemId, cancelling playback report!")
return return
@ -83,7 +83,7 @@ class Player(xbmc.Player):
log.info("ONPLAYBACK_STARTED: %s itemid: %s" % (currentFile, itemId)) log.info("ONPLAYBACK_STARTED: %s itemid: %s" % (currentFile, itemId))
plexitem = "plex_%s" % currentFile plexitem = "plex_%s" % tryEncode(currentFile)
runtime = window("%s.runtime" % plexitem) runtime = window("%s.runtime" % plexitem)
refresh_id = window("%s.refreshid" % plexitem) refresh_id = window("%s.refreshid" % plexitem)
playMethod = window("%s.playmethod" % plexitem) playMethod = window("%s.playmethod" % plexitem)
@ -146,8 +146,10 @@ class Player(xbmc.Player):
# Get the current audio track and subtitles # Get the current audio track and subtitles
if playMethod == "Transcode": if playMethod == "Transcode":
# property set in PlayUtils.py # property set in PlayUtils.py
postdata['AudioStreamIndex'] = window("%sAudioStreamIndex" % currentFile) postdata['AudioStreamIndex'] = window("%sAudioStreamIndex"
postdata['SubtitleStreamIndex'] = window("%sSubtitleStreamIndex" % currentFile) % tryEncode(currentFile))
postdata['SubtitleStreamIndex'] = window("%sSubtitleStreamIndex"
% tryEncode(currentFile))
else: else:
# Get the current kodi audio and subtitles and convert to plex equivalent # Get the current kodi audio and subtitles and convert to plex equivalent
tracks_query = { tracks_query = {
@ -385,15 +387,16 @@ class Player(xbmc.Player):
# Clean the WINDOW properties # Clean the WINDOW properties
for filename in self.played_info: for filename in self.played_info:
plex_item = 'plex_%s' % tryEncode(filename)
cleanup = ( cleanup = (
'plex_%s.itemid' % filename, '%s.itemid' % plex_item,
'plex_%s.runtime' % filename, '%s.runtime' % plex_item,
'plex_%s.refreshid' % filename, '%s.refreshid' % plex_item,
'plex_%s.playmethod' % filename, '%s.playmethod' % plex_item,
'plex_%s.type' % filename, '%s.type' % plex_item,
'plex_%s.runtime' % filename, '%s.runtime' % plex_item,
'plex_%s.playcount' % filename, '%s.playcount' % plex_item,
'plex_%s.playlistPosition' % filename '%s.playlistPosition' % plex_item
) )
for item in cleanup: for item in cleanup:
window(item, clear=True) window(item, clear=True)