private IEnumerable <ImportDecision> GetDecisions(IEnumerable <String> videoFiles, Series series, bool sceneSource, QualityModel quality = null) { foreach (var file in videoFiles) { ImportDecision decision = null; try { var localEpisode = _parsingService.GetLocalEpisode(file, series, sceneSource); if (localEpisode != null) { if (quality != null && new QualityModelComparer(localEpisode.Series.Profile).Compare(quality, localEpisode.Quality) > 0) { _logger.Debug("Using quality from folder: {0}", quality); localEpisode.Quality = quality; } localEpisode.Size = _diskProvider.GetFileSize(file); _logger.Debug("Size: {0}", localEpisode.Size); //TODO: make it so media info doesn't ruin the import process of a new series if (sceneSource) { localEpisode.MediaInfo = _videoFileInfoReader.GetMediaInfo(file); } decision = GetDecision(localEpisode); } else { localEpisode = new LocalEpisode(); localEpisode.Path = file; decision = new ImportDecision(localEpisode, "Unable to parse file"); } } catch (EpisodeNotFoundException e) { var localEpisode = new LocalEpisode(); localEpisode.Path = file; decision = new ImportDecision(localEpisode, e.Message); } catch (Exception e) { _logger.ErrorException("Couldn't import file. " + file, e); } if (decision != null) { yield return(decision); } } }
public override IEnumerable <ExtraFile> ProcessFiles(Series series, List <string> filesOnDisk, List <string> importedFiles) { _logger.Debug("Looking for existing extra files in {0}", series.Path); var extraFiles = new List <OtherExtraFile>(); var filterResult = FilterAndClean(series, 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 localEpisode = _parsingService.GetLocalEpisode(possibleExtraFile, series); if (localEpisode == null) { _logger.Debug("Unable to parse extra file: {0}", possibleExtraFile); continue; } if (localEpisode.Episodes.Empty()) { _logger.Debug("Cannot find related episodes for: {0}", possibleExtraFile); continue; } if (localEpisode.Episodes.DistinctBy(e => e.EpisodeFileId).Count() > 1) { _logger.Debug("Extra file: {0} does not match existing files.", possibleExtraFile); continue; } var extraFile = new OtherExtraFile { SeriesId = series.Id, SeasonNumber = localEpisode.SeasonNumber, EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId, RelativePath = series.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)); }
private ImportDecision GetDecision(string file, Series series, DownloadClientItem downloadClientItem, ParsedEpisodeInfo folderInfo, bool sceneSource, bool shouldUseFolderName) { ImportDecision decision = null; try { var localEpisode = _parsingService.GetLocalEpisode(file, series, shouldUseFolderName ? folderInfo : null, sceneSource); if (localEpisode != null) { localEpisode.Quality = GetQuality(folderInfo, localEpisode.Quality, series); localEpisode.Size = _diskProvider.GetFileSize(file); _logger.Debug("Size: {0}", localEpisode.Size); //TODO: make it so media info doesn't ruin the import process of a new series if (sceneSource) { localEpisode.MediaInfo = _videoFileInfoReader.GetMediaInfo(file); } if (localEpisode.Episodes.Empty()) { decision = new ImportDecision(localEpisode, new Rejection("Invalid season or episode")); } else { decision = GetDecision(localEpisode, downloadClientItem); } } else { localEpisode = new LocalEpisode(); localEpisode.Path = file; decision = new ImportDecision(localEpisode, new Rejection("Unable to parse file")); } } catch (Exception e) { _logger.Error(e, "Couldn't import file. {0}", file); var localEpisode = new LocalEpisode { Path = file }; decision = new ImportDecision(localEpisode, new Rejection("Unexpected error processing file")); } if (decision == null) { _logger.Error("Unable to make a decision on {0}", file); } return(decision); }
public void Handle(SeriesScannedEvent message) { if (!_diskProvider.FolderExists(message.Series.Path)) { return; } _logger.Debug("Looking for existing metadata in {0}", message.Series.Path); var filesOnDisk = _diskProvider.GetFiles(message.Series.Path, SearchOption.AllDirectories); var possibleMetadataFiles = filesOnDisk.Where(c => !MediaFileExtensions.Extensions.Contains(Path.GetExtension(c).ToLower()) && !c.StartsWith(Path.Combine(message.Series.Path, "EXTRAS"))).ToList(); var filteredFiles = _metadataFileService.FilterExistingFiles(possibleMetadataFiles, message.Series); var metadataFiles = new List <MetadataFile>(); foreach (var possibleMetadataFile in filteredFiles) { foreach (var consumer in _consumers) { var metadata = consumer.FindMetadataFile(message.Series, possibleMetadataFile); if (metadata == null) { continue; } if (metadata.Type == MetadataType.EpisodeImage || metadata.Type == MetadataType.EpisodeMetadata) { var localEpisode = _parsingService.GetLocalEpisode(possibleMetadataFile, message.Series, false); if (localEpisode == null) { _logger.Debug("Cannot find related episodes for: {0}", possibleMetadataFile); break; } if (localEpisode.Episodes.DistinctBy(e => e.EpisodeFileId).Count() > 1) { _logger.Debug("Metadata file: {0} does not match existing files.", possibleMetadataFile); break; } metadata.EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId; } metadataFiles.Add(metadata); } } _metadataFileService.Upsert(metadataFiles); }
private ImportDecision GetDecision(string file, Series series, ParsedEpisodeInfo folderInfo, bool sceneSource, bool shouldUseFolderName) { ImportDecision decision = null; try { var localEpisode = _parsingService.GetLocalEpisode(file, series, shouldUseFolderName ? folderInfo : null, sceneSource); if (localEpisode != null) { localEpisode.Quality = GetQuality(folderInfo, localEpisode.Quality, series); localEpisode.Size = _diskProvider.GetFileSize(file); _logger.Debug("Size: {0}", localEpisode.Size); //TODO: make it so media info doesn't ruin the import process of a new series if (sceneSource) { localEpisode.MediaInfo = _videoFileInfoReader.GetMediaInfo(file); } decision = GetDecision(localEpisode); } else { localEpisode = new LocalEpisode(); localEpisode.Path = file; decision = new ImportDecision(localEpisode, new Rejection("Unable to parse file")); } } catch (EpisodeNotFoundException e) { var localEpisode = new LocalEpisode(); localEpisode.Path = file; decision = new ImportDecision(localEpisode, new Rejection(e.Message)); } catch (Exception e) { _logger.ErrorException("Couldn't import file. " + file, e); } return(decision); }
private IEnumerable <ImportDecision> GetDecisions(IEnumerable <String> videoFiles, Series series, bool sceneSource, QualityModel quality = null) { foreach (var file in videoFiles) { ImportDecision decision = null; try { var parsedEpisode = _parsingService.GetLocalEpisode(file, series, sceneSource); if (parsedEpisode != null) { if (quality != null && new QualityModelComparer(parsedEpisode.Series.QualityProfile).Compare(quality, parsedEpisode.Quality) > 0) { _logger.Debug("Using quality from folder: {0}", quality); parsedEpisode.Quality = quality; } parsedEpisode.Size = _diskProvider.GetFileSize(file); _logger.Debug("Size: {0}", parsedEpisode.Size); decision = GetDecision(parsedEpisode); } else { parsedEpisode = new LocalEpisode(); parsedEpisode.Path = file; decision = new ImportDecision(parsedEpisode, "Unable to parse file"); } } catch (Exception e) { _logger.ErrorException("Couldn't import file." + file, e); } if (decision != null) { yield return(decision); } } }
public override IEnumerable <ExtraFile> ProcessFiles(Series series, List <string> filesOnDisk, List <string> importedFiles) { _logger.Debug("Looking for existing metadata in {0}", series.Path); var metadataFiles = new List <MetadataFile>(); var filterResult = FilterAndClean(series, 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(series, possibleMetadataFile); if (metadata == null) { continue; } if (metadata.Type == MetadataType.EpisodeImage || metadata.Type == MetadataType.EpisodeMetadata) { var localEpisode = _parsingService.GetLocalEpisode(possibleMetadataFile, series); if (localEpisode == null) { _logger.Debug("Unable to parse extra file: {0}", possibleMetadataFile); continue; } if (localEpisode.Episodes.Empty()) { _logger.Debug("Cannot find related episodes for: {0}", possibleMetadataFile); continue; } if (localEpisode.Episodes.DistinctBy(e => e.EpisodeFileId).Count() > 1) { _logger.Debug("Extra file: {0} does not match existing files.", possibleMetadataFile); continue; } metadata.SeasonNumber = localEpisode.SeasonNumber; metadata.EpisodeFileId = localEpisode.Episodes.First().EpisodeFileId; } 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)); }