From 147d35ca2412172ed3c6d89f4d3987c2cd0ee334 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Jun 2018 16:38:10 +0200 Subject: [PATCH 1/7] Include Plex Home username in "Log-out Plex Home user" --- resources/lib/entrypoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index 0739ddeb..a1a78a97 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -146,7 +146,7 @@ def doMainListing(content_type=None): addDirectoryItem(lang(30173), "plugin://%s?mode=channels" % v.ADDON_ID) # Plex user switch - addDirectoryItem(lang(39200), + addDirectoryItem('%s%s' % (lang(39200), settings('username')), "plugin://%s?mode=switchuser" % v.ADDON_ID) # some extra entries for settings and stuff From 48810a227fb66bc187bbdce68594d2c4ee8a3f48 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Jun 2018 17:26:36 +0200 Subject: [PATCH 2/7] Revert "Fix playqueue monitoring locking mechanism" This reverts commit 1e43f1cc77b9198fabe028472c059b0b321d8c9e. - Should fix a racing condition if the playlist is cleared (picked up by both kodimonitor and playqueue monitor) --- resources/lib/playqueue.py | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/resources/lib/playqueue.py b/resources/lib/playqueue.py index 3bf8a61b..fd188bb3 100644 --- a/resources/lib/playqueue.py +++ b/resources/lib/playqueue.py @@ -226,26 +226,20 @@ class PlayqueueMonitor(Thread): if stopped(): break sleep(1000) - work = [] - # Detect changed playqueues first, do the work afterwards - with LOCK: - for playqueue in PLAYQUEUES: - kodi_pl = js.playlist_get_items(playqueue.playlistid) - if playqueue.old_kodi_pl != kodi_pl: - if playqueue.id is None and (not state.DIRECT_PATHS or - state.CONTEXT_MENU_PLAY): - # Only initialize if directly fired up using direct - # paths. Otherwise let default.py do its magic - LOG.debug('Not yet initiating playback') - elif playqueue.pkc_edit: - playqueue.pkc_edit = False - LOG.debug('PKC edited the playqueue - skipping') - else: - # We do need to update our playqueues - work.append((playqueue, kodi_pl)) - playqueue.old_kodi_pl = kodi_pl - # Now do the work - LOCK individual playqueue edits - for playqueue, kodi_pl in work: - self._compare_playqueues(playqueue, kodi_pl) + for playqueue in PLAYQUEUES: + kodi_pl = js.playlist_get_items(playqueue.playlistid) + if playqueue.old_kodi_pl != kodi_pl: + if playqueue.id is None and (not state.DIRECT_PATHS or + state.CONTEXT_MENU_PLAY): + # Only initialize if directly fired up using direct + # paths. Otherwise let default.py do its magic + LOG.debug('Not yet initiating playback') + elif playqueue.pkc_edit: + playqueue.pkc_edit = False + LOG.debug('PKC just edited the playqueue - skipping') + else: + # compare old and new playqueue + self._compare_playqueues(playqueue, kodi_pl) + playqueue.old_kodi_pl = list(kodi_pl) sleep(200) LOG.info("----===## PlayqueueMonitor stopped ##===----") From 87b22f1588f02d10f0698bf2dfa949d13b1da840 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Jun 2018 17:31:57 +0200 Subject: [PATCH 3/7] Revert "Make sure that LOCK is released after adding one element" This reverts commit c05b772e902183b8ed50ecf9180cfe3f30e9eb58. - Should fix a racing condition if the playlist is cleared (picked up by both kodimonitor and playqueue monitor) --- resources/lib/playqueue.py | 73 ++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/resources/lib/playqueue.py b/resources/lib/playqueue.py index fd188bb3..551d89b0 100644 --- a/resources/lib/playqueue.py +++ b/resources/lib/playqueue.py @@ -179,42 +179,39 @@ class PlayqueueMonitor(Thread): elif identical: LOG.debug('Detected playqueue item %s moved to position %s', i + j, i) - with LOCK: - PL.move_playlist_item(playqueue, i + j, i) + PL.move_playlist_item(playqueue, i + j, i) del old[j], index[j] break else: LOG.debug('Detected new Kodi element at position %s: %s ', i, new_item) - with LOCK: - try: - if playqueue.id is None: - PL.init_Plex_playlist(playqueue, kodi_item=new_item) - else: - PL.add_item_to_PMS_playlist(playqueue, - i, - kodi_item=new_item) - except PL.PlaylistError: - # Could not add the element - pass - except IndexError: - # This is really a hack - happens when using Addon Paths - # and repeatedly starting the same element. Kodi will - # then not pass kodi id nor file path AND will also not - # start-up playback. Hence kodimonitor kicks off - # playback. Also see kodimonitor.py - _playlist_onadd() - pass + try: + if playqueue.id is None: + PL.init_Plex_playlist(playqueue, kodi_item=new_item) else: - for j in range(i, len(index)): - index[j] += 1 + PL.add_item_to_PMS_playlist(playqueue, + i, + kodi_item=new_item) + except PL.PlaylistError: + # Could not add the element + pass + except IndexError: + # This is really a hack - happens when using Addon Paths + # and repeatedly starting the same element. Kodi will then + # not pass kodi id nor file path AND will also not + # start-up playback. Hence kodimonitor kicks off playback. + # Also see kodimonitor.py - _playlist_onadd() + pass + else: + for j in range(i, len(index)): + index[j] += 1 for i in reversed(index): if self.stopped(): # Chances are that we got an empty Kodi playlist due to # Kodi exit return LOG.debug('Detected deletion of playqueue element at pos %s', i) - with LOCK: - PL.delete_playlist_item_from_PMS(playqueue, i) + PL.delete_playlist_item_from_PMS(playqueue, i) LOG.debug('Done comparing playqueues') def run(self): @@ -226,20 +223,18 @@ class PlayqueueMonitor(Thread): if stopped(): break sleep(1000) - for playqueue in PLAYQUEUES: - kodi_pl = js.playlist_get_items(playqueue.playlistid) - if playqueue.old_kodi_pl != kodi_pl: - if playqueue.id is None and (not state.DIRECT_PATHS or - state.CONTEXT_MENU_PLAY): - # Only initialize if directly fired up using direct - # paths. Otherwise let default.py do its magic - LOG.debug('Not yet initiating playback') - elif playqueue.pkc_edit: - playqueue.pkc_edit = False - LOG.debug('PKC just edited the playqueue - skipping') - else: - # compare old and new playqueue - self._compare_playqueues(playqueue, kodi_pl) - playqueue.old_kodi_pl = list(kodi_pl) + with LOCK: + for playqueue in PLAYQUEUES: + kodi_pl = js.playlist_get_items(playqueue.playlistid) + if playqueue.old_kodi_pl != kodi_pl: + if playqueue.id is None and (not state.DIRECT_PATHS or + state.CONTEXT_MENU_PLAY): + # Only initialize if directly fired up using direct + # paths. Otherwise let default.py do its magic + LOG.debug('Not yet initiating playback') + else: + # compare old and new playqueue + self._compare_playqueues(playqueue, kodi_pl) + playqueue.old_kodi_pl = list(kodi_pl) sleep(200) LOG.info("----===## PlayqueueMonitor stopped ##===----") From f9121d281ca18abff41b5f5d5efdb1683129d2de Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 3 Jun 2018 13:32:25 +0200 Subject: [PATCH 4/7] Direct paths: Don't download PMS sections twice --- resources/lib/librarysync.py | 7 +++---- resources/lib/music.py | 27 ++++++++++----------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 79e2ca23..d220e97b 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -423,10 +423,6 @@ class LibrarySync(Thread): """ Compare the views to Plex """ - if state.DIRECT_PATHS is True and state.ENABLE_MUSIC is True: - # Will reboot Kodi is new library detected - music.excludefromscan_music_folders() - self.views = [] vnodes = self.vnodes @@ -437,6 +433,9 @@ class LibrarySync(Thread): except AttributeError: LOG.error("Error download PMS views, abort maintain_views") return False + if state.DIRECT_PATHS is True and state.ENABLE_MUSIC is True: + # Will reboot Kodi is new library detected + music.excludefromscan_music_folders(xml=sections) self.nodes = { v.PLEX_TYPE_MOVIE: [], diff --git a/resources/lib/music.py b/resources/lib/music.py index 5acc29e3..30e7ab61 100644 --- a/resources/lib/music.py +++ b/resources/lib/music.py @@ -4,7 +4,6 @@ from re import compile as re_compile from xml.etree.ElementTree import ParseError from utils import XmlKodiSetting, reboot_kodi, language as lang -from PlexFunctions import get_plex_sections from PlexAPI import API import variables as v @@ -15,21 +14,15 @@ REGEX_MUSICPATH = re_compile(r'''^\^(.+)\$$''') ############################################################################### -def excludefromscan_music_folders(): +def excludefromscan_music_folders(xml): """ Gets a complete list of paths for music libraries from the PMS. Sets them to be excluded in the advancedsettings.xml from being scanned by Kodi. Existing keys will be replaced + xml: etree XML PMS answer containing all library sections Reboots Kodi if new library detected """ - xml = get_plex_sections() - try: - xml[0].attrib - except (TypeError, IndexError, AttributeError): - LOG.error('Could not get Plex sections') - return - # Build paths paths = [] reboot = False api = API(item=None) @@ -46,8 +39,8 @@ def excludefromscan_music_folders(): try: with XmlKodiSetting('advancedsettings.xml', force_create=True, - top_element='advancedsettings') as xml: - parent = xml.set_setting(['audio', 'excludefromscan']) + top_element='advancedsettings') as xml_file: + parent = xml_file.set_setting(['audio', 'excludefromscan']) for path in paths: for element in parent: if element.text == path: @@ -55,14 +48,15 @@ def excludefromscan_music_folders(): break else: LOG.info('New Plex music library detected: %s', path) - xml.set_setting(['audio', 'excludefromscan', 'regexp'], - value=path, append=True) + xml_file.set_setting(['audio', 'excludefromscan', 'regexp'], + value=path, + append=True) if paths: # We only need to reboot if we ADD new paths! - reboot = xml.write_xml + reboot = xml_file.write_xml # Delete obsolete entries # Make sure we're not saving an empty audio-excludefromscan - xml.write_xml = reboot + xml_file.write_xml = reboot for element in parent: for path in paths: if element.text == path: @@ -71,10 +65,9 @@ def excludefromscan_music_folders(): LOG.info('Deleting music library from advancedsettings: %s', element.text) parent.remove(element) - xml.write_xml = True + xml_file.write_xml = True except (ParseError, IOError): LOG.error('Could not adjust advancedsettings.xml') - reboot = False if reboot is True: # 'New Plex music library detected. Sorry, but we need to # restart Kodi now due to the changes made.' From 0486934d81b3cb4f65d97c841f80464cc9ab0ede Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 3 Jun 2018 13:48:00 +0200 Subject: [PATCH 5/7] Force a sync on startup even if Kodi is playing something - Fixes #482 --- resources/lib/librarysync.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index d220e97b..6c67a5a2 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -1585,6 +1585,9 @@ class LibrarySync(Thread): state.DB_SCAN = True window('plex_dbScan', value="true") LOG.info('Doing initial sync on Kodi startup') + if state.SUSPEND_SYNC: + LOG.warning('Forcing startup sync even if Kodi is playing') + state.SUSPEND_SYNC = False if self.full_sync(): initial_sync_done = True last_sync = utils.unix_timestamp() From 9b1085c1347a78dabc7b74b0910e608355078ecd Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 3 Jun 2018 14:04:11 +0200 Subject: [PATCH 6/7] Less logging - Fixes #482 --- resources/lib/kodidb_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index eec51644..a23ce758 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -678,8 +678,8 @@ class KodiDBMethods(object): self.cursor.execute(query, (path,)) path_id = self.cursor.fetchall() if len(path_id) != 1: - LOG.error('Found wrong number of path ids: %s for path %s, abort', - path_id, path) + LOG.debug('Found wrong number of path ids: %s for path %s, abort', + path_id, path) return query = ''' SELECT idSong From cfecee44bfd44833360a4a25387092f8612f846e Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 3 Jun 2018 14:11:14 +0200 Subject: [PATCH 7/7] Version bump --- README.md | 2 +- addon.xml | 11 +++++++++-- changelog.txt | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f6bc3e3f..5435f199 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![stable version](https://img.shields.io/badge/stable_version-1.8.18-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.0.28-red.svg?maxAge=60&style=flat) ](https://github.com/croneter/binary_repo/raw/master/beta/repository.plexkodiconnectbeta/repository.plexkodiconnectbeta-1.0.2.zip) +[![beta version](https://img.shields.io/badge/beta_version-2.0.29-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 902ca238..91cb5051 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -67,7 +67,14 @@ Нативная интеграция сервера Plex в Kodi Подключите Kodi к своему серверу Plex. Плагин предполагает что вы управляете своими видео с помощью Plex (а не в Kodi). Вы можете потерять текущие базы данных музыки и видео в Kodi (так как плагин напрямую их изменяет). Используйте на свой страх и риск Используйте на свой страх и риск - version 2.0.28 (beta only): + version 2.0.29 (beta only): +- Fix a racing condition leading to e.g. Plex Companion not working as intended +- Force a sync on startup even if Kodi is playing something +- Include Plex Home username in "Log-out Plex Home user" +- Direct paths: Don't download PMS sections twice +- Less logging + +version 2.0.28 (beta only): - Fix endless reboots if Plex music library missing - Fix Plex Companion failing leading to PMS connection loss - Fix PKC add-on setting user changes not saving diff --git a/changelog.txt b/changelog.txt index 0ae550c0..1af6881a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +version 2.0.29 (beta only): +- Fix a racing condition leading to e.g. Plex Companion not working as intended +- Force a sync on startup even if Kodi is playing something +- Include Plex Home username in "Log-out Plex Home user" +- Direct paths: Don't download PMS sections twice +- Less logging + version 2.0.28 (beta only): - Fix endless reboots if Plex music library missing - Fix Plex Companion failing leading to PMS connection loss