コード例 #1
0
        private async Task <IReadOnlyCollection <bool> > UpdateMoviesAsync(ISpinWheelService spinWheelService,
                                                                           IReadOnlyCollection <IPlexMovieMetadata> plexMovieMetadataItems,
                                                                           IReadOnlyCollection <IMovieIdentifier> embyMovieIdentifiers)
        {
            var cts = new CancellationTokenSource();
            IEmbyImportMovieLogic embyImportMovieLogic = null;

            try
            {
                embyImportMovieLogic = _logicFactory.CreateLogic <IEmbyImportMovieLogic>();
                embyImportMovieLogic.ItemProcessed += spinWheelService.OnItemProcessed;

                await spinWheelService.StartSpinWheelAsync(cts.Token);

                var updateTasks = plexMovieMetadataItems
                                  .Select(plexMovieMetaDataItem =>
                {
                    var embyMovieIdentifier = embyMovieIdentifiers.First(x => plexMovieMetaDataItem.Filenames.Contains(x.Filename));
                    return(embyImportMovieLogic.RunAsync(plexMovieMetaDataItem, embyMovieIdentifier));
                })
                                  .ToArray();

                return(await Task.WhenAll(updateTasks));
            }
            finally
            {
                if (embyImportMovieLogic != null)
                {
                    embyImportMovieLogic.ItemProcessed -= spinWheelService.OnItemProcessed;
                }
                spinWheelService.StopSpinWheel(cts);
                cts.Dispose();
            }
        }
コード例 #2
0
        public async Task <bool> RunAsync(IPlexMovieMetadata plexMovieMetadata, IMovieIdentifier embyMovieIdentifier)
        {
            var retval = true;

            await SemSlim.WaitAsync();

            try
            {
                _logger.Log(Severity.Info, $"Processing '{plexMovieMetadata.Title}'");

                // Add movie to all collections (create if necessary).
                var embyImportMovieCollectionsLogic = _logicFactory.CreateLogic <IEmbyImportMovieCollectionsLogic>();
                if (await embyImportMovieCollectionsLogic.RunAsync(plexMovieMetadata.Collections, embyMovieIdentifier) == false)
                {
                    var msg = $"Failed to update Emby collections for '{plexMovieMetadata.Title}'.";
                    _logger.Log(Severity.Warn, msg);
                    retval = false;
                }

                // Add images to movie.
                var embyImportMovieImagesLogic = _logicFactory.CreateLogic <IEmbyImportMovieImagesLogic>();
                if (await embyImportMovieImagesLogic.RunAsync(plexMovieMetadata, embyMovieIdentifier) == false)
                {
                    _logger.Log(Severity.Warn, $"One or more images could not be properly added to '{plexMovieMetadata.Title}'.");
                    retval = false;
                }

                // Update movie metadata.
                var embyImportMovieMetadataLogic = _logicFactory.CreateLogic <IEmbyImportMovieMetadataLogic>();
                if (await embyImportMovieMetadataLogic.RunAsync(plexMovieMetadata, embyMovieIdentifier) == false)
                {
                    _logger.Log(Severity.Warn, $"Metadata could not be updated on '{plexMovieMetadata.Title}'.");
                    retval = false;
                }

                return(retval);
            }
            finally
            {
                OnItemProcessed();
                SemSlim.Release();
            }
        }
コード例 #3
0
        public async Task <bool> RunAsync()
        {
            var connectionInformationEmby1 = _connectionInformationFactory
                                             .CreateConnectionInformation <IConsoleEmbyInstance1ConnectionOptions>();
            var connectionInformationPlex1 = _connectionInformationFactory
                                             .CreateConnectionInformation <IConsolePlexInstance1ConnectionOptions>();

            var embyClient = _clientFactory.CreateClient <IEmbyClient>(connectionInformationEmby1);
            var plexClient = _clientFactory.CreateClient <IPlexClient>(connectionInformationPlex1);

            var userCredentialsService = _serviceFactory.CreateService <IUserCredentialsService>();

            var clients = new List <IClient> {
                embyClient, plexClient
            };

            bool retval;

            try
            {
                // FYI: As async access to the console is not possible, login data is collected ahead of the async login tasks.
                // FYI: Each client gets an instance of the credentials service, but it's up to the client to use it or not.
                clients.ForEach(x => x.SetLoginData(userCredentialsService));

                var didLoginAll = await LoginAllClientsAsync(clients);

                if (didLoginAll == false)
                {
                    _logger.Error("Login to one or more servers failed.");
                    return(false);
                }

                var plexExportLogic = _logicFactory.CreateLogic <IPlexExportLogic>();
                var embyImportLogic = _logicFactory.CreateLogic <IEmbyImportLogic>();

                // TODO - handle RemoteLoggedOut?
                //_embyClient.RemoteLoggedOut += EmbyClient_RemoteLoggedOut;

                //await _embyService.DoItAsync(_embyClient);

                var didExportFromPlex = await plexExportLogic.RunAsync();

                if (didExportFromPlex == false)
                {
                    _logger.Warn("No items to process - exiting.");
                    return(false);
                }

                var didImportToEmby = await embyImportLogic.RunAsync(plexExportLogic.MovieMetadataItems);

                if (didImportToEmby == false)
                {
                    _logger.Warn("Import failed.");
                    return(false);
                }

                _logger.Info("Import finished.");
            }
            finally
            {
                var didLogoutAll = await LogoutAllClientsAsync(clients);

                retval = didLogoutAll;
                _logger.Info("Logic done.");
            }

            return(retval);
        }