Prompt user to select libraries to sync upon changing PMS

This commit is contained in:
croneter 2019-02-08 10:59:12 +01:00
parent 50d770718d
commit 1a1e4b113d
3 changed files with 32 additions and 11 deletions

View file

@ -84,6 +84,11 @@ def _sync_from_pms():
SECTIONS = list(plexdb.all_sections()) SECTIONS = list(plexdb.all_sections())
utils.window('Plex.nodes.total', str(len(sections))) utils.window('Plex.nodes.total', str(len(sections)))
LOG.info("Finished processing %s library sections: %s", len(sections), SECTIONS) LOG.info("Finished processing %s library sections: %s", len(sections), SECTIONS)
if app.CONN.machine_identifier != utils.settings('sections_asked_for_machine_identifier'):
LOG.info('First time connecting to this PMS, choosing libraries')
if choose_libraries():
with PlexDB() as plexdb:
SECTIONS = list(plexdb.all_sections())
return True return True
@ -265,19 +270,24 @@ def choose_libraries():
Returns True if this was successful, False if not Returns True if this was successful, False if not
""" """
# xbmcgui.Dialog().multiselect(heading, options[, autoclose, preselect, useDetails]) # Re-set value in order to make sure we got the lastest user input
# "Select Plex libraries to sync" app.SYNC.enable_music = utils.settings('enableMusic') == 'true'
import xbmcgui import xbmcgui
sections = [] sections = []
preselect = [] preselect = []
for i, section in enumerate(SECTIONS): index = 0
sections.append(section['section_name']) for section in SECTIONS:
if section['plex_type'] == v.PLEX_TYPE_ARTIST: if not app.SYNC.enable_music and section['plex_type'] == v.PLEX_TYPE_ARTIST:
if section['sync_to_kodi'] and app.SYNC.enable_music: LOG.info('Ignoring music section: %s', section)
preselect.append(i) continue
elif section['plex_type'] == v.PLEX_TYPE_PHOTO:
continue
else: else:
sections.append(section['section_name'])
if section['sync_to_kodi']: if section['sync_to_kodi']:
preselect.append(i) preselect.append(index)
index += 1
# "Select Plex libraries to sync"
selected = xbmcgui.Dialog().multiselect(utils.lang(30524), selected = xbmcgui.Dialog().multiselect(utils.lang(30524),
sections, sections,
preselect=preselect, preselect=preselect,
@ -285,10 +295,19 @@ def choose_libraries():
if selected is None: if selected is None:
# User canceled # User canceled
return False return False
index = 0
with PlexDB() as plexdb: with PlexDB() as plexdb:
for i, section in enumerate(SECTIONS): for section in SECTIONS:
sync = True if i in selected else False if not app.SYNC.enable_music and section['plex_type'] == v.PLEX_TYPE_ARTIST:
plexdb.update_section_sync(section['section_id'], sync) continue
elif section['plex_type'] == v.PLEX_TYPE_PHOTO:
continue
else:
sync = True if index in selected else False
plexdb.update_section_sync(section['section_id'], sync)
index += 1
sections = list(plexdb.all_sections()) sections = list(plexdb.all_sections())
LOG.info('Plex libraries to sync: %s', sections) LOG.info('Plex libraries to sync: %s', sections)
utils.settings('sections_asked_for_machine_identifier',
value=app.CONN.machine_identifier)
return True return True

View file

@ -466,6 +466,7 @@ def wipe_database():
kodi_db.reset_cached_images() kodi_db.reset_cached_images()
# reset the install run flag # reset the install run flag
settings('SyncInstallRunDone', value="false") settings('SyncInstallRunDone', value="false")
settings('sections_asked_for_machine_identifier', value='')
init_dbs() init_dbs()
LOG.info('Wiping done') LOG.info('Wiping done')
if settings('kodi_db_has_been_wiped_clean') != 'true': if settings('kodi_db_has_been_wiped_clean') != 'true':

View file

@ -49,6 +49,7 @@
<setting id="dbCreatedWithVersion" type="text" default="" visible="false"/> <setting id="dbCreatedWithVersion" type="text" default="" visible="false"/>
<setting id="plexid" type="text" default="" visible="false"/> <setting id="plexid" type="text" default="" visible="false"/>
<setting id="userid" type="text" default="" visible="false"/> <setting id="userid" type="text" default="" visible="false"/>
<setting id="sections_asked_for_machine_identifier" type="text" default="" visible="false"/>
</category> </category>
<category label="30506"><!-- Sync Options --> <category label="30506"><!-- Sync Options -->