private List <ImportResult> ProcessFolder(IDirectoryInfo directoryInfo, ImportMode importMode, DownloadClientItem downloadClientItem) { var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name); var author = _parsingService.GetAuthor(cleanedUpName); return(ProcessFolder(directoryInfo, importMode, author, downloadClientItem)); }
private List <ImportResult> ProcessFolder(IDirectoryInfo directoryInfo, ImportMode importMode, DownloadClientItem downloadClientItem) { var cleanedUpName = GetCleanedUpFolderName(directoryInfo.Name); var author = _parsingService.GetAuthor(cleanedUpName); if (author == null) { _logger.Debug("Unknown Author {0}", cleanedUpName); return(new List <ImportResult> { UnknownAuthorResult("Unknown Author") }); } return(ProcessFolder(directoryInfo, importMode, author, downloadClientItem)); }
private List <ManualImportItem> ProcessFolder(string folder, string downloadId, Author author, FilterFilesType filter, bool replaceExistingFiles) { DownloadClientItem downloadClientItem = null; var directoryInfo = new DirectoryInfo(folder); author = author ?? _parsingService.GetAuthor(directoryInfo.Name); if (downloadId.IsNotNullOrWhiteSpace()) { var trackedDownload = _trackedDownloadService.Find(downloadId); downloadClientItem = trackedDownload?.DownloadItem; if (author == null) { author = trackedDownload?.RemoteBook?.Author; } } var authorFiles = _diskScanService.GetBookFiles(folder).ToList(); var idOverrides = new IdentificationOverrides { Author = author }; var itemInfo = new ImportDecisionMakerInfo { DownloadClientItem = downloadClientItem, ParsedTrackInfo = Parser.Parser.ParseTitle(directoryInfo.Name) }; var config = new ImportDecisionMakerConfig { Filter = filter, NewDownload = true, SingleRelease = false, IncludeExisting = !replaceExistingFiles, AddNewAuthors = false, KeepAllEditions = true }; var decisions = _importDecisionMaker.GetImportDecisions(authorFiles, idOverrides, itemInfo, config); // paths will be different for new and old files which is why we need to map separately var newFiles = authorFiles.Join(decisions, f => f.FullName, d => d.Item.Path, (f, d) => new { File = f, Decision = d }, PathEqualityComparer.Instance); var newItems = newFiles.Select(x => MapItem(x.Decision, downloadId, replaceExistingFiles, false)); var existingDecisions = decisions.Except(newFiles.Select(x => x.Decision)); var existingItems = existingDecisions.Select(x => MapItem(x, null, replaceExistingFiles, false)); return(newItems.Concat(existingItems).ToList()); }