Exemple #1
0
 protected override Task <Either <BaseError, List <PlexMovie> > > GetMovieLibraryItems(
     PlexConnectionParameters connectionParameters,
     PlexLibrary library) =>
 _plexServerApiClient.GetMovieLibraryContents(
     library,
     connectionParameters.Connection,
     connectionParameters.Token);
Exemple #2
0
        public async Task <Either <BaseError, Unit> > ScanLibrary(
            PlexConnection connection,
            PlexServerAuthToken token,
            PlexLibrary plexMediaSourceLibrary)
        {
            Either <BaseError, List <PlexMovie> > entries = await _plexServerApiClient.GetMovieLibraryContents(
                plexMediaSourceLibrary,
                connection,
                token);

            await entries.Match(
                async movieEntries =>
            {
                foreach (PlexMovie incoming in movieEntries)
                {
                    // TODO: figure out how to rebuild playlists
                    Either <BaseError, MediaItemScanResult <PlexMovie> > maybeMovie = await _movieRepository
                                                                                      .GetOrAdd(plexMediaSourceLibrary, incoming)
                                                                                      .BindT(existing => UpdateStatistics(existing, incoming, connection, token))
                                                                                      .BindT(existing => UpdateMetadata(existing, incoming))
                                                                                      .BindT(existing => UpdateArtwork(existing, incoming));

                    await maybeMovie.Match(
                        async result =>
                    {
                        if (result.IsAdded)
                        {
                            await _searchIndex.AddItems(new List <MediaItem> {
                                result.Item
                            });
                        }
                        else if (result.IsUpdated)
                        {
                            await _searchIndex.UpdateItems(new List <MediaItem> {
                                result.Item
                            });
                        }
                    },
                        error =>
                    {
                        _logger.LogWarning(
                            "Error processing plex movie at {Key}: {Error}",
                            incoming.Key,
                            error.Value);
                        return(Task.CompletedTask);
                    });
                }

                var movieKeys  = movieEntries.Map(s => s.Key).ToList();
                List <int> ids = await _movieRepository.RemoveMissingPlexMovies(plexMediaSourceLibrary, movieKeys);
                await _searchIndex.RemoveItems(ids);
            },
                error =>
            {
                _logger.LogWarning(
                    "Error synchronizing plex library {Path}: {Error}",
                    plexMediaSourceLibrary.Name,
                    error.Value);

                return(Task.CompletedTask);
            });

            return(Unit.Default);
        }