1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-27 02:09:59 +00: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)
{
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)

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,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);
}
}
}
}