From 2f90a29acfe6b7bbd45c2097eea31f944acb37db Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 7 Jun 2018 16:27:41 +0200 Subject: [PATCH 1/5] Fix resume for On Deck widget for direct paths --- resources/lib/PlexAPI.py | 11 ++++++++--- resources/lib/entrypoint.py | 35 +++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 54e127e0..c750d719 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -99,15 +99,20 @@ class API(object): """ return self.item.get('ratingKey') - def path(self, force_first_media=True, force_addon=False): + def path(self, force_first_media=True, force_addon=False, + direct_paths=None): """ Returns a "fully qualified path": add-on paths or direct paths depending on the current settings. Will NOT valide the playurl Returns unicode or None if something went wrong. + + Pass direct_path=True if you're calling from another Plex python + instance - because otherwise direct paths will evaluate to False! """ + direct_paths = direct_paths or state.DIRECT_PATHS filename = self.file_path(force_first_media=force_first_media) - if (not state.DIRECT_PATHS or force_addon - or self.plex_type() == v.PLEX_TYPE_CLIP): + if (not direct_paths or force_addon or + self.plex_type() == v.PLEX_TYPE_CLIP): if filename and '/' in filename: filename = filename.rsplit('/', 1) elif filename: diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index a1a78a97..e66cf7fb 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -529,40 +529,45 @@ def getOnDeck(viewid, mediatype, tagname, limit): xbmcplugin.setContent(HANDLE, 'episodes') append_show_title = settings('OnDeckTvAppendShow') == 'true' append_sxxexx = settings('OnDeckTvAppendSeason') == 'true' - directpaths = settings('useDirectPaths') == 'true' if settings('OnDeckTVextended') == 'false': # Chances are that this view is used on Kodi startup # Wait till we've connected to a PMS. At most 30s counter = 0 while window('plex_authenticated') != 'true': counter += 1 - if counter >= 300: + if counter == 300: log.error('Aborting On Deck view, we were not authenticated ' 'for the PMS') - return xbmcplugin.endOfDirectory(HANDLE, False) + xbmcplugin.endOfDirectory(HANDLE, False) + return sleep(100) xml = downloadutils.DownloadUtils().downloadUrl( '{server}/library/sections/%s/onDeck' % viewid) if xml in (None, 401): log.error('Could not download PMS xml for view %s' % viewid) - return xbmcplugin.endOfDirectory(HANDLE) - limitcounter = 0 + xbmcplugin.endOfDirectory(HANDLE, False) + return + direct_paths = settings('useDirectPaths') == '1' + counter = 0 for item in xml: api = API(item) listitem = api.create_listitem( append_show_title=append_show_title, append_sxxexx=append_sxxexx) - url = api.path() + if api.resume_point(): + listitem.setProperty('resumetime', str(api.resume_point())) + path = api.path(force_first_media=False, direct_paths=direct_paths) xbmcplugin.addDirectoryItem( handle=HANDLE, - url=url, + url=path, listitem=listitem) - limitcounter += 1 - if limitcounter == limit: + counter += 1 + if counter == limit: break - return xbmcplugin.endOfDirectory( + xbmcplugin.endOfDirectory( handle=HANDLE, cacheToDisc=settings('enableTextureCache') == 'true') + return # if the addon is called with nextup parameter, # we return the nextepisodes list of the given tagname @@ -661,8 +666,9 @@ def watchlater(): log.info('Displaying watch later plex.tv items') xbmcplugin.setContent(HANDLE, 'movies') + direct_paths = settings('useDirectPaths') == '1' for item in xml: - __build_item(item) + __build_item(item, direct_paths) xbmcplugin.endOfDirectory( handle=HANDLE, @@ -715,12 +721,13 @@ def browse_plex(key=None, plex_section_id=None): artists = False albums = False musicvideos = False + direct_paths = settings('useDirectPaths') == '1' for item in xml: if item.tag == 'Directory': __build_folder(item, plex_section_id=plex_section_id) else: typus = item.attrib.get('type') - __build_item(item) + __build_item(item, direct_paths) if typus == v.PLEX_TYPE_PHOTO: photos = True elif typus == v.PLEX_TYPE_MOVIE: @@ -803,7 +810,7 @@ def __build_folder(xml_element, plex_section_id=None): listitem=listitem) -def __build_item(xml_element): +def __build_item(xml_element, direct_paths): api = API(xml_element) listitem = api.create_listitem() resume = api.resume_point() @@ -820,7 +827,7 @@ def __build_item(xml_element): elif api.plex_type() == v.PLEX_TYPE_PHOTO: url = api.get_picture_path() else: - url = api.path() + url = api.path(direct_paths=direct_paths) if api.resume_point(): listitem.setProperty('resumetime', str(api.resume_point())) xbmcplugin.addDirectoryItem(handle=HANDLE, From 65561eea47e2c021c3de6f48d868c3b498104b86 Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 7 Jun 2018 17:11:13 +0200 Subject: [PATCH 2/5] Fix DB reset on Startup if PMS connection fails - Should fix #484 --- resources/lib/librarysync.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index 6c67a5a2..862d71d8 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -423,9 +423,6 @@ class LibrarySync(Thread): """ Compare the views to Plex """ - self.views = [] - vnodes = self.vnodes - # Get views sections = PF.get_plex_sections() try: @@ -436,6 +433,8 @@ class LibrarySync(Thread): 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.views = [] + vnodes = self.vnodes self.nodes = { v.PLEX_TYPE_MOVIE: [], @@ -1511,10 +1510,6 @@ class LibrarySync(Thread): LOG.info("Db version: %s", settings('dbCreatedWithVersion')) LOG.info('Refreshing video nodes and playlists now') - # Completely refresh Kodi playlists and video nodes - utils.delete_playlists() - utils.delete_nodes() - self.maintain_views() # Setup the paths for addon-paths (even when using direct paths) with kodidb.GetKodiDB('video') as kodi_db: kodi_db.setup_path_table() @@ -1539,7 +1534,12 @@ class LibrarySync(Thread): last_time_sync = utils.unix_timestamp() LOG.info('Initial start-up full sync starting') xbmc.executebuiltin('InhibitIdleShutdown(true)') - if self.full_sync(): + # Completely refresh Kodi playlists and video nodes + utils.delete_playlists() + utils.delete_nodes() + if not self.maintain_views(): + LOG.error('Initial maintain_views not successful') + elif self.full_sync(): LOG.info('Initial start-up full sync successful') settings('SyncInstallRunDone', value='true') self.install_sync_done = True @@ -1588,7 +1588,12 @@ class LibrarySync(Thread): if state.SUSPEND_SYNC: LOG.warning('Forcing startup sync even if Kodi is playing') state.SUSPEND_SYNC = False - if self.full_sync(): + # Completely refresh Kodi playlists and video nodes + utils.delete_playlists() + utils.delete_nodes() + if not self.maintain_views(): + LOG.info('Initial maintain_views on startup unsuccessful') + elif self.full_sync(): initial_sync_done = True last_sync = utils.unix_timestamp() LOG.info('Done initial sync on Kodi startup') From ee1a33cc4c834f72bad9ee1bd375b89aa7515684 Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 7 Jun 2018 17:15:37 +0200 Subject: [PATCH 3/5] Fix searching for PMS if there is no internet connection - Fixes #485 --- resources/lib/PlexFunctions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lib/PlexFunctions.py b/resources/lib/PlexFunctions.py index 7a127659..de165fb1 100644 --- a/resources/lib/PlexFunctions.py +++ b/resources/lib/PlexFunctions.py @@ -330,7 +330,7 @@ def _pms_list_from_plex_tv(token): xml.attrib except AttributeError: LOG.error('Could not get list of PMS from plex.tv') - return + return [] from Queue import Queue queue = Queue() From 807fb1614ed56499676e080b3dde21d10efd941c Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 7 Jun 2018 17:23:24 +0200 Subject: [PATCH 4/5] Fix context menu missing "Delete item from PMS" - Fixes #483 --- resources/lib/initialsetup.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 795cbf9e..259d5c15 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -128,10 +128,9 @@ def _write_pms_settings(url, token): return for entry in xml: if entry.attrib.get('id', '') == 'allowMediaDeletion': - settings('plex_allows_mediaDeletion', - value=entry.attrib.get('value', 'true')) - window('plex_allows_mediaDeletion', - value=entry.attrib.get('value', 'true')) + value = 'true' if entry.get('value', '1') == '1' else 'false' + settings('plex_allows_mediaDeletion', value=value) + window('plex_allows_mediaDeletion', value=value) class InitialSetup(object): From ffb0496e13a785d61959563dac3da60a7aa05c67 Mon Sep 17 00:00:00 2001 From: Croneter Date: Thu, 7 Jun 2018 17:25:25 +0200 Subject: [PATCH 5/5] Version bump --- README.md | 2 +- addon.xml | 10 ++++++++-- changelog.txt | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5435f199..16cf7b7b 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.29-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.30-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 91cb5051..a6cead06 100644 --- a/addon.xml +++ b/addon.xml @@ -1,5 +1,5 @@ - + @@ -67,7 +67,13 @@ Нативная интеграция сервера Plex в Kodi Подключите Kodi к своему серверу Plex. Плагин предполагает что вы управляете своими видео с помощью Plex (а не в Kodi). Вы можете потерять текущие базы данных музыки и видео в Kodi (так как плагин напрямую их изменяет). Используйте на свой страх и риск Используйте на свой страх и риск - version 2.0.29 (beta only): + version 2.0.30 (beta only): +- Fix resume for On Deck widget for direct paths +- Fix DB reset on Startup if PMS connection fails +- Fix searching for PMS if there is no internet connection +- Fix context menu missing "Delete item from PMS" + +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" diff --git a/changelog.txt b/changelog.txt index 1af6881a..b4c0b55f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,9 @@ +version 2.0.30 (beta only): +- Fix resume for On Deck widget for direct paths +- Fix DB reset on Startup if PMS connection fails +- Fix searching for PMS if there is no internet connection +- Fix context menu missing "Delete item from PMS" + 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