private MetadataFile ProcessMovieMetadata(IMetadata consumer, Movie movie, MovieFile movieFile, List <MetadataFile> existingMetadataFiles) { _logger.Debug("Processing Movie Metadata for: {0}", Path.Combine(movie.Path, movieFile.RelativePath)); var movieFileMetadata = consumer.MovieMetadata(movie, movieFile); if (movieFileMetadata == null) { return(null); } var fullPath = Path.Combine(movie.Path, movieFileMetadata.RelativePath); _otherExtraFileRenamer.RenameOtherExtraFile(movie, fullPath); var existingMetadata = GetMetadataFile(movie, existingMetadataFiles, c => c.Type == MetadataType.MovieMetadata && c.MovieFileId == movieFile.Id); if (existingMetadata != null) { var existingFullPath = Path.Combine(movie.Path, existingMetadata.RelativePath); if (fullPath.PathNotEquals(existingFullPath)) { _diskTransferService.TransferFile(existingFullPath, fullPath, TransferMode.Move); existingMetadata.RelativePath = movieFileMetadata.RelativePath; } } var hash = movieFileMetadata.Contents.SHA256Hash(); var metadata = existingMetadata ?? new MetadataFile { MovieId = movie.Id, MovieFileId = movieFile.Id, Consumer = consumer.GetType().Name, Type = MetadataType.MovieMetadata, RelativePath = movieFileMetadata.RelativePath, Extension = Path.GetExtension(fullPath) }; if (hash == metadata.Hash) { return(null); } _logger.Debug("Writing Movie File Metadata to: {0}", fullPath); SaveMetadataFile(fullPath, movieFileMetadata.Contents); metadata.Hash = hash; return(metadata); }
private MetadataFile ProcessEpisodeMetadata(IMetadata consumer, Series series, EpisodeFile episodeFile, List <MetadataFile> existingMetadataFiles) { var episodeMetadata = consumer.EpisodeMetadata(series, episodeFile); if (episodeMetadata == null) { return(null); } var fullPath = Path.Combine(series.Path, episodeMetadata.RelativePath); _otherExtraFileRenamer.RenameOtherExtraFile(series, fullPath); var existingMetadata = GetMetadataFile(series, existingMetadataFiles, c => c.Type == MetadataType.EpisodeMetadata && c.EpisodeFileId == episodeFile.Id); if (existingMetadata != null) { var existingFullPath = Path.Combine(series.Path, existingMetadata.RelativePath); if (fullPath.PathNotEquals(existingFullPath)) { _diskTransferService.TransferFile(existingFullPath, fullPath, TransferMode.Move); existingMetadata.RelativePath = episodeMetadata.RelativePath; } } var hash = episodeMetadata.Contents.SHA256Hash(); var metadata = existingMetadata ?? new MetadataFile { SeriesId = series.Id, SeasonNumber = episodeFile.SeasonNumber, EpisodeFileId = episodeFile.Id, Consumer = consumer.GetType().Name, Type = MetadataType.EpisodeMetadata, RelativePath = episodeMetadata.RelativePath, Extension = Path.GetExtension(fullPath) }; if (hash == metadata.Hash) { return(null); } _logger.Debug("Writing Episode Metadata to: {0}", fullPath); SaveMetadataFile(fullPath, episodeMetadata.Contents); metadata.Hash = hash; return(metadata); }
private MetadataFile ProcessAuthorMetadata(IMetadata consumer, Author author, List <MetadataFile> existingMetadataFiles) { var artistMetadata = consumer.AuthorMetadata(author); if (artistMetadata == null) { return(null); } var hash = artistMetadata.Contents.SHA256Hash(); var metadata = GetMetadataFile(author, existingMetadataFiles, e => e.Type == MetadataType.AuthorMetadata) ?? new MetadataFile { AuthorId = author.Id, Consumer = consumer.GetType().Name, Type = MetadataType.AuthorMetadata }; if (hash == metadata.Hash) { if (artistMetadata.RelativePath != metadata.RelativePath) { metadata.RelativePath = artistMetadata.RelativePath; return(metadata); } return(null); } var fullPath = Path.Combine(author.Path, artistMetadata.RelativePath); _otherExtraFileRenamer.RenameOtherExtraFile(author, fullPath); _logger.Debug("Writing Author Metadata to: {0}", fullPath); SaveMetadataFile(fullPath, artistMetadata.Contents); metadata.Hash = hash; metadata.RelativePath = artistMetadata.RelativePath; metadata.Extension = Path.GetExtension(fullPath); return(metadata); }