From fdbe42a05a240b781c37be5712f8f6e7a0a7b1fc Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 10:42:57 +0100 Subject: [PATCH 1/8] Fix keyError sessionKey for weird PMS messages --- resources/lib/library_sync/websocket.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/lib/library_sync/websocket.py b/resources/lib/library_sync/websocket.py index bdc1bf98..c302f8d9 100644 --- a/resources/lib/library_sync/websocket.py +++ b/resources/lib/library_sync/websocket.py @@ -256,6 +256,9 @@ def process_playing(data): skip = True if skip: continue + if 'sessionKey' not in message: + LOG.warn('Received malformed message from the PMS: %s', message) + continue session_key = message['sessionKey'] # Do we already have a sessionKey stored? if session_key not in PLAYSTATE_SESSIONS: From d09d2e6aaf344ec8222a06d781f792d5ed831834 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 10:53:10 +0100 Subject: [PATCH 2/8] Fix playlist sync: sequence item 0: expected string or unicode --- resources/lib/playlists/pms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/lib/playlists/pms.py b/resources/lib/playlists/pms.py index ccafd3bf..2d69ee75 100644 --- a/resources/lib/playlists/pms.py +++ b/resources/lib/playlists/pms.py @@ -108,7 +108,8 @@ def add_items(playlist, plex_ids): 'title': playlist.plex_name, 'smart': 0, 'uri': ('server://%s/com.plexapp.plugins.library/library/metadata/%s' - % (app.CONN.machine_identifier, ','.join(plex_ids))) + % (app.CONN.machine_identifier, + ','.join(unicode(x) for x in plex_ids))) } xml = DU().downloadUrl(url='{server}/playlists/', action_type='POST', From 3a9fcacd5c3af84e0ef99aae9fd17c82a8ae3b44 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 11:24:55 +0100 Subject: [PATCH 3/8] Fix PKC not deleting all the items it should --- resources/lib/library_sync/full_sync.py | 17 +++++++++++------ resources/lib/plex_db/common.py | 9 +++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/resources/lib/library_sync/full_sync.py b/resources/lib/library_sync/full_sync.py index 6e2b1119..83c0528b 100644 --- a/resources/lib/library_sync/full_sync.py +++ b/resources/lib/library_sync/full_sync.py @@ -372,12 +372,17 @@ class FullSync(common.fullsync_mixin): ]) for plex_type, context in kinds: # Delete movies that are not on Plex anymore - with context(self.current_sync) as ctx: - for plex_id in ctx.plexdb.plex_id_by_last_sync(plex_type, - self.current_sync): - if self.isCanceled(): - return False - ctx.remove(plex_id, plex_type) + while True: + with context(self.current_sync) as ctx: + plex_ids = list(ctx.plexdb.plex_id_by_last_sync(plex_type, + self.current_sync, + BATCH_SIZE)) + for plex_id in plex_ids: + if self.isCanceled(): + return False + ctx.remove(plex_id, plex_type) + if len(plex_ids) < BATCH_SIZE: + break LOG.debug('Done deleting') return True diff --git a/resources/lib/plex_db/common.py b/resources/lib/plex_db/common.py index 0ce2af9b..dcacabfd 100644 --- a/resources/lib/plex_db/common.py +++ b/resources/lib/plex_db/common.py @@ -100,13 +100,14 @@ class PlexDBBase(object): method = getattr(self, 'entry_to_%s' % v.PLEX_TYPE_FROM_KODI_TYPE[kodi_type]) return method(self.cursor.fetchone()) - def plex_id_by_last_sync(self, plex_type, last_sync): + def plex_id_by_last_sync(self, plex_type, last_sync, limit): """ Returns an iterator for all items where the last_sync is NOT identical """ - return (x[0] for x in - self.cursor.execute('SELECT plex_id FROM %s WHERE last_sync <> ?' % plex_type, - (last_sync, ))) + query = ''' + SELECT plex_id FROM %s WHERE last_sync <> ? LIMIT %s + ''' % (plex_type, limit) + return (x[0] for x in self.cursor.execute(query, (last_sync, ))) def checksum(self, plex_id, plex_type): """ From 996adc2c038d8742b481a4fa2219656773835890 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 11:30:03 +0100 Subject: [PATCH 4/8] Fix artwork caching AttributeError --- resources/lib/sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/sync.py b/resources/lib/sync.py index c6fd0c7b..2c3ba4ba 100644 --- a/resources/lib/sync.py +++ b/resources/lib/sync.py @@ -135,7 +135,7 @@ class Sync(backgroundthread.KillableThread): LOG.info('Not synching Plex artwork - not caching') return if self.image_cache_thread and self.image_cache_thread.is_alive(): - self.image_cache_thread.cancel() + self.image_cache_thread.abort() self.image_cache_thread.join() self.image_cache_thread = artwork.ImageCachingThread() self.image_cache_thread.start() From fb9c560ccd5ddc0611e4410a4777b0b00535330a Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 11:34:16 +0100 Subject: [PATCH 5/8] Fix FutureWarning --- resources/lib/plex_tv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/plex_tv.py b/resources/lib/plex_tv.py index 3cb35d77..c6712b4f 100644 --- a/resources/lib/plex_tv.py +++ b/resources/lib/plex_tv.py @@ -264,7 +264,7 @@ def _sign_in_with_pin(): return app.APP.monitor.waitForAbort(0.1) if not pinlogin.expired: - if pinlogin.xml: + if pinlogin.xml is not None: pin_login_window.setLinking() return pinlogin.xml finally: From 65fe1ed3991dba215699e225754db0ed5bc88204 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 13:02:45 +0100 Subject: [PATCH 6/8] Show info pop-up "Searching for PMS" until PKC displays the results --- resources/lib/initialsetup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 4dcda83f..926c1528 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -314,7 +314,7 @@ class InitialSetup(object): heading='{plex}', message=utils.lang(30001), icon='{plex}', - time=5000) + time=60000) while True: if https_updated is False: serverlist = PF.discover_pms(self.plex_token) @@ -343,6 +343,8 @@ class InitialSetup(object): dialoglist.append('%s (%s)' % (server['name'], msg)) # Let user pick server from a list + # Close the PKC info "Searching for PMS" + executebuiltin("Dialog.Close(all, true)") resp = utils.dialog('select', utils.lang(39012), dialoglist) if resp == -1: # User cancelled From b858373aeb997c9f531bec038ba996d73732ff0e Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 13:24:31 +0100 Subject: [PATCH 7/8] Also show a pop-up if PKC searches for changed PMS address on PKC startup --- resources/lib/initialsetup.py | 76 ++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 926c1528..43718a35 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -220,7 +220,7 @@ class InitialSetup(object): verifySSL=verifySSL) return chk - def pick_pms(self, showDialog=False): + def pick_pms(self, showDialog=False, inform_of_search=False): """ Searches for PMS in local Lan and optionally (if self.plex_token set) also on plex.tv @@ -260,10 +260,10 @@ class InitialSetup(object): if showDialog is True: server = self._user_pick_pms() else: - server = self._auto_pick_pms() + server = self._auto_pick_pms(show_dialog=inform_of_search) return server - def _auto_pick_pms(self): + def _auto_pick_pms(self, show_dialog=False): """ Will try to pick PMS based on machineIdentifier saved in file settings but only once @@ -272,35 +272,47 @@ class InitialSetup(object): """ https_updated = False server = None - while True: - if https_updated is False: - serverlist = PF.discover_pms(self.plex_token) - for item in serverlist: - if item.get('machineIdentifier') == app.CONN.machine_identifier: - server = item - if server is None: - name = utils.settings('plex_servername') - LOG.warn('The PMS you have used before with a unique ' - 'machineIdentifier of %s and name %s is ' - 'offline', app.CONN.machine_identifier, name) + if show_dialog: + # Searching for PMS + utils.dialog('notification', + heading='{plex}', + message=utils.lang(30001), + icon='{plex}', + time=60000) + try: + while True: + if https_updated is False: + serverlist = PF.discover_pms(self.plex_token) + for item in serverlist: + if item.get('machineIdentifier') == app.CONN.machine_identifier: + server = item + if server is None: + name = utils.settings('plex_servername') + LOG.warn('The PMS you have used before with a unique ' + 'machineIdentifier of %s and name %s is ' + 'offline', app.CONN.machine_identifier, name) + return + chk = self._check_pms_connectivity(server) + if chk == 504 and https_updated is False: + # switch HTTPS to HTTP or vice-versa + if server['scheme'] == 'https': + server['scheme'] = 'http' + else: + server['scheme'] = 'https' + https_updated = True + continue + # Problems connecting + elif chk >= 400 or chk is False: + LOG.warn('Problems connecting to server %s. chk is %s', + server['name'], chk) return - chk = self._check_pms_connectivity(server) - if chk == 504 and https_updated is False: - # switch HTTPS to HTTP or vice-versa - if server['scheme'] == 'https': - server['scheme'] = 'http' - else: - server['scheme'] = 'https' - https_updated = True - continue - # Problems connecting - elif chk >= 400 or chk is False: - LOG.warn('Problems connecting to server %s. chk is %s', - server['name'], chk) - return - LOG.info('We found a server to automatically connect to: %s', - server['name']) - return server + LOG.info('We found a server to automatically connect to: %s', + server['name']) + return server + finally: + if show_dialog: + executebuiltin("Dialog.Close(all, true)") + def _user_pick_pms(self): """ @@ -553,7 +565,7 @@ class InitialSetup(object): if not self.plex_token and app.ACCOUNT.myplexlogin: self.plex_tv_sign_in() - server = self.pick_pms() + server = self.pick_pms(inform_of_search=True) if server is not None: # Write our chosen server to Kodi settings file self.save_pms_settings(server['baseURL'], server['token']) From 7d7d40bc0de73959c3ce1fc92babc74b3c08f682 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 13:29:46 +0100 Subject: [PATCH 8/8] Stable and beta version bump 2.6.2 --- README.md | 4 ++-- addon.xml | 12 ++++++++++-- changelog.txt | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1ce160bd..25b29ded 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![stable version](https://img.shields.io/badge/stable_version-2.6.1-blue.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/stable/repository.plexkodiconnect/repository.plexkodiconnect-1.0.2.zip) -[![beta version](https://img.shields.io/badge/beta_version-2.6.1-red.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/beta/repository.plexkodiconnectbeta/repository.plexkodiconnectbeta-1.0.2.zip) +[![stable version](https://img.shields.io/badge/stable_version-2.6.2-blue.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/stable/repository.plexkodiconnect/repository.plexkodiconnect-1.0.2.zip) +[![beta version](https://img.shields.io/badge/beta_version-2.6.2-red.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/beta/repository.plexkodiconnectbeta/repository.plexkodiconnectbeta-1.0.2.zip) [![Installation](https://img.shields.io/badge/wiki-installation-brightgreen.svg?maxAge=60&style=flat)](https://github.com/croneter/PlexKodiConnect/wiki/Installation) [![FAQ](https://img.shields.io/badge/wiki-FAQ-brightgreen.svg?maxAge=60&style=flat)](https://github.com/croneter/PlexKodiConnect/wiki/faq) diff --git a/addon.xml b/addon.xml index aac1e503..112693c9 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -77,7 +77,15 @@ Нативна інтеграція Plex в Kodi Підключає Kodi до серверу Plex. Цей плагін передбачає, що ви керуєте всіма своїми відео за допомогою Plex (і ніяк не Kodi). Ви можете втратити дані, які вже зберігаються у відео та музичних БД Kodi (оскільки цей плагін безпосередньо їх змінює). Використовуйте на свій страх і ризик! Використовуйте на свій ризик - version 2.6.1: + version 2.6.2: +- Fix playlist sync: sequence item 0: expected string or unicode +- Fix PKC not deleting all the items it should +- Fix keyError 'sessionKey' for weird PMS messages +- Fix artwork caching AttributeError: 'ImageCachingThread' object has no attribute 'cancel' +- Improve pop-up "Searching for PMS" +- Fix FutureWarning + +version 2.6.1: - WARNING: You will need to reset the Kodi database! - Fix TV sections not being deleted e.g. after user switch - Don't show a library sync error pop-up when full sync is interrupted diff --git a/changelog.txt b/changelog.txt index b4d9d91b..8cc2ac14 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,11 @@ +version 2.6.2: +- Fix playlist sync: sequence item 0: expected string or unicode +- Fix PKC not deleting all the items it should +- Fix keyError 'sessionKey' for weird PMS messages +- Fix artwork caching AttributeError: 'ImageCachingThread' object has no attribute 'cancel' +- Improve pop-up "Searching for PMS" +- Fix FutureWarning + version 2.6.1: - WARNING: You will need to reset the Kodi database! - Fix TV sections not being deleted e.g. after user switch