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 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 diff --git a/resources/lib/kodidb_functions.py b/resources/lib/kodidb_functions.py index a6184e3a..2c0753a5 100644 --- a/resources/lib/kodidb_functions.py +++ b/resources/lib/kodidb_functions.py @@ -678,7 +678,7 @@ class KodiDBMethods(object): self.cursor.execute(query, (path,)) path_ids = self.cursor.fetchall() if len(path_ids) != 1: - LOG.error('Found wrong number of path ids: %s for path %s, abort', + LOG.debug('Found wrong number of path ids: %s for path %s, abort', path_ids, path) return query = ''' diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 9fb1cac6..4e599da7 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -434,10 +434,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 @@ -448,6 +444,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: [], @@ -1606,6 +1605,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() 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.' diff --git a/resources/lib/playqueue.py b/resources/lib/playqueue.py index cfdec32b..2ef97858 100644 --- a/resources/lib/playqueue.py +++ b/resources/lib/playqueue.py @@ -179,43 +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_playqueue(playqueue, - kodi_item=new_item) - else: - PL.add_item_to_plex_playqueue(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_playqueue(playqueue, kodi_item=new_item) else: - for j in range(i, len(index)): - index[j] += 1 + PL.add_item_to_plex_playqueue(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): @@ -227,8 +223,6 @@ 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) @@ -238,15 +232,9 @@ class PlayqueueMonitor(Thread): # 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) + # compare old and new playqueue + self._compare_playqueues(playqueue, kodi_pl) + playqueue.old_kodi_pl = list(kodi_pl) sleep(200) LOG.info("----===## PlayqueueMonitor stopped ##===----")