1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

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.

This commit is contained in:
Taloth Saldono 2015-02-05 22:15:30 +01:00
parent 6c22a5ffdb
commit f5ddb36ebd
4 changed files with 20 additions and 24 deletions

View File

@ -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)
if (!_diskProvider.FileExists(resourcePath) || _diskProvider.GetFileSize(resourcePath) == 0)
{
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)
var baseResourcePath = RegexResizedImage.Replace(resourcePath, ".jpg$1");
if (baseResourcePath != resourcePath)
{
var baseResourceUrl = RegexResizedImage.Replace(resourceUrl, ".jpg$1");
if (baseResourceUrl != resourceUrl)
{
result = base.GetResponse(baseResourceUrl);
return baseResourcePath;
}
}
return result;
return resourcePath;
}
public override bool CanHandle(string resourceUrl)

View File

@ -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.

View File

@ -159,7 +159,8 @@ public void should_log_error_if_resize_failed()
Subject.HandleAsync(new SeriesUpdatedEvent(_series));
ExceptionVerification.ExpectedErrors(1);
Mocker.GetMock<IImageResizer>()
.Verify(v => v.Resize(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Exactly(2));
}
}
}

View File

@ -106,15 +106,8 @@ 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);
}
}
}
private void DownloadCover(Series series, MediaCover cover)
@ -158,8 +151,15 @@ private void EnsureResizedCovers(Series series, MediaCover cover, bool forceResi
{
_logger.Debug("Resizing {0}-{1} for {2}", cover.CoverType, height, series);
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);
}
}
}
}