mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-23 06:45:19 -07:00
Fix Corruped Media Cover Images.
This commit is contained in:
parent
a7e071318b
commit
eb299ce847
1 changed files with 29 additions and 2 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue