Ejemplo n.º 1
0
        private async Task <PlexMediaContainer> GetLibraryContainer(PlexLibraryRow library, bool fullRefresh, string authToken, string plexUri)
        {
            PlexMediaContainer libraryContainer;

            if (fullRefresh)
            {
                libraryContainer = await _plexApi.GetLibrary(authToken, plexUri, library.LibraryKey);
            }
            else
            {
                libraryContainer = await _plexApi.GetRecentlyAdded(authToken, plexUri, library.LibraryKey);
            }

            return(libraryContainer);
        }
Ejemplo n.º 2
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);
        }