Fixed: Album Metadata Images don't always save in correct folder

pull/145/head
Qstick 7 years ago
parent 8219a8014b
commit 2afa6c02de

@ -331,7 +331,7 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
return new List<ImageFileResult>(); return new List<ImageFileResult>();
} }
return ProcessAlbumImages(artist, album).ToList(); return ProcessAlbumImages(album).ToList();
} }
public override List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile) public override List<ImageFileResult> TrackImages(Artist artist, TrackFile trackFile)
@ -351,14 +351,13 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
} }
} }
private IEnumerable<ImageFileResult> ProcessAlbumImages(Artist artist, Album album) private IEnumerable<ImageFileResult> ProcessAlbumImages(Album album)
{ {
foreach (var image in album.Images) foreach (var image in album.Images)
{ {
var destination = Path.GetFileName(album.Path); var destination = image.CoverType.ToString().ToLowerInvariant() + Path.GetExtension(image.Url);
var filename = string.Format("{0}\\{1}{2}", destination, image.CoverType.ToString().ToLower(), Path.GetExtension(image.Url));
yield return new ImageFileResult(filename, image.Url); yield return new ImageFileResult(destination, image.Url);
} }
} }

@ -392,7 +392,7 @@ namespace NzbDrone.Core.Extras.Metadata
Extension = Path.GetExtension(fullPath) Extension = Path.GetExtension(fullPath)
}; };
DownloadImage(artist, image); DownloadImage(album, image);
result.Add(metadata); result.Add(metadata);
} }
@ -476,6 +476,32 @@ namespace NzbDrone.Core.Extras.Metadata
} }
} }
private void DownloadImage(Album album, ImageFileResult image)
{
var fullPath = Path.Combine(album.Path, image.RelativePath);
try
{
if (image.Url.StartsWith("http"))
{
_httpClient.DownloadFile(image.Url, fullPath);
}
else
{
_diskProvider.CopyFile(image.Url, fullPath);
}
_mediaFileAttributeService.SetFilePermissions(fullPath);
}
catch (WebException ex)
{
_logger.Warn(ex, "Couldn't download image {0} for {1}. {2}", image.Url, album, ex.Message);
}
catch (Exception ex)
{
_logger.Error(ex, "Couldn't download image {0} for {1}. {2}", image.Url, album, ex.Message);
}
}
private void SaveMetadataFile(string path, string contents) private void SaveMetadataFile(string path, string contents)
{ {
_diskProvider.WriteAllText(path, contents); _diskProvider.WriteAllText(path, contents);

Loading…
Cancel
Save