1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-29 03:05:49 +00:00

Fixed: Metadata creation issue due to relative episode file paths

This commit is contained in:
Mark McDowall 2014-08-14 23:57:49 -07:00
parent ff4aa0685f
commit 39c66b7951
3 changed files with 29 additions and 33 deletions

View file

@ -4,12 +4,12 @@ namespace NzbDrone.Core.Metadata.Files
{
public class ImageFileResult
{
public String Path { get; set; }
public String RelativePath { 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;
}
}

View file

@ -4,12 +4,12 @@ namespace NzbDrone.Core.Metadata.Files
{
public class MetadataFileResult
{
public String Path { get; set; }
public String RelativePath { 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;
}
}

View file

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