Fixed: Metadata creation issue due to relative episode file paths

pull/4/head
Mark McDowall 10 years ago
parent ff4aa0685f
commit 39c66b7951

@ -4,12 +4,12 @@ namespace NzbDrone.Core.Metadata.Files
{ {
public class ImageFileResult public class ImageFileResult
{ {
public String Path { get; set; } public String RelativePath { get; set; }
public String Url { get; set; } public String Url { get; set; }
public ImageFileResult(string path, string url) public ImageFileResult(string relativePath, string url)
{ {
Path = path; RelativePath = relativePath;
Url = url; Url = url;
} }
} }

@ -4,12 +4,12 @@ namespace NzbDrone.Core.Metadata.Files
{ {
public class MetadataFileResult public class MetadataFileResult
{ {
public String Path { get; set; } public String RelativePath { get; set; }
public String Contents { get; set; } public String Contents { get; set; }
public MetadataFileResult(string path, string contents) public MetadataFileResult(string relativePath, string contents)
{ {
Path = path; RelativePath = relativePath;
Contents = contents; Contents = contents;
} }
} }

@ -156,11 +156,11 @@ namespace NzbDrone.Core.Metadata
return null; return null;
} }
_logger.Debug("Writing Series Metadata to: {0}", seriesMetadata.Path); _logger.Debug("Writing Series Metadata to: {0}", seriesMetadata.RelativePath);
_diskProvider.WriteAllText(seriesMetadata.Path, seriesMetadata.Contents); _diskProvider.WriteAllText(seriesMetadata.RelativePath, seriesMetadata.Contents);
metadata.Hash = hash; metadata.Hash = hash;
metadata.RelativePath = series.Path.GetRelativePath(seriesMetadata.Path); metadata.RelativePath = series.Path.GetRelativePath(seriesMetadata.RelativePath);
return metadata; return metadata;
} }
@ -174,7 +174,7 @@ namespace NzbDrone.Core.Metadata
return null; return null;
} }
var fullPath = Path.Combine(series.Path, episodeMetadata.Path); var fullPath = Path.Combine(series.Path, episodeMetadata.RelativePath);
var existingMetadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.EpisodeMetadata && var existingMetadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.EpisodeMetadata &&
c.EpisodeFileId == episodeFile.Id); c.EpisodeFileId == episodeFile.Id);
@ -182,10 +182,10 @@ namespace NzbDrone.Core.Metadata
if (existingMetadata != null) if (existingMetadata != null)
{ {
var existingFullPath = Path.Combine(series.Path, existingMetadata.RelativePath); var existingFullPath = Path.Combine(series.Path, existingMetadata.RelativePath);
if (!episodeMetadata.Path.PathEquals(existingFullPath)) if (!fullPath.PathEquals(existingFullPath))
{ {
_diskProvider.MoveFile(existingFullPath, fullPath); _diskProvider.MoveFile(existingFullPath, fullPath);
existingMetadata.RelativePath = episodeMetadata.Path; existingMetadata.RelativePath = episodeMetadata.RelativePath;
} }
} }
@ -198,7 +198,7 @@ namespace NzbDrone.Core.Metadata
EpisodeFileId = episodeFile.Id, EpisodeFileId = episodeFile.Id,
Consumer = consumer.GetType().Name, Consumer = consumer.GetType().Name,
Type = MetadataType.EpisodeMetadata, Type = MetadataType.EpisodeMetadata,
RelativePath = episodeMetadata.Path RelativePath = episodeMetadata.RelativePath
}; };
if (hash == metadata.Hash) if (hash == metadata.Hash)
@ -220,25 +220,23 @@ namespace NzbDrone.Core.Metadata
foreach (var image in consumer.SeriesImages(series)) foreach (var image in consumer.SeriesImages(series))
{ {
if (_diskProvider.FileExists(image.Path)) if (_diskProvider.FileExists(image.RelativePath))
{ {
_logger.Debug("Series image already exists: {0}", image.Path); _logger.Debug("Series image already exists: {0}", image.RelativePath);
continue; continue;
} }
var relativePath = series.Path.GetRelativePath(image.Path);
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeriesImage && var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeriesImage &&
c.RelativePath == relativePath) ?? c.RelativePath == image.RelativePath) ??
new MetadataFile new MetadataFile
{ {
SeriesId = series.Id, SeriesId = series.Id,
Consumer = consumer.GetType().Name, Consumer = consumer.GetType().Name,
Type = MetadataType.SeriesImage, Type = MetadataType.SeriesImage,
RelativePath = relativePath RelativePath = image.RelativePath
}; };
_diskProvider.CopyFile(image.Url, image.Path); _diskProvider.CopyFile(image.Url, image.RelativePath);
result.Add(metadata); result.Add(metadata);
} }
@ -254,27 +252,25 @@ namespace NzbDrone.Core.Metadata
{ {
foreach (var image in consumer.SeasonImages(series, season)) foreach (var image in consumer.SeasonImages(series, season))
{ {
if (_diskProvider.FileExists(image.Path)) if (_diskProvider.FileExists(image.RelativePath))
{ {
_logger.Debug("Season image already exists: {0}", image.Path); _logger.Debug("Season image already exists: {0}", image.RelativePath);
continue; continue;
} }
var relativePath = series.Path.GetRelativePath(image.Path);
var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeasonImage && var metadata = existingMetadataFiles.SingleOrDefault(c => c.Type == MetadataType.SeasonImage &&
c.SeasonNumber == season.SeasonNumber && c.SeasonNumber == season.SeasonNumber &&
c.RelativePath == relativePath) ?? c.RelativePath == image.RelativePath) ??
new MetadataFile new MetadataFile
{ {
SeriesId = series.Id, SeriesId = series.Id,
SeasonNumber = season.SeasonNumber, SeasonNumber = season.SeasonNumber,
Consumer = consumer.GetType().Name, Consumer = consumer.GetType().Name,
Type = MetadataType.SeasonImage, Type = MetadataType.SeasonImage,
RelativePath = relativePath RelativePath = image.RelativePath
}; };
DownloadImage(series, image.Url, image.Path); DownloadImage(series, image.Url, image.RelativePath);
result.Add(metadata); result.Add(metadata);
} }
@ -289,11 +285,11 @@ namespace NzbDrone.Core.Metadata
foreach (var image in consumer.EpisodeImages(series, episodeFile)) foreach (var image in consumer.EpisodeImages(series, episodeFile))
{ {
var fullPath = Path.Combine(series.Path, image.Path); var fullPath = Path.Combine(series.Path, image.RelativePath);
if (_diskProvider.FileExists(image.Path)) if (_diskProvider.FileExists(fullPath))
{ {
_logger.Debug("Episode image already exists: {0}", image.Path); _logger.Debug("Episode image already exists: {0}", image.RelativePath);
continue; continue;
} }
@ -306,7 +302,7 @@ namespace NzbDrone.Core.Metadata
if (!fullPath.PathEquals(existingFullPath)) if (!fullPath.PathEquals(existingFullPath))
{ {
_diskProvider.MoveFile(fullPath, fullPath); _diskProvider.MoveFile(fullPath, fullPath);
existingMetadata.RelativePath = image.Path; existingMetadata.RelativePath = image.RelativePath;
return new List<MetadataFile>{ existingMetadata }; return new List<MetadataFile>{ existingMetadata };
} }
@ -319,10 +315,10 @@ namespace NzbDrone.Core.Metadata
EpisodeFileId = episodeFile.Id, EpisodeFileId = episodeFile.Id,
Consumer = consumer.GetType().Name, Consumer = consumer.GetType().Name,
Type = MetadataType.EpisodeImage, Type = MetadataType.EpisodeImage,
RelativePath = series.Path.GetRelativePath(image.Path) RelativePath = image.RelativePath
}; };
DownloadImage(series, image.Url, image.Path); DownloadImage(series, image.Url, fullPath);
result.Add(metadata); result.Add(metadata);
} }

Loading…
Cancel
Save