1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-31 16:02:29 +01:00
Sonarr/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecification.cs

50 lines
1.4 KiB
C#

using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.MediaCover
{
public interface ICoverExistsSpecification
{
bool AlreadyExists(string url, string path);
}
public class CoverAlreadyExistsSpecification : ICoverExistsSpecification
{
private readonly IDiskProvider _diskProvider;
private readonly IHttpProvider _httpProvider;
private readonly Logger _logger;
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider, IHttpProvider httpProvider, Logger logger)
{
_diskProvider = diskProvider;
_httpProvider = httpProvider;
_logger = logger;
}
public bool AlreadyExists(string url, string path)
{
if (!_diskProvider.FileExists(path))
{
return false;
}
var headers = _httpProvider.GetHeader(url);
string sizeString;
if (headers.TryGetValue(HttpProvider.CONTENT_LENGHT_HEADER, out sizeString))
{
int size;
int.TryParse(sizeString, out size);
var fileSize = _diskProvider.GetFileSize(path);
return fileSize == size;
}
_logger.Warn("Couldn't find content-length header {0}", headers.ToJson());
return false;
}
}
}