1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Storing nzo_id from SAB in history (data)

This commit is contained in:
Mark McDowall 2013-10-20 18:30:46 -07:00
parent fa2bc76102
commit 2e1b921543
8 changed files with 36 additions and 51 deletions

View File

@ -22,7 +22,7 @@ public BlackholeProvider(IConfigService configService, IHttpProvider httpProvide
_logger = logger;
}
public void DownloadNzb(RemoteEpisode remoteEpisode)
public string DownloadNzb(RemoteEpisode remoteEpisode)
{
var url = remoteEpisode.Release.DownloadUrl;
var title = remoteEpisode.Release.Title;
@ -34,8 +34,9 @@ public void DownloadNzb(RemoteEpisode remoteEpisode)
_logger.Trace("Downloading NZB from: {0} to: {1}", url, filename);
_httpProvider.DownloadFile(url, filename);
_logger.Trace("NZB Download succeeded, saved to: {0}", filename);
return null;
}
public bool IsConfigured

View File

@ -24,7 +24,7 @@ public NzbgetClient(IConfigService configService, IHttpProvider httpProvider, IP
_logger = logger;
}
public void DownloadNzb(RemoteEpisode remoteEpisode)
public string DownloadNzb(RemoteEpisode remoteEpisode)
{
var url = remoteEpisode.Release.DownloadUrl;
var title = remoteEpisode.Release.Title + ".nzb";
@ -46,6 +46,7 @@ public void DownloadNzb(RemoteEpisode remoteEpisode)
var success = Json.Deserialize<EnqueueResponse>(response).Result;
_logger.Debug("Queue Response: [{0}]", success);
return null;
}
public bool IsConfigured

View File

@ -26,7 +26,7 @@ public PneumaticClient(IConfigService configService, IHttpProvider httpProvider,
_diskProvider = diskProvider;
}
public void DownloadNzb(RemoteEpisode remoteEpisode)
public string DownloadNzb(RemoteEpisode remoteEpisode)
{
var url = remoteEpisode.Release.DownloadUrl;
var title = remoteEpisode.Release.Title;
@ -41,8 +41,6 @@ public void DownloadNzb(RemoteEpisode remoteEpisode)
//Save to the Pneumatic directory (The user will need to ensure its accessible by XBMC)
var filename = Path.Combine(_configService.PneumaticFolder, title + ".nzb");
logger.Trace("Downloading NZB from: {0} to: {1}", url, filename);
_httpProvider.DownloadFile(url, filename);
@ -50,6 +48,8 @@ public void DownloadNzb(RemoteEpisode remoteEpisode)
var contents = String.Format("plugin://plugin.program.pneumatic/?mode=strm&type=add_file&nzb={0}&nzbname={1}", filename, title);
_diskProvider.WriteAllText(Path.Combine(_configService.DownloadedEpisodesFolder, title + ".strm"), contents);
return null;
}
public bool IsConfigured

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json.Linq;
using NLog;
@ -13,43 +14,6 @@
namespace NzbDrone.Core.Download.Clients.Sabnzbd
{
public class SabRequestBuilder
{
private readonly IConfigService _configService;
public SabRequestBuilder(IConfigService configService)
{
_configService = configService;
}
public IRestRequest AddToQueueRequest(RemoteEpisode remoteEpisode)
{
string cat = _configService.SabTvCategory;
int priority = (int)_configService.SabRecentTvPriority;
string name = remoteEpisode.Release.DownloadUrl.Replace("&", "%26");
string nzbName = HttpUtility.UrlEncode(remoteEpisode.Release.Title);
string action = string.Format("mode=addurl&name={0}&priority={1}&pp=3&cat={2}&nzbname={3}&output=json",
name, priority, cat, nzbName);
string request = GetSabRequest(action);
return new RestRequest(request);
}
private string GetSabRequest(string action)
{
return string.Format(@"http://{0}:{1}/api?{2}&apikey={3}&ma_username={4}&ma_password={5}",
_configService.SabHost,
_configService.SabPort,
action,
_configService.SabApiKey,
_configService.SabUsername,
_configService.SabPassword);
}
}
public class SabnzbdClient : IDownloadClient
{
private readonly IConfigService _configService;
@ -74,7 +38,7 @@ public SabnzbdClient(IConfigService configService,
_logger = logger;
}
public void DownloadNzb(RemoteEpisode remoteEpisode)
public string DownloadNzb(RemoteEpisode remoteEpisode)
{
var url = remoteEpisode.Release.DownloadUrl;
var title = remoteEpisode.Release.Title;
@ -84,9 +48,11 @@ public void DownloadNzb(RemoteEpisode remoteEpisode)
using (var nzb = _httpProvider.DownloadStream(url))
{
_logger.Info("Adding report [{0}] to the queue.", title);
var response = _sabCommunicationProxy.DownloadNzb(nzb, title, category, priority);
var response = Json.Deserialize<SabAddResponse>(_sabCommunicationProxy.DownloadNzb(nzb, title, category, priority));
_logger.Debug("Queue Response: [{0}]", response);
_logger.Debug("Queue Response: [{0}]", response.Status);
return response.Ids.First();
}
}

View File

@ -1,4 +1,5 @@
using NLog;
using System;
using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Messaging.Events;
@ -40,10 +41,17 @@ public void DownloadReport(RemoteEpisode remoteEpisode)
return;
}
downloadClient.DownloadNzb(remoteEpisode);
var downloadClientId = downloadClient.DownloadNzb(remoteEpisode);
var episodeGrabbedEvent = new EpisodeGrabbedEvent(remoteEpisode);
if (!String.IsNullOrWhiteSpace(downloadClientId))
{
episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name;
episodeGrabbedEvent.DownloadClientId = downloadClientId;
}
_logger.ProgressInfo("Report sent to download client. {0}", downloadTitle);
_eventAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode));
_eventAggregator.PublishEvent(episodeGrabbedEvent);
}
}
}

View File

@ -1,4 +1,5 @@
using NzbDrone.Common.Messaging;
using System;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.Download
@ -6,6 +7,8 @@ namespace NzbDrone.Core.Download
public class EpisodeGrabbedEvent : IEvent
{
public RemoteEpisode Episode { get; private set; }
public String DownloadClient { get; set; }
public String DownloadClientId { get; set; }
public EpisodeGrabbedEvent(RemoteEpisode episode)
{

View File

@ -5,7 +5,7 @@ namespace NzbDrone.Core.Download
{
public interface IDownloadClient
{
void DownloadNzb(RemoteEpisode remoteEpisode);
string DownloadNzb(RemoteEpisode remoteEpisode);
bool IsConfigured { get; }
IEnumerable<QueueItem> GetQueue();
}

View File

@ -75,6 +75,12 @@ public void Handle(EpisodeGrabbedEvent message)
history.Data.Add("ReleaseGroup", message.Episode.Release.ReleaseGroup);
history.Data.Add("Age", message.Episode.Release.Age.ToString());
if (!String.IsNullOrWhiteSpace(message.DownloadClientId))
{
history.Data.Add("DownloadClient", message.DownloadClient);
history.Data.Add("DownloadClientId", message.DownloadClientId);
}
_historyRepository.Insert(history);
}
}