def select_libraries(self, libraries): ''' Select all or certain libraries to be whitelisted. ''' choices = [x['Name'] for x in libraries] choices.insert(0, translate(33121)) selection = dialog("multi", translate(33120), choices) if selection is None: raise LibraryException('LibrarySelection') elif not selection: LOG.info("Nothing was selected.") raise LibraryException('SyncLibraryLater') if 0 in selection: selection = list(range(1, len(libraries) + 1)) selected_libraries = [] for x in selection: library = libraries[x - 1] if library['Media'] != 'mixed': selected_libraries.append(library['Id']) else: selected_libraries.append("Mixed:%s" % library['Id']) self.sync['Libraries'] = selected_libraries return [libraries[x - 1] for x in selection]
def mapping(self): ''' Load the mapping of the full sync. This allows us to restore a previous sync. ''' if self.sync['Libraries']: if not dialog("yesno", heading="{jellyfin}", line1=translate(33102)): if not dialog("yesno", heading="{jellyfin}", line1=translate(33173)): dialog("ok", heading="{jellyfin}", line1=translate(33122)) raise LibraryException("ProgressStopped") else: self.sync['Libraries'] = [] self.sync['RestorePoint'] = {} else: LOG.info("generate full sync") libraries = [] for library in self.get_libraries(): if library[2] in ('movies', 'tvshows', 'musicvideos', 'music', 'mixed'): libraries.append({'Id': library[0], 'Name': library[1], 'Media': library[2]}) libraries = self.select_libraries(libraries) if [x['Media'] for x in libraries if x['Media'] in ('movies', 'mixed')]: self.sync['Libraries'].append("Boxsets:") save_sync(self.sync)
def get_fast_sync(self): new_fast_sync = compare_version(self.server['auth/server-version'], "4.2.0.23") enable_fast_sync = False if settings('SyncInstallRunDone.bool'): if settings('kodiCompanion.bool'): for plugin in self.server['api'].get_plugins(): if plugin['Name'] in ("Emby.Kodi Sync Queue", "Kodi companion"): enable_fast_sync = True break if new_fast_sync > 0: self.fast_sync(enable_fast_sync) elif enable_fast_sync: if not self.fast_sync_plugin(): dialog("ok", heading="{emby}", line1=_(33128)) raise Exception("Failed to retrieve latest updates") else: raise LibraryException('CompanionMissing') LOG.info("--<[ retrieve changes ]")
def select_libraries(self, libraries): ''' Select all or certain libraries to be whitelisted. ''' if dialog("yesno", heading="{jellyfin}", line1=_(33125), nolabel=_(33127), yeslabel=_(33126)): LOG.info("Selected sync later.") raise LibraryException('SyncLibraryLater') choices = [x['Name'] for x in libraries] choices.insert(0, _(33121)) selection = dialog("multi", _(33120), choices) if selection is None: raise LibraryException('LibrarySelection') elif not selection: LOG.info("Nothing was selected.") raise LibraryException('SyncLibraryLater') if 0 in selection: selection = list(range(1, len(libraries) + 1)) selected_libraries = [] for x in selection: library = libraries[x - 1] if library['Media'] != 'mixed': selected_libraries.append(library['Id']) else: selected_libraries.append("Mixed:%s" % library['Id']) self.sync['Libraries'] = selected_libraries return [libraries[x - 1] for x in selection]
def startup(self): ''' Run at startup. Check databases. Check for the server plugin. ''' Views().get_views() Views().get_nodes() try: if get_sync()['Libraries']: try: with FullSync(self, self.server) as sync: sync.libraries() Views().get_nodes() except Exception as error: LOG.error(error) elif not settings('SyncInstallRunDone.bool'): with FullSync(self, self.server) as sync: sync.libraries() Views().get_nodes() return True if settings('SyncInstallRunDone.bool'): if settings('kodiCompanion.bool'): for plugin in self.server['api'].get_plugins(): if plugin['Name'] in ("Emby.Kodi Sync Queue", "Kodi companion"): if not self.fast_sync(): dialog("ok", heading="{emby}", line1=_(33128)) raise Exception( "Failed to retrieve latest updates") LOG.info("--<[ retrieve changes ]") break else: raise LibraryException('CompanionMissing') return True except LibraryException as error: LOG.error(error.status) if error.status in 'SyncLibraryLater': dialog("ok", heading="{emby}", line1=_(33129)) settings('SyncInstallRunDone.bool', True) sync = get_sync() sync['Libraries'] = [] save_sync(sync) return True elif error.status == 'CompanionMissing': dialog("ok", heading="{emby}", line1=_(33099)) settings('kodiCompanion.bool', False) return True except Exception as error: LOG.exception(error) return False
def startup(self): ''' Run at startup. Check databases. Check for the server plugin. ''' self.test_databases() Views().get_views() Views().get_nodes() try: if get_sync()['Libraries']: try: with FullSync(self, self.server) as sync: sync.libraries() Views().get_nodes() except Exception as error: LOG.exception(error) elif not settings('SyncInstallRunDone.bool'): with FullSync(self, self.server) as sync: sync.libraries() Views().get_nodes() return True if settings('SyncInstallRunDone.bool'): if settings('kodiCompanion.bool'): if self.server.jellyfin.check_companion_installed(): if not self.fast_sync(): dialog("ok", heading="{jellyfin}", line1=translate(33128)) raise Exception("Failed to retrieve latest updates") LOG.info("--<[ retrieve changes ]") else: raise LibraryException('CompanionMissing') return True except LibraryException as error: LOG.error(error.status) if error.status in 'SyncLibraryLater': dialog("ok", heading="{jellyfin}", line1=translate(33129)) settings('SyncInstallRunDone.bool', True) sync = get_sync() sync['Libraries'] = [] save_sync(sync) return True elif error.status == 'CompanionMissing': dialog("ok", heading="{jellyfin}", line1=translate(33099)) settings('kodiCompanion.bool', False) return True except Exception as error: LOG.exception(error) return False