2014-09-07 11:39:00 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
|
using NzbDrone.Core.Exceptions;
|
|
|
|
|
using NzbDrone.Core.Indexers;
|
|
|
|
|
using NzbDrone.Core.Organizer;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
using NLog;
|
2014-09-11 20:24:00 +00:00
|
|
|
|
using NzbDrone.Core.RemotePathMappings;
|
2014-09-07 11:39:00 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Download
|
|
|
|
|
{
|
|
|
|
|
public abstract class UsenetClientBase<TSettings> : DownloadClientBase<TSettings>
|
|
|
|
|
where TSettings : IProviderConfig, new()
|
|
|
|
|
{
|
|
|
|
|
protected readonly IHttpClient _httpClient;
|
|
|
|
|
|
|
|
|
|
protected UsenetClientBase(IHttpClient httpClient,
|
2014-09-11 20:24:00 +00:00
|
|
|
|
IConfigService configService,
|
|
|
|
|
IDiskProvider diskProvider,
|
|
|
|
|
IRemotePathMappingService remotePathMappingService,
|
|
|
|
|
Logger logger)
|
2014-10-13 21:11:35 +00:00
|
|
|
|
: base(configService, diskProvider, remotePathMappingService, logger)
|
2014-09-07 11:39:00 +00:00
|
|
|
|
{
|
|
|
|
|
_httpClient = httpClient;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override DownloadProtocol Protocol
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return DownloadProtocol.Usenet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract String AddFromNzbFile(RemoteEpisode remoteEpisode, String filename, Byte[] fileContent);
|
|
|
|
|
|
|
|
|
|
public override String Download(RemoteEpisode remoteEpisode)
|
|
|
|
|
{
|
|
|
|
|
var url = remoteEpisode.Release.DownloadUrl;
|
|
|
|
|
var filename = FileNameBuilder.CleanFileName(remoteEpisode.Release.Title) + ".nzb";
|
|
|
|
|
|
|
|
|
|
Byte[] nzbData;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-09-12 22:39:42 +00:00
|
|
|
|
nzbData = _httpClient.Get(new HttpRequest(url)).ResponseData;
|
2014-09-07 11:39:00 +00:00
|
|
|
|
}
|
2015-06-27 09:43:17 +00:00
|
|
|
|
catch (HttpException ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException(String.Format("Downloading nzb for episode '{0}' failed ({1})",
|
|
|
|
|
remoteEpisode.Release.Title, url), ex);
|
|
|
|
|
|
|
|
|
|
throw new ReleaseDownloadException(remoteEpisode.Release, "Downloading nzb failed", ex);
|
|
|
|
|
}
|
2014-09-07 11:39:00 +00:00
|
|
|
|
catch (WebException ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException(String.Format("Downloading nzb for episode '{0}' failed ({1})",
|
|
|
|
|
remoteEpisode.Release.Title, url), ex);
|
|
|
|
|
|
|
|
|
|
throw new ReleaseDownloadException(remoteEpisode.Release, "Downloading nzb failed", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.Info("Adding report [{0}] to the queue.", remoteEpisode.Release.Title);
|
|
|
|
|
return AddFromNzbFile(remoteEpisode, filename, nzbData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|