From f5ddb36ebd3fbc6cfcb11e94075c67726634e1d1 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Thu, 5 Feb 2015 22:15:30 +0100 Subject: [PATCH] Fixed: All issues regarding Media Covers should be fixed now after apply this update. Refresh browser cache if still missing and report issues on forum. --- .../Frontend/Mappers/MediaCoverMapper.cs | 21 +++++++------------ .../MediaCovers/MediaCoverModule.cs | 2 +- .../MediaCoverServiceFixture.cs | 3 ++- .../MediaCover/MediaCoverService.cs | 18 ++++++++-------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/NzbDrone.Api/Frontend/Mappers/MediaCoverMapper.cs b/src/NzbDrone.Api/Frontend/Mappers/MediaCoverMapper.cs index 58e14020d..75abdaee5 100644 --- a/src/NzbDrone.Api/Frontend/Mappers/MediaCoverMapper.cs +++ b/src/NzbDrone.Api/Frontend/Mappers/MediaCoverMapper.cs @@ -13,11 +13,13 @@ public class MediaCoverMapper : StaticResourceMapperBase private static readonly Regex RegexResizedImage = new Regex(@"-\d+\.jpg($|\?)", RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly IAppFolderInfo _appFolderInfo; + private readonly IDiskProvider _diskProvider; public MediaCoverMapper(IAppFolderInfo appFolderInfo, IDiskProvider diskProvider, Logger logger) : base(diskProvider, logger) { _appFolderInfo = appFolderInfo; + _diskProvider = diskProvider; } public override string Map(string resourceUrl) @@ -25,25 +27,18 @@ public override string Map(string resourceUrl) var path = resourceUrl.Replace('/', Path.DirectorySeparatorChar); path = path.Trim(Path.DirectorySeparatorChar); - return Path.Combine(_appFolderInfo.GetAppDataPath(), path); - } + var resourcePath = Path.Combine(_appFolderInfo.GetAppDataPath(), path); - public override Response GetResponse(string resourceUrl) - { - var result = base.GetResponse(resourceUrl); - - // Return the full sized image if someone requests a non-existing resized one. - // TODO: This code can be removed later once everyone had the update for a while. - if (result is NotFoundResponse) + if (!_diskProvider.FileExists(resourcePath) || _diskProvider.GetFileSize(resourcePath) == 0) { - var baseResourceUrl = RegexResizedImage.Replace(resourceUrl, ".jpg$1"); - if (baseResourceUrl != resourceUrl) + var baseResourcePath = RegexResizedImage.Replace(resourcePath, ".jpg$1"); + if (baseResourcePath != resourcePath) { - result = base.GetResponse(baseResourceUrl); + return baseResourcePath; } } - return result; + return resourcePath; } public override bool CanHandle(string resourceUrl) diff --git a/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs b/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs index 08fbeec08..a4ad78ef4 100644 --- a/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs +++ b/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs @@ -29,7 +29,7 @@ private Response GetMediaCover(int seriesId, string filename) { var filePath = Path.Combine(_appFolderInfo.GetAppDataPath(), "MediaCover", seriesId.ToString(), filename); - if (!_diskProvider.FileExists(filePath)) + if (!_diskProvider.FileExists(filePath) || _diskProvider.GetFileSize(filePath) == 0) { // Return the full sized image if someone requests a non-existing resized one. // TODO: This code can be removed later once everyone had the update for a while. diff --git a/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs b/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs index cd54723af..fb5900f37 100644 --- a/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaCoverTests/MediaCoverServiceFixture.cs @@ -159,7 +159,8 @@ public void should_log_error_if_resize_failed() Subject.HandleAsync(new SeriesUpdatedEvent(_series)); - ExceptionVerification.ExpectedErrors(1); + Mocker.GetMock() + .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs index d72916f7d..446865425 100644 --- a/src/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/src/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -106,14 +106,7 @@ private void EnsureCovers(Series series) _logger.ErrorException("Couldn't download media cover for " + series, e); } - try - { - EnsureResizedCovers(series, cover, !alreadyExists); - } - catch (Exception e) - { - _logger.ErrorException("Couldn't resize media cover for " + series + " using full size image instead.", e); - } + EnsureResizedCovers(series, cover, !alreadyExists); } } @@ -158,7 +151,14 @@ private void EnsureResizedCovers(Series series, MediaCover cover, bool forceResi { _logger.Debug("Resizing {0}-{1} for {2}", cover.CoverType, height, series); - _resizer.Resize(mainFileName, resizeFileName, height); + try + { + _resizer.Resize(mainFileName, resizeFileName, height); + } + catch + { + _logger.Debug("Couldn't resize media cover {0}-{1} for {2}, using full size image instead.", cover.CoverType, height, series); + } } } }