From f9121d281ca18abff41b5f5d5efdb1683129d2de Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 3 Jun 2018 13:32:25 +0200 Subject: [PATCH] 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.'