Merge branch 'hotfixes' of https://github.com/croneter/PlexKodiConnect into hotfixes
This commit is contained in:
commit
faf17f34d1
8 changed files with 53 additions and 41 deletions
|
@ -195,7 +195,10 @@ class PlexCompanion(Thread):
|
||||||
elif task['action'] == 'refreshPlayQueue':
|
elif task['action'] == 'refreshPlayQueue':
|
||||||
self._process_refresh(data)
|
self._process_refresh(data)
|
||||||
elif task['action'] == 'setStreams':
|
elif task['action'] == 'setStreams':
|
||||||
self._process_streams(data)
|
try:
|
||||||
|
self._process_streams(data)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -206,7 +206,7 @@ def discover_pms(token=None):
|
||||||
if token:
|
if token:
|
||||||
LOG.info('Checking with plex.tv for more PMS to connect to')
|
LOG.info('Checking with plex.tv for more PMS to connect to')
|
||||||
plex_pms_list = _pms_list_from_plex_tv(token)
|
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:
|
else:
|
||||||
LOG.info('No plex token supplied, only checked LAN for available PMS')
|
LOG.info('No plex token supplied, only checked LAN for available PMS')
|
||||||
plex_pms_list = []
|
plex_pms_list = []
|
||||||
|
@ -231,10 +231,18 @@ def discover_pms(token=None):
|
||||||
pms['ip'],
|
pms['ip'],
|
||||||
pms['port'])
|
pms['port'])
|
||||||
plex_pms_list.append(pms)
|
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
|
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():
|
def _plex_gdm():
|
||||||
"""
|
"""
|
||||||
PlexGDM - looks for PMS in the local LAN and returns a list of the PMS found
|
PlexGDM - looks for PMS in the local LAN and returns a list of the PMS found
|
||||||
|
|
|
@ -9,7 +9,7 @@ from threading import Thread
|
||||||
from os import makedirs
|
from os import makedirs
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from xbmc import sleep, translatePath
|
import xbmc
|
||||||
from xbmcvfs import exists
|
from xbmcvfs import exists
|
||||||
|
|
||||||
from utils import settings, language as lang, kodi_sql, try_encode, try_decode,\
|
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
|
# Abort was requested while waiting. We should exit
|
||||||
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
|
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
|
||||||
return
|
return
|
||||||
sleep(1000)
|
xbmc.sleep(1000)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = queue.get(block=False)
|
url = queue.get(block=False)
|
||||||
except Empty:
|
except Empty:
|
||||||
if not set_zero:
|
if not set_zero and not xbmc.getCondVisibility(
|
||||||
|
'Window.IsVisible(DialogAddonSettings.xml)'):
|
||||||
# Avoid saving '0' all the time
|
# Avoid saving '0' all the time
|
||||||
set_zero = True
|
set_zero = True
|
||||||
settings('caching_artwork_count', value='0')
|
settings('caching_artwork_count', value='0')
|
||||||
sleep(1000)
|
xbmc.sleep(1000)
|
||||||
continue
|
continue
|
||||||
set_zero = False
|
set_zero = False
|
||||||
if isinstance(url, ArtworkSyncMessage):
|
if isinstance(url, ArtworkSyncMessage):
|
||||||
|
@ -115,7 +116,7 @@ class Image_Cache_Thread(Thread):
|
||||||
'over-loaded. Sleep %s seconds before trying '
|
'over-loaded. Sleep %s seconds before trying '
|
||||||
'again to download %s',
|
'again to download %s',
|
||||||
2**sleeptime, double_urldecode(url))
|
2**sleeptime, double_urldecode(url))
|
||||||
sleep((2**sleeptime) * 1000)
|
xbmc.sleep((2**sleeptime) * 1000)
|
||||||
sleeptime += 1
|
sleeptime += 1
|
||||||
continue
|
continue
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
|
@ -129,11 +130,12 @@ class Image_Cache_Thread(Thread):
|
||||||
queue.task_done()
|
queue.task_done()
|
||||||
# Update the caching state in the PKC settings.
|
# Update the caching state in the PKC settings.
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter > 20:
|
if (counter > 20 and not xbmc.getCondVisibility(
|
||||||
|
'Window.IsVisible(DialogAddonSettings.xml)')):
|
||||||
counter = 0
|
counter = 0
|
||||||
settings('caching_artwork_count', value=str(queue.qsize()))
|
settings('caching_artwork_count', value=str(queue.qsize()))
|
||||||
# Sleep for a bit to reduce CPU strain
|
# Sleep for a bit to reduce CPU strain
|
||||||
sleep(sleep_between)
|
xbmc.sleep(sleep_between)
|
||||||
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
|
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,7 +202,7 @@ class Artwork():
|
||||||
if dialog('yesno', "Image Texture Cache", lang(39251)):
|
if dialog('yesno', "Image Texture Cache", lang(39251)):
|
||||||
LOG.info("Resetting all cache data first")
|
LOG.info("Resetting all cache data first")
|
||||||
# Remove all existing textures first
|
# Remove all existing textures first
|
||||||
path = try_decode(translatePath("special://thumbnails/"))
|
path = try_decode(xbmc.translatePath("special://thumbnails/"))
|
||||||
if exists_dir(path):
|
if exists_dir(path):
|
||||||
rmtree(path, ignore_errors=True)
|
rmtree(path, ignore_errors=True)
|
||||||
self.restore_cache_directories()
|
self.restore_cache_directories()
|
||||||
|
@ -318,7 +320,7 @@ class Artwork():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# Delete thumbnail as well as the entry
|
# 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)
|
LOG.debug("Deleting cached thumbnail: %s", path)
|
||||||
if exists(path):
|
if exists(path):
|
||||||
rmtree(try_decode(path), ignore_errors=True)
|
rmtree(try_decode(path), ignore_errors=True)
|
||||||
|
@ -334,8 +336,8 @@ class Artwork():
|
||||||
"a", "b", "c", "d", "e", "f",
|
"a", "b", "c", "d", "e", "f",
|
||||||
"Video", "plex")
|
"Video", "plex")
|
||||||
for path in paths:
|
for path in paths:
|
||||||
makedirs(try_decode(translatePath("special://thumbnails/%s"
|
makedirs(try_decode(xbmc.translatePath("special://thumbnails/%s"
|
||||||
% path)))
|
% path)))
|
||||||
|
|
||||||
|
|
||||||
class ArtworkSyncMessage(object):
|
class ArtworkSyncMessage(object):
|
||||||
|
|
|
@ -32,7 +32,7 @@ class DownloadUtils():
|
||||||
_shared_state = {}
|
_shared_state = {}
|
||||||
|
|
||||||
# How many failed attempts before declaring PMS dead?
|
# How many failed attempts before declaring PMS dead?
|
||||||
connectionAttempts = 2
|
connectionAttempts = 1
|
||||||
# How many 401 returns before declaring unauthorized?
|
# How many 401 returns before declaring unauthorized?
|
||||||
unauthorizedAttempts = 2
|
unauthorizedAttempts = 2
|
||||||
# How long should we wait for an answer from the
|
# 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. '
|
LOG.warn('Failed to connect to %s too many times. '
|
||||||
'Declare PMS dead', url)
|
'Declare PMS dead', url)
|
||||||
window('plex_online', value="false")
|
window('plex_online', value="false")
|
||||||
except:
|
except ValueError:
|
||||||
# 'countError' not yet set
|
# 'countError' not yet set
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -3,7 +3,7 @@ from logging import getLogger
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Empty
|
from Queue import Empty
|
||||||
|
|
||||||
from xbmc import sleep
|
import xbmc
|
||||||
|
|
||||||
from utils import thread_methods, settings, language as lang, dialog
|
from utils import thread_methods, settings, language as lang, dialog
|
||||||
import plexdb_functions as plexdb
|
import plexdb_functions as plexdb
|
||||||
|
@ -59,16 +59,17 @@ class ThreadedProcessFanart(Thread):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
LOG.info("---===### Stopped FanartSync ###===---")
|
LOG.info("---===### Stopped FanartSync ###===---")
|
||||||
return
|
return
|
||||||
sleep(1000)
|
xbmc.sleep(1000)
|
||||||
# grabs Plex item from queue
|
# grabs Plex item from queue
|
||||||
try:
|
try:
|
||||||
item = queue.get(block=False)
|
item = queue.get(block=False)
|
||||||
except Empty:
|
except Empty:
|
||||||
if not set_zero:
|
if not set_zero and not xbmc.getCondVisibility(
|
||||||
|
'Window.IsVisible(DialogAddonSettings.xml)'):
|
||||||
# Avoid saving '0' all the time
|
# Avoid saving '0' all the time
|
||||||
set_zero = True
|
set_zero = True
|
||||||
settings('fanarttv_lookups', value='0')
|
settings('fanarttv_lookups', value='0')
|
||||||
sleep(200)
|
xbmc.sleep(200)
|
||||||
continue
|
continue
|
||||||
set_zero = False
|
set_zero = False
|
||||||
if isinstance(item, ArtworkSyncMessage):
|
if isinstance(item, ArtworkSyncMessage):
|
||||||
|
@ -92,7 +93,8 @@ class ThreadedProcessFanart(Thread):
|
||||||
plex_db.set_fanart_synched(item['plex_id'])
|
plex_db.set_fanart_synched(item['plex_id'])
|
||||||
# Update the caching state in the PKC settings. Avoid saving '0'
|
# Update the caching state in the PKC settings. Avoid saving '0'
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter > 10:
|
if (counter > 20 and not xbmc.getCondVisibility(
|
||||||
|
'Window.IsVisible(DialogAddonSettings.xml)')):
|
||||||
counter = 0
|
counter = 0
|
||||||
settings('fanarttv_lookups', value=str(queue.qsize()))
|
settings('fanarttv_lookups', value=str(queue.qsize()))
|
||||||
queue.task_done()
|
queue.task_done()
|
||||||
|
|
|
@ -62,7 +62,11 @@ def playback_triage(plex_id=None, plex_type=None, path=None, resolve=True):
|
||||||
return
|
return
|
||||||
playqueue = PQ.get_playqueue_from_type(
|
playqueue = PQ.get_playqueue_from_type(
|
||||||
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type])
|
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[plex_type])
|
||||||
pos = js.get_position(playqueue.playlistid)
|
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")
|
# Can return -1 (as in "no playlist")
|
||||||
pos = pos if pos != -1 else 0
|
pos = pos if pos != -1 else 0
|
||||||
LOG.debug('playQueue position %s for %s', pos, playqueue)
|
LOG.debug('playQueue position %s for %s', pos, playqueue)
|
||||||
|
|
|
@ -264,8 +264,10 @@ class UserClient(Thread):
|
||||||
Reset all user settings
|
Reset all user settings
|
||||||
"""
|
"""
|
||||||
LOG.debug("Reset UserClient authentication.")
|
LOG.debug("Reset UserClient authentication.")
|
||||||
self.do_utils.stopSession()
|
try:
|
||||||
|
self.do_utils.stopSession()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
window('plex_authenticated', clear=True)
|
window('plex_authenticated', clear=True)
|
||||||
state.AUTHENTICATED = False
|
state.AUTHENTICATED = False
|
||||||
window('pms_token', clear=True)
|
window('pms_token', clear=True)
|
||||||
|
|
|
@ -57,7 +57,6 @@ class WebSocket(Thread):
|
||||||
LOG.info("----===## Starting %s ##===----", self.__class__.__name__)
|
LOG.info("----===## Starting %s ##===----", self.__class__.__name__)
|
||||||
|
|
||||||
counter = 0
|
counter = 0
|
||||||
handshake_counter = 0
|
|
||||||
stopped = self.stopped
|
stopped = self.stopped
|
||||||
suspended = self.suspended
|
suspended = self.suspended
|
||||||
while not stopped():
|
while not stopped():
|
||||||
|
@ -94,9 +93,10 @@ class WebSocket(Thread):
|
||||||
LOG.info("%s: Error connecting", self.__class__.__name__)
|
LOG.info("%s: Error connecting", self.__class__.__name__)
|
||||||
self.ws = None
|
self.ws = None
|
||||||
counter += 1
|
counter += 1
|
||||||
if counter > 3:
|
if counter >= 10:
|
||||||
counter = 0
|
LOG.info('%s: Repeated IOError detected. Stopping now',
|
||||||
self.IOError_response()
|
self.__class__.__name__)
|
||||||
|
break
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
except websocket.WebSocketTimeoutException:
|
except websocket.WebSocketTimeoutException:
|
||||||
LOG.info("%s: Timeout while connecting, trying again",
|
LOG.info("%s: Timeout while connecting, trying again",
|
||||||
|
@ -106,10 +106,10 @@ class WebSocket(Thread):
|
||||||
except websocket.WebSocketException as e:
|
except websocket.WebSocketException as e:
|
||||||
LOG.info('%s: WebSocketException: %s',
|
LOG.info('%s: WebSocketException: %s',
|
||||||
self.__class__.__name__, e)
|
self.__class__.__name__, e)
|
||||||
if ('Handshake Status 401' in e.args
|
if ('Handshake Status 401' in e.args or
|
||||||
or 'Handshake Status 403' in e.args):
|
'Handshake Status 403' in e.args):
|
||||||
handshake_counter += 1
|
counter += 1
|
||||||
if handshake_counter >= 5:
|
if counter >= 5:
|
||||||
LOG.info('%s: Error in handshake detected. '
|
LOG.info('%s: Error in handshake detected. '
|
||||||
'Stopping now', self.__class__.__name__)
|
'Stopping now', self.__class__.__name__)
|
||||||
break
|
break
|
||||||
|
@ -125,7 +125,6 @@ class WebSocket(Thread):
|
||||||
sleep(1000)
|
sleep(1000)
|
||||||
else:
|
else:
|
||||||
counter = 0
|
counter = 0
|
||||||
handshake_counter = 0
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("%s: Unknown exception encountered: %s",
|
LOG.error("%s: Unknown exception encountered: %s",
|
||||||
self.__class__.__name__, e)
|
self.__class__.__name__, e)
|
||||||
|
@ -202,11 +201,6 @@ class PMS_Websocket(WebSocket):
|
||||||
# Put PMS message on queue and let libsync take care of it
|
# Put PMS message on queue and let libsync take care of it
|
||||||
state.WEBSOCKET_QUEUE.put(message)
|
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):
|
class Alexa_Websocket(WebSocket):
|
||||||
"""
|
"""
|
||||||
|
@ -252,9 +246,6 @@ class Alexa_Websocket(WebSocket):
|
||||||
return
|
return
|
||||||
process_command(message.attrib['path'][1:], message.attrib)
|
process_command(message.attrib['path'][1:], message.attrib)
|
||||||
|
|
||||||
def IOError_response(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Path in thread_methods
|
# Path in thread_methods
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.thread_stopped = True
|
self.thread_stopped = True
|
||||||
|
|
Loading…
Reference in a new issue