Merge branch 'hotfixes' of https://github.com/croneter/PlexKodiConnect into hotfixes

This commit is contained in:
croneter 2018-06-01 19:56:47 +02:00
commit faf17f34d1
8 changed files with 53 additions and 41 deletions

View file

@ -195,7 +195,10 @@ class PlexCompanion(Thread):
elif task['action'] == 'refreshPlayQueue':
self._process_refresh(data)
elif task['action'] == 'setStreams':
try:
self._process_streams(data)
except KeyError:
pass
def run(self):
"""

View file

@ -206,7 +206,7 @@ def discover_pms(token=None):
if token:
LOG.info('Checking with plex.tv for more PMS to connect to')
plex_pms_list = _pms_list_from_plex_tv(token)
LOG.debug('PMS found on plex.tv: %s', plex_pms_list)
_log_pms(plex_pms_list)
else:
LOG.info('No plex token supplied, only checked LAN for available PMS')
plex_pms_list = []
@ -231,10 +231,18 @@ def discover_pms(token=None):
pms['ip'],
pms['port'])
plex_pms_list.append(pms)
LOG.debug('Found the following PMS in total: %s', plex_pms_list)
_log_pms(plex_pms_list)
return plex_pms_list
def _log_pms(pms_list):
log_list = deepcopy(pms_list)
for pms in log_list:
if pms.get('token') is not None:
pms['token'] = '%s...' % pms['token'][:5]
LOG.debug('Found the following PMS: %s', log_list)
def _plex_gdm():
"""
PlexGDM - looks for PMS in the local LAN and returns a list of the PMS found

View file

@ -9,7 +9,7 @@ from threading import Thread
from os import makedirs
import requests
from xbmc import sleep, translatePath
import xbmc
from xbmcvfs import exists
from utils import settings, language as lang, kodi_sql, try_encode, try_decode,\
@ -64,16 +64,17 @@ class Image_Cache_Thread(Thread):
# Abort was requested while waiting. We should exit
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
return
sleep(1000)
xbmc.sleep(1000)
try:
url = queue.get(block=False)
except Empty:
if not set_zero:
if not set_zero and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)'):
# Avoid saving '0' all the time
set_zero = True
settings('caching_artwork_count', value='0')
sleep(1000)
xbmc.sleep(1000)
continue
set_zero = False
if isinstance(url, ArtworkSyncMessage):
@ -115,7 +116,7 @@ class Image_Cache_Thread(Thread):
'over-loaded. Sleep %s seconds before trying '
'again to download %s',
2**sleeptime, double_urldecode(url))
sleep((2**sleeptime) * 1000)
xbmc.sleep((2**sleeptime) * 1000)
sleeptime += 1
continue
except Exception as err:
@ -129,11 +130,12 @@ class Image_Cache_Thread(Thread):
queue.task_done()
# Update the caching state in the PKC settings.
counter += 1
if counter > 20:
if (counter > 20 and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)')):
counter = 0
settings('caching_artwork_count', value=str(queue.qsize()))
# Sleep for a bit to reduce CPU strain
sleep(sleep_between)
xbmc.sleep(sleep_between)
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
@ -200,7 +202,7 @@ class Artwork():
if dialog('yesno', "Image Texture Cache", lang(39251)):
LOG.info("Resetting all cache data first")
# Remove all existing textures first
path = try_decode(translatePath("special://thumbnails/"))
path = try_decode(xbmc.translatePath("special://thumbnails/"))
if exists_dir(path):
rmtree(path, ignore_errors=True)
self.restore_cache_directories()
@ -318,7 +320,7 @@ class Artwork():
pass
else:
# Delete thumbnail as well as the entry
path = translatePath("special://thumbnails/%s" % cachedurl)
path = xbmc.translatePath("special://thumbnails/%s" % cachedurl)
LOG.debug("Deleting cached thumbnail: %s", path)
if exists(path):
rmtree(try_decode(path), ignore_errors=True)
@ -334,7 +336,7 @@ class Artwork():
"a", "b", "c", "d", "e", "f",
"Video", "plex")
for path in paths:
makedirs(try_decode(translatePath("special://thumbnails/%s"
makedirs(try_decode(xbmc.translatePath("special://thumbnails/%s"
% path)))

View file

@ -32,7 +32,7 @@ class DownloadUtils():
_shared_state = {}
# How many failed attempts before declaring PMS dead?
connectionAttempts = 2
connectionAttempts = 1
# How many 401 returns before declaring unauthorized?
unauthorizedAttempts = 2
# How long should we wait for an answer from the
@ -318,7 +318,7 @@ class DownloadUtils():
LOG.warn('Failed to connect to %s too many times. '
'Declare PMS dead', url)
window('plex_online', value="false")
except:
except ValueError:
# 'countError' not yet set
pass
return None

View file

@ -3,7 +3,7 @@ from logging import getLogger
from threading import Thread
from Queue import Empty
from xbmc import sleep
import xbmc
from utils import thread_methods, settings, language as lang, dialog
import plexdb_functions as plexdb
@ -59,16 +59,17 @@ class ThreadedProcessFanart(Thread):
# Abort was requested while waiting. We should exit
LOG.info("---===### Stopped FanartSync ###===---")
return
sleep(1000)
xbmc.sleep(1000)
# grabs Plex item from queue
try:
item = queue.get(block=False)
except Empty:
if not set_zero:
if not set_zero and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)'):
# Avoid saving '0' all the time
set_zero = True
settings('fanarttv_lookups', value='0')
sleep(200)
xbmc.sleep(200)
continue
set_zero = False
if isinstance(item, ArtworkSyncMessage):
@ -92,7 +93,8 @@ class ThreadedProcessFanart(Thread):
plex_db.set_fanart_synched(item['plex_id'])
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
if (counter > 20 and not xbmc.getCondVisibility(
'Window.IsVisible(DialogAddonSettings.xml)')):
counter = 0
settings('fanarttv_lookups', value=str(queue.qsize()))
queue.task_done()

View file

@ -62,7 +62,11 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
return
playqueue = PQ.get_playqueue_from_type(
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type])
try:
pos = js.get_position(playqueue.playlistid)
except KeyError:
LOG.warning('No position returned from Kodi player! Assuming 0')
pos = 0
# Can return -1 (as in "no playlist")
pos = pos if pos != -1 else 0
LOG.debug('playQueue position %s for %s', pos, playqueue)

View file

@ -264,8 +264,10 @@ class UserClient(Thread):
Reset all user settings
"""
LOG.debug("Reset UserClient authentication.")
try:
self.do_utils.stopSession()
except AttributeError:
pass
window('plex_authenticated', clear=True)
state.AUTHENTICATED = False
window('pms_token', clear=True)

View file

@ -57,7 +57,6 @@ class WebSocket(Thread):
LOG.info("----===## Starting %s ##===----", self.__class__.__name__)
counter = 0
handshake_counter = 0
stopped = self.stopped
suspended = self.suspended
while not stopped():
@ -94,9 +93,10 @@ class WebSocket(Thread):
LOG.info("%s: Error connecting", self.__class__.__name__)
self.ws = None
counter += 1
if counter > 3:
counter = 0
self.IOError_response()
if counter >= 10:
LOG.info('%s: Repeated IOError detected. Stopping now',
self.__class__.__name__)
break
sleep(1000)
except websocket.WebSocketTimeoutException:
LOG.info("%s: Timeout while connecting, trying again",
@ -106,10 +106,10 @@ class WebSocket(Thread):
except websocket.WebSocketException as e:
LOG.info('%s: WebSocketException: %s',
self.__class__.__name__, e)
if ('Handshake Status 401' in e.args
or 'Handshake Status 403' in e.args):
handshake_counter += 1
if handshake_counter >= 5:
if ('Handshake Status 401' in e.args or
'Handshake Status 403' in e.args):
counter += 1
if counter >= 5:
LOG.info('%s: Error in handshake detected. '
'Stopping now', self.__class__.__name__)
break
@ -125,7 +125,6 @@ class WebSocket(Thread):
sleep(1000)
else:
counter = 0
handshake_counter = 0
except Exception as e:
LOG.error("%s: Unknown exception encountered: %s",
self.__class__.__name__, e)
@ -202,11 +201,6 @@ class PMS_Websocket(WebSocket):
# Put PMS message on queue and let libsync take care of it
state.WEBSOCKET_QUEUE.put(message)
def IOError_response(self):
LOG.warn("Repeatedly could not connect to PMS, "
"declaring the connection dead")
window('plex_online', value='false')
class Alexa_Websocket(WebSocket):
"""
@ -252,9 +246,6 @@ class Alexa_Websocket(WebSocket):
return
process_command(message.attrib['path'][1:], message.attrib)
def IOError_response(self):
pass
# Path in thread_methods
def stop(self):
self.thread_stopped = True