private void GivenAMatchingLibrary() { _plexServer = new PlexServerRowBuilder().WithLibraries().Build(); _plexServer.PlexLibraries.ElementAt(0).LibraryKey = _command.Key; _plexServer.PlexLibraries.ElementAt(0).IsEnabled = false; _plexService.GetServer().Returns(_plexServer); }
private void GivenNoMatchingLibrary(bool isArchived) { _plexServer = new PlexServerRowBuilder().WithLibraries().Build(); _plexServer.PlexLibraries.ElementAt(0).IsArchived = isArchived; if (isArchived) { _plexServer.PlexLibraries.ElementAt(0).LibraryKey = _command.Key; } _plexService.GetServer().Returns(_plexServer); }
private static void CheckForDeletedLibraries(PlexServerRow server, PlexMediaContainer libraryContainer) { foreach (var existingLibrary in server.PlexLibraries.Where(x => !x.IsArchived)) { var libraryExists = libraryContainer.MediaContainer.Directory.Any(x => x.Key == existingLibrary.LibraryKey); if (libraryExists) { continue; } existingLibrary.IsArchived = true; existingLibrary.IsEnabled = false; } }
private static void SetNewLibraries(PlexMediaContainer libraryContainer, PlexServerRow server) { var newLibraries = libraryContainer.MediaContainer.Directory.Where(rl => !server.PlexLibraries.Select(x => x.LibraryKey).Contains(rl.Key)).Select(nl => new PlexLibraryRow { LibraryKey = nl.Key, Title = nl.Title, Type = nl.Type, IsEnabled = false }); foreach (var newLibrary in newLibraries) { server.PlexLibraries.Add(newLibrary); } }
private async Task CreateAdminServer(Server adminServer, User plexUser) { _logger.LogInformation("Found a PlexServer owned by the Admin account"); var plexServer = new PlexServerRow { Identifier = Guid.NewGuid(), AccessToken = adminServer.AccessToken, Name = adminServer.Name, MachineIdentifier = adminServer.MachineIdentifier, LocalIp = adminServer.LocalAddresses.Split(",").FirstOrDefault(), LocalPort = _plexSettings.DefaultLocalPort, ExternalIp = adminServer.Address, ExternalPort = Convert.ToInt32(adminServer.Port), Scheme = adminServer.Scheme, PlexLibraries = new List <PlexLibraryRow>() }; _logger.LogInformation("Getting available libraries on PlexServer"); var libraryContainer = await _plexApi.GetLibraries(plexUser.AuthToken, plexServer.GetPlexUri(_plexSettings.ConnectLocally)); var directories = libraryContainer?.MediaContainer.Directory; if (directories != null) { _logger.LogInformation( $"Identified '{directories.Count}' libraries on the PlexServer"); plexServer.PlexLibraries = directories.Select(x => new PlexLibraryRow { LibraryKey = x.Key, Title = x.Title, Type = x.Type }).ToList(); } else { _logger.LogInformation("No Plex Libraries were found for the server"); } await _plexService.AddServer(plexServer); }
private void GivenAPlexServer() { _plexServer = new PlexServerRowBuilder().Build(); _plexService.GetServer().Returns(_plexServer); }
private void GivenAServerIsCreated() { _plexService.AddServer(Arg.Do <PlexServerRow>(x => _createdServer = x)); }
public async Task AddServer(PlexServerRow server) { await _plexServerRepository.Add(server); }
public async Task Add(PlexServerRow server) { await base.Add(server); }
private async Task SynchroniseLibrary(bool fullRefresh, PlexLibraryRow libraryToSync, PlexServerRow plexServer, string plexUrl, ISyncProcessor syncProcessor) { _logger.LogInformation($"Sync processing library type: {libraryToSync.Type}|{libraryToSync.LibraryKey}"); var libraryContainer = await GetLibraryContainer(libraryToSync, fullRefresh, plexServer.AccessToken, plexUrl); var syncResult = await syncProcessor.Synchronise(libraryContainer, fullRefresh, plexServer.AccessToken, plexUrl, plexServer.MachineIdentifier); _logger.LogInformation($"Sync finished processing library type: {libraryToSync.Type}|{libraryToSync.LibraryKey}"); _logger.LogInformation($"Sync Results. Create: {syncResult.NewItems.Count} Update: {syncResult.ExistingItems.Count}"); foreach (var newItem in syncResult.NewItems) { libraryToSync.PlexMediaItems.Add(newItem); } await _unitOfWork.CommitAsync(); await AutoCompleteRequests(syncResult, syncProcessor.Type); }
public static string GetPlexUri(this PlexServerRow server, bool useLocal) { var uri = useLocal ? $"{server.Scheme}://{server.LocalIp}:{server.LocalPort}" : $"{server.Scheme}://{server.ExternalIp}:{server.ExternalPort}"; return(uri); }