예제 #1
0
        public ImportResult(ImportDecision importDecision, params string[] errors)
        {
            Ensure.That(importDecision, () => importDecision).IsNotNull();

            ImportDecision = importDecision;
            Errors         = errors.ToList();
        }
예제 #2
0
        private ImportDecision GetDecision(LocalMovie localMovie, DownloadClientItem downloadClientItem, bool otherFiles)
        {
            ImportDecision decision = null;

            var fileMovieInfo = Parser.Parser.ParseMoviePath(localMovie.Path);

            if (fileMovieInfo != null)
            {
                fileMovieInfo = _parsingService.EnhanceMovieInfo(fileMovieInfo);
            }

            localMovie.FileMovieInfo = fileMovieInfo;
            localMovie.Size          = _diskProvider.GetFileSize(localMovie.Path);

            try
            {
                _aggregationService.Augment(localMovie, downloadClientItem, otherFiles);

                if (localMovie.Movie == null)
                {
                    decision = new ImportDecision(localMovie, new Rejection("Invalid movie"));
                }
                else
                {
                    decision = GetDecision(localMovie, downloadClientItem);
                }
            }
            catch (AugmentingFailedException)
            {
                decision = new ImportDecision(localMovie, new Rejection("Unable to parse file"));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Couldn't import file. {0}", localMovie.Path);

                decision = new ImportDecision(localMovie, new Rejection("Unexpected error processing file"));
            }

            if (decision == null)
            {
                _logger.Error("Unable to make a decision on {0}", localMovie.Path);
            }
            else if (decision.Rejections.Any())
            {
                _logger.Debug("File rejected for the following reasons: {0}", string.Join(", ", decision.Rejections));
            }
            else
            {
                _logger.Debug("File accepted");
            }

            return(decision);
        }
예제 #3
0
        private ImportDecision GetDecision(string file, Movie movie, DownloadClientItem downloadClientItem, ParsedMovieInfo folderInfo, bool sceneSource, bool shouldUseFolderName, bool shouldCheckQuality = false)
        {
            ImportDecision decision = null;

            try
            {
                var minimalInfo = shouldUseFolderName
                    ? folderInfo.JsonClone()
                    : _parsingService.ParseMinimalPathMovieInfo(file);

                LocalMovie localMovie = null;
                //var localMovie = _parsingService.GetLocalMovie(file, movie, shouldUseFolderName ? folderInfo : null, sceneSource);

                if (minimalInfo != null)
                {
                    //TODO: make it so media info doesn't ruin the import process of a new movie
                    var mediaInfo        = _config.EnableMediaInfo ? _videoFileInfoReader.GetMediaInfo(file) : null;
                    var size             = _diskProvider.GetFileSize(file);
                    var historyItems     = _historyService.FindByDownloadId(downloadClientItem?.DownloadId ?? "");
                    var firstHistoryItem = historyItems.OrderByDescending(h => h.Date).FirstOrDefault();
                    var sizeMovie        = new LocalMovie();
                    sizeMovie.Size = size;
                    localMovie     = _parsingService.GetLocalMovie(file, minimalInfo, movie, new List <object> {
                        mediaInfo, firstHistoryItem, sizeMovie
                    }, sceneSource);
                    localMovie.Quality = GetQuality(folderInfo, localMovie.Quality, movie);
                    localMovie.Size    = size;

                    _logger.Debug("Size: {0}", localMovie.Size);

                    decision = GetDecision(localMovie, downloadClientItem);
                }

                else
                {
                    localMovie      = new LocalMovie();
                    localMovie.Path = file;

                    if (MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
                    {
                        _logger.Warn("Unable to parse movie info from path {0}", file);
                    }

                    decision = new ImportDecision(localMovie, new Rejection("Unable to parse file"));
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Couldn't import file. " + file);

                var localMovie = new LocalMovie {
                    Path = file
                };
                decision = new ImportDecision(localMovie, new Rejection("Unexpected error processing file"));
            }

            //LocalMovie nullMovie = null;

            //decision = new ImportDecision(nullMovie, new Rejection("IMPLEMENTATION MISSING!!!"));

            return(decision);
        }
예제 #4
0
        private ImportDecision GetDecision(string file, Movie movie, DownloadClientItem downloadClientItem, ParsedMovieInfo folderInfo, bool sceneSource, bool shouldUseFolderName, bool shouldCheckQuality = false)
        {
            ImportDecision decision = null;

            try
            {
                ParsedMovieInfo modifiedFolderInfo = null;
                if (folderInfo != null)
                {
                    modifiedFolderInfo = folderInfo.JsonClone();
                    // We want the filename to be used for parsing quality, etc. even if we didn't get any movie info from there.
                    modifiedFolderInfo.SimpleReleaseTitle = Path.GetFileName(file);
                }

                var minimalInfo = _parsingService.ParseMinimalPathMovieInfo(file) ?? modifiedFolderInfo;

                LocalMovie localMovie = null;

                if (minimalInfo != null)
                {
                    //TODO: make it so media info doesn't ruin the import process of a new movie
                    var mediaInfo        = (_config.EnableMediaInfo || !movie.Path?.IsParentPath(file) == true) ? _videoFileInfoReader.GetMediaInfo(file) : null;
                    var size             = _diskProvider.GetFileSize(file);
                    var historyItems     = _historyService.FindByDownloadId(downloadClientItem?.DownloadId ?? "");
                    var firstHistoryItem = historyItems?.OrderByDescending(h => h.Date)?.FirstOrDefault();
                    var sizeMovie        = new LocalMovie();
                    sizeMovie.Size = size;
                    localMovie     = _parsingService.GetLocalMovie(file, minimalInfo, movie, new List <object> {
                        mediaInfo, firstHistoryItem, sizeMovie, folderInfo
                    }, sceneSource);
                    localMovie.Quality = GetQuality(folderInfo, localMovie.Quality, movie);
                    localMovie.Size    = size;

                    _logger.Debug("Size: {0}", localMovie.Size);

                    decision = GetDecision(localMovie, downloadClientItem);
                }
                else
                {
                    localMovie      = new LocalMovie();
                    localMovie.Path = file;

                    if (MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
                    {
                        if (_warnedFiles.Find(file) == null)
                        {
                            _warnedFiles.Set(file, "warned");
                            _logger.Warn("Unable to parse movie info from path {0}", file);
                        }
                        else
                        {
                            _logger.Trace("Already warned user that we are unable to parse movie info from path: {0}", file);
                        }
                    }

                    decision = new ImportDecision(localMovie, new Rejection("Unable to parse file"));
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Couldn't import file. {0}", file);

                var localMovie = new LocalMovie {
                    Path = file
                };
                decision = new ImportDecision(localMovie, new Rejection("Unexpected error processing file"));
            }

            //LocalMovie nullMovie = null;

            //decision = new ImportDecision(nullMovie, new Rejection("IMPLEMENTATION MISSING!!!"));

            return(decision);
        }