public ServerSelectionWindow()
        {
            OnlineServers      = new ObservableCollection <PlexServer>();
            OfflineServers     = new ObservableCollection <PlexServer>();
            SelectedPlexServer = null;

            InitializeComponent();
            Initialize();
        }
Ejemplo n.º 2
0
        public async Task <IReadOnlyCollection <PlexTvShow> > GetTvShowsAsync(PlexServer server)
        {
            _logger.LogInformation($"Retrieving plex tv shows from server {server.Name}.");

            var libraries = await _plexClient.GetLibraries(server.AccessToken, server.Host);

            var tvDirectories = libraries.MediaContainer.Directory.Where(x => x.Type == "show").ToList();

            var tvShowMetadata = (await Task.WhenAll(tvDirectories.Select(d => _plexClient.GetLibrary(server.AccessToken, server.Host, d.Key)))).SelectMany(x => x.MediaContainer.Metadata).ToList();

            var tvShows = tvShowMetadata.Select(metadata => new PlexTvShow(metadata.Title, metadata.Year, metadata.RatingKey));

            return(tvShows.ToList());
        }
        private void SetupDatabase()
        {
            PlexServer  plexServer  = FakeDbData.GetPlexServer().Generate();
            PlexLibrary plexLibrary = FakeDbData.GetPlexLibrary(1, 1, PlexMediaType.TvShow).Generate();

            try
            {
                _dbContext.PlexServers.Add(plexServer);
                _dbContext.PlexLibraries.Add(plexLibrary);
                _dbContext.SaveChanges();
            }
            catch (Exception e)
            {
                Log.Fatal(e);
                throw;
            }
        }
Ejemplo n.º 4
0
        public async Task <Result <PlexServerStatus> > CheckPlexServerStatusAsync(PlexServer plexServer, int plexAccountId = 0, bool trimEntries = true)
        {
            // Get plexServer authToken
            var authToken = await _plexAuthenticationService.GetPlexServerTokenAsync(plexServer.Id, plexAccountId);

            if (authToken.IsFailed)
            {
                return(authToken.ToResult());
            }

            // Request status
            var serverStatus = await _plexServiceApi.GetPlexServerStatusAsync(authToken.Value, plexServer.ServerUrl);

            serverStatus.PlexServer   = plexServer;
            serverStatus.PlexServerId = plexServer.Id;

            // Add plexServer status to DB, the PlexServerStatus table functions as a server log.
            var result = await _mediator.Send(new CreatePlexServerStatusCommand(serverStatus));

            if (result.IsFailed)
            {
                return(result.ToResult());
            }

            if (trimEntries)
            {
                // Ensure that there are not too many PlexServerStatuses stored.
                var trimResult = await _mediator.Send(new TrimPlexServerStatusCommand(plexServer.Id));

                if (trimResult.IsFailed)
                {
                    return(trimResult.ToResult());
                }
            }

            return(await _mediator.Send(new GetPlexServerStatusByIdQuery(result.Value)));
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        public async Task <Result <bool> > RefreshLibrariesAsync(PlexAccount plexAccount, PlexServer plexServer)
        {
            if (plexServer == null)
            {
                string msg = "plexServer was null";
                Log.Warning(msg);
                return(Result.Fail(msg));
            }

            Log.Debug($"Refreshing PlexLibraries for plexServer: {plexServer.Name}");

            var authToken = await _plexAuthenticationService.GetPlexServerTokenAsync(plexServer.Id, plexAccount.Id);

            if (authToken.IsFailed)
            {
                return(Result.Fail(new Error("Failed to retrieve the server auth token")));
            }

            var libraries = await _plexServiceApi.GetLibrarySectionsAsync(authToken.Value, plexServer.ServerUrl);

            if (!libraries.Any())
            {
                string msg = $"plexLibraries returned for server {plexServer.Name} - {plexServer.ServerUrl} was empty";
                Log.Warning(msg);
                return(Result.Fail(msg));
            }

            return(await _mediator.Send(new AddOrUpdatePlexLibrariesCommand(plexAccount, plexServer, libraries)));
        }
Ejemplo n.º 6
0
 public AddOrUpdatePlexLibrariesCommand(PlexAccount plexAccount, PlexServer plexServer, List <PlexLibrary> plexLibraries)
 {
     PlexAccount   = plexAccount;
     PlexServer    = plexServer;
     PlexLibraries = plexLibraries;
 }
 private void PlexServerButton_Click(object sender, RoutedEventArgs e)
 {
     SelectedPlexServer = (PlexServer)((Button)sender).Tag;
     DialogResult       = true;
     Close();
 }
Ejemplo n.º 8
0
        public async Task <IReadOnlyCollection <Season> > GetSeasonsAsync(PlexTvShow tvShow, PlexServer server)
        {
            var seasonMetadata = await _plexClient.GetChildrenMetadata(
                server.AccessToken,
                server.Host,
                int.Parse(tvShow.Key));

            return(await Task.WhenAll(seasonMetadata.MediaContainer.Metadata.Select(GetSeasonsFromMetadataAsync)));

            async Task <Season> GetSeasonsFromMetadataAsync(Metadata metadata)
            {
                var episodesMetadata = await _plexClient.GetChildrenMetadata(
                    server.AccessToken,
                    server.Host,
                    int.Parse(metadata.RatingKey));

                var episodes = episodesMetadata.MediaContainer.Metadata.Select(
                    m => new Episode
                {
                    Title         = m.Title,
                    SeasonNumber  = m.ParentIndex,
                    EpisodeNumber = m.Index
                });

                return(new Season {
                    SeasonNumber = metadata.Index, Episodes = episodes.ToList()
                });
            }
        }