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);
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 6
0
        private void GivenAPlexServer()
        {
            _plexServer = new PlexServerRowBuilder().Build();

            _plexService.GetServer().Returns(_plexServer);
        }
Ejemplo n.º 7
0
 private void GivenAServerIsCreated()
 {
     _plexService.AddServer(Arg.Do <PlexServerRow>(x => _createdServer = x));
 }
Ejemplo n.º 8
0
 public async Task AddServer(PlexServerRow server)
 {
     await _plexServerRepository.Add(server);
 }
Ejemplo n.º 9
0
 public async Task Add(PlexServerRow server)
 {
     await base.Add(server);
 }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }