diff --git a/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs b/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs index 983754fa7..12bb5daf5 100644 --- a/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs +++ b/src/NzbDrone.Core/Extras/Metadata/Consumers/Xbmc/XbmcMetadata.cs @@ -331,7 +331,7 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc return new List(); } - return ProcessAlbumImages(artist, album).ToList(); + return ProcessAlbumImages(album).ToList(); } public override List TrackImages(Artist artist, TrackFile trackFile) @@ -351,14 +351,13 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc } } - private IEnumerable ProcessAlbumImages(Artist artist, Album album) + private IEnumerable ProcessAlbumImages(Album album) { foreach (var image in album.Images) { - var destination = Path.GetFileName(album.Path); - var filename = string.Format("{0}\\{1}{2}", destination, image.CoverType.ToString().ToLower(), Path.GetExtension(image.Url)); + var destination = image.CoverType.ToString().ToLowerInvariant() + Path.GetExtension(image.Url); - yield return new ImageFileResult(filename, image.Url); + yield return new ImageFileResult(destination, image.Url); } } diff --git a/src/NzbDrone.Core/Extras/Metadata/MetadataService.cs b/src/NzbDrone.Core/Extras/Metadata/MetadataService.cs index 003350eaf..9d6383fd9 100644 --- a/src/NzbDrone.Core/Extras/Metadata/MetadataService.cs +++ b/src/NzbDrone.Core/Extras/Metadata/MetadataService.cs @@ -392,7 +392,7 @@ namespace NzbDrone.Core.Extras.Metadata Extension = Path.GetExtension(fullPath) }; - DownloadImage(artist, image); + DownloadImage(album, image); 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) { _diskProvider.WriteAllText(path, contents);