1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-29 11:16:19 +00:00
Sonarr/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecification.cs

49 lines
1.4 KiB
C#
Raw Normal View History

2013-06-03 05:39:42 +00:00
using NLog;
using NzbDrone.Common;
namespace NzbDrone.Core.MediaCover
{
public interface ICoverExistsSpecification
{
2013-06-03 05:39:42 +00:00
bool AlreadyExists(string url, string path);
}
public class CoverAlreadyExistsSpecification : ICoverExistsSpecification
{
private readonly IDiskProvider _diskProvider;
private readonly IHttpProvider _httpProvider;
2013-06-03 05:39:42 +00:00
private readonly Logger _logger;
2013-06-03 05:39:42 +00:00
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider, IHttpProvider httpProvider, Logger logger)
{
_diskProvider = diskProvider;
_httpProvider = httpProvider;
2013-06-03 05:39:42 +00:00
_logger = logger;
}
public bool AlreadyExists(string url, string path)
{
if (!_diskProvider.FileExists(path))
{
return false;
}
var headers = _httpProvider.DownloadHeader(url);
2013-06-03 05:39:42 +00:00
string sizeString;
2013-06-03 05:39:42 +00:00
if (headers.TryGetValue(headers[HttpProvider.ContentLenghtHeader], out sizeString))
{
int size;
int.TryParse(sizeString, out size);
var fileSize = _diskProvider.GetFileSize(path);
2013-06-03 05:39:42 +00:00
return fileSize == size;
}
2013-06-03 05:39:42 +00:00
_logger.Warn("Couldn't read content length header {0}", headers[HttpProvider.ContentLenghtHeader]);
return false;
}
}
}