You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecifica...

34 lines
980 B

10 years ago
using NzbDrone.Common.Disk;
using NzbDrone.Common.Http;
namespace NzbDrone.Core.MediaCover
{
public interface ICoverExistsSpecification
{
bool AlreadyExists(string url, string path);
}
public class CoverAlreadyExistsSpecification : ICoverExistsSpecification
{
private readonly IDiskProvider _diskProvider;
10 years ago
private readonly IHttpClient _httpClient;
10 years ago
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider, IHttpClient httpClient)
{
_diskProvider = diskProvider;
10 years ago
_httpClient = httpClient;
}
public bool AlreadyExists(string url, string path)
{
if (!_diskProvider.FileExists(path))
{
return false;
}
10 years ago
var headers = _httpClient.Head(new HttpRequest(url)).Headers;
var fileSize = _diskProvider.GetFileSize(path);
return fileSize == headers.ContentLength;
}
}
}