public override IEnumerable <ExtraFile> ProcessFiles(Movie movie, List <string> filesOnDisk, List <string> importedFiles) { _logger.Debug("Looking for existing metadata in {0}", movie.Path); var metadataFiles = new List <MetadataFile>(); var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles); foreach (var possibleMetadataFile in filterResult.FilesOnDisk) { // Don't process files that have known Subtitle file extensions (saves a bit of unecessary processing) if (SubtitleFileExtensions.Extensions.Contains(Path.GetExtension(possibleMetadataFile))) { continue; } foreach (var consumer in _consumers) { var metadata = consumer.FindMetadataFile(movie, possibleMetadataFile); if (metadata == null) { continue; } if (metadata.Type == MetadataType.MovieImage || metadata.Type == MetadataType.MovieMetadata) { var minimalInfo = _parsingService.ParseMinimalPathMovieInfo(possibleMetadataFile); if (minimalInfo == null) { _logger.Debug("Unable to parse extra file: {0}", possibleMetadataFile); continue; } metadata.MovieFileId = movie.MovieFileId; } metadata.Extension = Path.GetExtension(possibleMetadataFile); metadataFiles.Add(metadata); } } _logger.Info("Found {0} existing metadata files", metadataFiles.Count); _metadataFileService.Upsert(metadataFiles); // Return files that were just imported along with files that were // previously imported so previously imported files aren't imported twice return(metadataFiles.Concat(filterResult.PreviouslyImported)); }
public override IEnumerable <ExtraFile> ProcessFiles(Movie movie, List <string> filesOnDisk, List <string> importedFiles) { _logger.Debug("Looking for existing extra files in {0}", movie.Path); var extraFiles = new List <OtherExtraFile>(); var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles); foreach (var possibleExtraFile in filterResult.FilesOnDisk) { var extension = Path.GetExtension(possibleExtraFile); if (extension.IsNullOrWhiteSpace()) { _logger.Debug("No extension for file: {0}", possibleExtraFile); continue; } var minimalInfo = _parsingService.ParseMinimalPathMovieInfo(possibleExtraFile); if (minimalInfo == null) { _logger.Debug("Unable to parse extra file: {0}", possibleExtraFile); continue; } var extraFile = new OtherExtraFile { MovieId = movie.Id, MovieFileId = movie.MovieFileId, RelativePath = movie.Path.GetRelativePath(possibleExtraFile), Extension = extension }; extraFiles.Add(extraFile); } _logger.Info("Found {0} existing other extra files", extraFiles.Count); _otherExtraFileService.Upsert(extraFiles); // Return files that were just imported along with files that were // previously imported so previously imported files aren't imported twice return(extraFiles.Concat(filterResult.PreviouslyImported)); }
public override IEnumerable <ExtraFile> ProcessFiles(Movie movie, List <string> filesOnDisk, List <string> importedFiles) { _logger.Debug("Looking for existing subtitle files in {0}", movie.Path); var subtitleFiles = new List <SubtitleFile>(); var filterResult = FilterAndClean(movie, filesOnDisk, importedFiles); foreach (var possibleSubtitleFile in filterResult.FilesOnDisk) { var extension = Path.GetExtension(possibleSubtitleFile); if (SubtitleFileExtensions.Extensions.Contains(extension)) { var minimalInfo = _parsingService.ParseMinimalPathMovieInfo(possibleSubtitleFile); if (minimalInfo == null) { _logger.Debug("Unable to parse subtitle file: {0}", possibleSubtitleFile); continue; } var subtitleFile = new SubtitleFile { MovieId = movie.Id, MovieFileId = movie.MovieFileId, RelativePath = movie.Path.GetRelativePath(possibleSubtitleFile), Language = LanguageParser.ParseSubtitleLanguage(possibleSubtitleFile), Extension = extension }; subtitleFiles.Add(subtitleFile); } } _logger.Info("Found {0} existing subtitle files", subtitleFiles.Count); _subtitleFileService.Upsert(subtitleFiles); // Return files that were just imported along with files that were // previously imported so previously imported files aren't imported twice return(subtitleFiles.Concat(filterResult.PreviouslyImported)); }
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); }
private Response Search() { if (Request.Query.Id == 0) { //Todo error handling } RootFolder rootFolder = _rootFolderService.Get(Request.Query.Id); int page = Request.Query.page; int per_page = Request.Query.per_page; int min = (page - 1) * per_page; int max = page * per_page; var unmapped = rootFolder.UnmappedFolders.OrderBy(f => f.Name).ToList(); int total_count = unmapped.Count; if (Request.Query.total_entries.HasValue) { total_count = Request.Query.total_entries; } max = total_count >= max ? max : total_count; var paged = unmapped.GetRange(min, max - min); var mapped = paged.Select(f => { Core.Movies.Movie m = null; var mappedMovie = _mappedMovies.Find(f.Name); if (mappedMovie != null) { return(mappedMovie); } var parsedTitle = _parsingService.ParseMinimalPathMovieInfo(f.Name); parsedTitle.ImdbId = Parser.ParseImdbId(parsedTitle.SimpleReleaseTitle); if (parsedTitle == null) { m = new Core.Movies.Movie { Title = f.Name.Replace(".", " ").Replace("-", " "), Path = f.Path, }; } else { m = new Core.Movies.Movie { Title = parsedTitle.MovieTitle, Year = parsedTitle.Year, ImdbId = parsedTitle.ImdbId, Path = f.Path }; } var files = _diskScanService.GetVideoFiles(f.Path); var decisions = _importDecisionMaker.GetImportDecisions(files.ToList(), m, true); var decision = decisions.Where(d => d.Approved && !d.Rejections.Any()).FirstOrDefault(); if (decision != null) { var local = decision.LocalMovie; m.MovieFile = new MovieFile { Path = local.Path, Edition = local.ParsedMovieInfo.Edition, Quality = local.Quality, MediaInfo = local.MediaInfo, ReleaseGroup = local.ParsedMovieInfo.ReleaseGroup, RelativePath = f.Path.GetRelativePath(local.Path) }; } mappedMovie = _searchProxy.MapMovieToTmdbMovie(m); if (mappedMovie != null) { mappedMovie.Monitored = true; _mappedMovies.Set(f.Name, mappedMovie, TimeSpan.FromDays(2)); return(mappedMovie); } return(null); }); return(new PagingResource <MovieResource> { Page = page, PageSize = per_page, SortDirection = SortDirection.Ascending, SortKey = Request.Query.sort_by, TotalRecords = total_count - mapped.Where(m => m == null).Count(), Records = MapToResource(mapped.Where(m => m != null)).ToList() }.AsResponse()); }
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); }