Fix Corruped Media Cover Images.

pull/373/head
Leonardo Galli 8 years ago
parent a7e071318b
commit eb299ce847

@ -1,5 +1,8 @@
using NzbDrone.Common.Disk;
using System;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
using System.Drawing;
using NLog;
namespace NzbDrone.Core.MediaCover
{
@ -12,11 +15,13 @@ namespace NzbDrone.Core.MediaCover
{
private readonly IDiskProvider _diskProvider;
private readonly IHttpClient _httpClient;
private readonly Logger _logger;
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider, IHttpClient httpClient)
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider, IHttpClient httpClient, Logger logger)
{
_diskProvider = diskProvider;
_httpClient = httpClient;
_logger = logger;
}
public bool AlreadyExists(string url, string path)
@ -26,9 +31,31 @@ namespace NzbDrone.Core.MediaCover
return false;
}
if (!IsValidGDIPlusImage(path))
{
_diskProvider.DeleteFile(path);
return false;
}
var headers = _httpClient.Head(new HttpRequest(url)).Headers;
var fileSize = _diskProvider.GetFileSize(path);
return fileSize == headers.ContentLength;
}
private bool IsValidGDIPlusImage(string filename)
{
try
{
using (var bmp = new Bitmap(filename))
{
}
return true;
}
catch (Exception ex)
{
_logger.Debug(ex, "Corrupted image found at: {0}. Redownloading...", filename);
return false;
}
}
}
}
Loading…
Cancel
Save