mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-05 02:22:31 +01:00
Metadata file improvements
Fixed: Duplicate metadata files won't cause metadata file processing to fail Fixed: Duplicate Metadata files will be removed from disk during rescan
This commit is contained in:
parent
573c2b8f60
commit
db4eadac40
@ -145,7 +145,7 @@ private MetadataFile ProcessSeriesMetadata(IMetadata consumer, Series series, Li
|
|||||||
|
|
||||||
var hash = seriesMetadata.Contents.SHA256Hash();
|
var hash = seriesMetadata.Contents.SHA256Hash();
|
||||||
|
|
||||||
var metadata = existingMetadataFiles.SingleOrDefault(e => e.Type == MetadataType.SeriesMetadata) ??
|
var metadata = GetMetadataFile(series, existingMetadataFiles, e => e.Type == MetadataType.SeriesMetadata) ??
|
||||||
new MetadataFile
|
new MetadataFile
|
||||||
{
|
{
|
||||||
SeriesId = series.Id,
|
SeriesId = series.Id,
|
||||||
@ -180,7 +180,7 @@ private MetadataFile ProcessEpisodeMetadata(IMetadata consumer, Series series, E
|
|||||||
|
|
||||||
var fullPath = Path.Combine(series.Path, episodeMetadata.RelativePath);
|
var fullPath = Path.Combine(series.Path, episodeMetadata.RelativePath);
|
||||||
|
|
||||||
var existingMetadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.EpisodeMetadata &&
|
var existingMetadata = GetMetadataFile(series, existingMetadataFiles, c => c.Type == MetadataType.EpisodeMetadata &&
|
||||||
c.EpisodeFileId == episodeFile.Id);
|
c.EpisodeFileId == episodeFile.Id);
|
||||||
|
|
||||||
if (existingMetadata != null)
|
if (existingMetadata != null)
|
||||||
@ -230,7 +230,7 @@ private List<MetadataFile> ProcessSeriesImages(IMetadata consumer, Series series
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeriesImage &&
|
var metadata = GetMetadataFile(series, existingMetadataFiles, c => c.Type == MetadataType.SeriesImage &&
|
||||||
c.RelativePath == image.RelativePath) ??
|
c.RelativePath == image.RelativePath) ??
|
||||||
new MetadataFile
|
new MetadataFile
|
||||||
{
|
{
|
||||||
@ -252,17 +252,21 @@ private List<MetadataFile> ProcessSeasonImages(IMetadata consumer, Series series
|
|||||||
{
|
{
|
||||||
var result = new List<MetadataFile>();
|
var result = new List<MetadataFile>();
|
||||||
|
|
||||||
foreach (var season in series.Seasons)
|
foreach (var seasonItem in series.Seasons)
|
||||||
{
|
{
|
||||||
foreach (var image in consumer.SeasonImages(series, season))
|
var season = seasonItem;
|
||||||
|
|
||||||
|
foreach (var imageItem in consumer.SeasonImages(series, season))
|
||||||
{
|
{
|
||||||
|
var image = imageItem;
|
||||||
|
|
||||||
if (_diskProvider.FileExists(image.RelativePath))
|
if (_diskProvider.FileExists(image.RelativePath))
|
||||||
{
|
{
|
||||||
_logger.Debug("Season image already exists: {0}", image.RelativePath);
|
_logger.Debug("Season image already exists: {0}", image.RelativePath);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeasonImage &&
|
var metadata = GetMetadataFile(series, existingMetadataFiles, c => c.Type == MetadataType.SeasonImage &&
|
||||||
c.SeasonNumber == season.SeasonNumber &&
|
c.SeasonNumber == season.SeasonNumber &&
|
||||||
c.RelativePath == image.RelativePath) ??
|
c.RelativePath == image.RelativePath) ??
|
||||||
new MetadataFile
|
new MetadataFile
|
||||||
@ -297,7 +301,7 @@ private List<MetadataFile> ProcessEpisodeImages(IMetadata consumer, Series serie
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingMetadata = existingMetadataFiles.FirstOrDefault(c => c.Type == MetadataType.EpisodeImage &&
|
var existingMetadata = GetMetadataFile(series, existingMetadataFiles, c => c.Type == MetadataType.EpisodeImage &&
|
||||||
c.EpisodeFileId == episodeFile.Id);
|
c.EpisodeFileId == episodeFile.Id);
|
||||||
|
|
||||||
if (existingMetadata != null)
|
if (existingMetadata != null)
|
||||||
@ -352,5 +356,29 @@ private void SaveMetadataFile(String path, String contents)
|
|||||||
_diskProvider.WriteAllText(path, contents);
|
_diskProvider.WriteAllText(path, contents);
|
||||||
_mediaFileAttributeService.SetFilePermissions(path);
|
_mediaFileAttributeService.SetFilePermissions(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MetadataFile GetMetadataFile(Series series, List<MetadataFile> existingMetadataFiles, Func<MetadataFile, bool> predicate)
|
||||||
|
{
|
||||||
|
var matchingMetadataFiles = existingMetadataFiles.Where(predicate).ToList();
|
||||||
|
|
||||||
|
if (matchingMetadataFiles.Empty())
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Remove duplicate metadata files from DB and disk
|
||||||
|
foreach (var file in matchingMetadataFiles.Skip(1))
|
||||||
|
{
|
||||||
|
var path = Path.Combine(series.Path, file.RelativePath);
|
||||||
|
|
||||||
|
_logger.Debug("Removing duplicate Metadata file: {0}", path);
|
||||||
|
|
||||||
|
_diskProvider.DeleteFile(path);
|
||||||
|
_metadataFileService.Delete(file.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return matchingMetadataFiles.First();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user