/// <inheritdoc/>
        public async Task PerformOrganization(string resultId)
        {
            var result = _repo.GetResult(resultId);

            var options = _config.GetAutoOrganizeOptions();

            if (string.IsNullOrEmpty(result.TargetPath))
            {
                throw new ArgumentException("No target path available.");
            }

            FileOrganizationResult organizeResult;

            switch (result.Type)
            {
            case FileOrganizerType.Episode:
                var episodeOrganizer = new EpisodeFileOrganizer(
                    this,
                    _fileSystem,
                    _loggerFactory.CreateLogger <EpisodeFileOrganizer>(),
                    _libraryManager,
                    _libraryMonitor,
                    _providerManager,
                    _namingOptions);
                organizeResult = await episodeOrganizer.OrganizeEpisodeFile(result.OriginalPath, options.TvOptions, CancellationToken.None)
                                 .ConfigureAwait(false);

                break;

            case FileOrganizerType.Movie:
                var movieOrganizer = new MovieFileOrganizer(
                    this,
                    _fileSystem,
                    _loggerFactory.CreateLogger <MovieFileOrganizer>(),
                    _libraryManager,
                    _libraryMonitor,
                    _providerManager,
                    _namingOptions);
                organizeResult = await movieOrganizer.OrganizeMovieFile(result.OriginalPath, options.MovieOptions, true, CancellationToken.None)
                                 .ConfigureAwait(false);

                break;

            default:
                throw new OrganizationException("No organizer exist for the type " + result.Type);
            }

            if (organizeResult.Status != FileSortingStatus.Success)
            {
                throw new OrganizationException(result.StatusMessage);
            }
        }
        /// <inheritdoc/>
        public async Task Execute(CancellationToken cancellationToken, IProgress <double> progress)
        {
            bool queueTv = false, queueMovie = false;

            var options = _config.GetAutoOrganizeOptions();

            if (options.TvOptions.IsEnabled)
            {
                queueTv = options.TvOptions.QueueLibraryScan;
                var fileOrganizationService = PluginEntryPoint.Current.FileOrganizationService;

                await new TvFolderOrganizer(_libraryManager, _logger, _fileSystem, _libraryMonitor, fileOrganizationService, _config, _providerManager)
                .Organize(options.TvOptions, progress, cancellationToken).ConfigureAwait(false);
            }

            if (options.MovieOptions.IsEnabled)
            {
                queueMovie = options.MovieOptions.QueueLibraryScan;
                var fileOrganizationService = PluginEntryPoint.Current.FileOrganizationService;

                await new MovieFolderOrganizer(_libraryManager, _logger, _fileSystem, _libraryMonitor, fileOrganizationService, _config, _providerManager)
                .Organize(options.MovieOptions, progress, cancellationToken).ConfigureAwait(false);
            }

            if ((queueTv || queueMovie) && !_libraryManager.IsScanRunning)
            {
                _libraryManager.QueueLibraryScan();
            }
        }
Пример #3
0
        public Task <FileOrganizationResult> OrganizeEpisodeFile(string path, CancellationToken cancellationToken)
        {
            var options = _config.GetAutoOrganizeOptions();

            return(OrganizeEpisodeFile(path, options, false, cancellationToken));
        }
 private AutoOrganizeOptions GetAutoOrganizeOptions()
 {
     return(_config.GetAutoOrganizeOptions());
 }
 private TvFileOrganizationOptions GetTvOptions()
 {
     return(_config.GetAutoOrganizeOptions().TvOptions);
 }