2013-06-03 05:39:42 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common;
|
2013-06-03 05:51:16 +00:00
|
|
|
|
using NzbDrone.Common.Serializer;
|
2013-05-29 04:10:23 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.MediaCover
|
|
|
|
|
{
|
|
|
|
|
public interface ICoverExistsSpecification
|
|
|
|
|
{
|
2013-06-03 05:39:42 +00:00
|
|
|
|
bool AlreadyExists(string url, string path);
|
2013-05-29 04:10:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-05-29 04:10:23 +00:00
|
|
|
|
|
2013-06-03 05:39:42 +00:00
|
|
|
|
public CoverAlreadyExistsSpecification(IDiskProvider diskProvider, IHttpProvider httpProvider, Logger logger)
|
2013-05-29 04:10:23 +00:00
|
|
|
|
{
|
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
|
_httpProvider = httpProvider;
|
2013-06-03 05:39:42 +00:00
|
|
|
|
_logger = logger;
|
2013-05-29 04:10:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AlreadyExists(string url, string path)
|
|
|
|
|
{
|
|
|
|
|
if (!_diskProvider.FileExists(path))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 06:12:31 +00:00
|
|
|
|
var headers = _httpProvider.GetHeader(url);
|
2013-05-29 04:10:23 +00:00
|
|
|
|
|
2013-06-03 05:39:42 +00:00
|
|
|
|
string sizeString;
|
2013-05-29 04:10:23 +00:00
|
|
|
|
|
2013-08-22 04:42:25 +00:00
|
|
|
|
if (headers.TryGetValue(HttpProvider.CONTENT_LENGTH_HEADER, out sizeString))
|
2013-05-29 04:10:23 +00:00
|
|
|
|
{
|
|
|
|
|
int size;
|
|
|
|
|
int.TryParse(sizeString, out size);
|
|
|
|
|
var fileSize = _diskProvider.GetFileSize(path);
|
|
|
|
|
|
2013-06-03 05:39:42 +00:00
|
|
|
|
return fileSize == size;
|
2013-05-29 04:10:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-03 05:51:16 +00:00
|
|
|
|
_logger.Warn("Couldn't find content-length header {0}", headers.ToJson());
|
2013-06-03 05:39:42 +00:00
|
|
|
|
|
|
|
|
|
return false;
|
2013-05-29 04:10:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|