public async Task Synchronise(bool fullRefresh) { var refreshType = fullRefresh ? "full" : "partial"; _logger.LogInformation($"Starting a {refreshType} sync with Plex."); var plexServer = await _plexService.GetServer(); if (plexServer == null) { _logger.LogInformation("Unable to sync plex content as no admin server was found"); } var librariesToSync = plexServer?.PlexLibraries.Where(x => x.IsEnabled).ToList(); if (librariesToSync == null || !librariesToSync.Any()) { _logger.LogDebug("No Plex libraries have been enabled for synchronisation"); return; } if (fullRefresh) { //TODO Why are we doing this? It should be a soft delete //What about issues/requests that use this as a FK? _plexService.DeleteAllMediaItems(); } var plexUrl = plexServer.GetPlexUri(_plexSettings.ConnectLocally); var plexLibraryContainer = await _plexApi.GetLibraries(plexServer.AccessToken, plexUrl); foreach (var libraryToSync in librariesToSync) { var existsAsRemoteLibrary = plexLibraryContainer.MediaContainer.Directory.Any(x => x.Key == libraryToSync.LibraryKey); if (!existsAsRemoteLibrary) { _logger.LogInformation($"Attempted to sync the local library '{libraryToSync.Type}|{libraryToSync.LibraryKey}' but it no longer exists remotely"); continue; } var syncProcessor = _processorProvider.GetProcessor(libraryToSync.Type); if (syncProcessor == null) { _logger.LogInformation($"Attempted to sync the local library '{libraryToSync.Type}|{libraryToSync.LibraryKey}' but the type is not supported"); return; } await SynchroniseLibrary(fullRefresh, libraryToSync, plexServer, plexUrl, syncProcessor); } }