Prevent queue/history from blowing up
This commit is contained in:
parent
715f6c3263
commit
9dcd58a631
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Parser;
|
||||
|
@ -42,9 +43,21 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
|
|||
|
||||
public override IEnumerable<QueueItem> GetQueue()
|
||||
{
|
||||
var items = _proxy.GetQueue(Settings);
|
||||
List<NzbgetQueueItem> queue;
|
||||
|
||||
foreach (var nzbGetQueueItem in items)
|
||||
try
|
||||
{
|
||||
queue = _proxy.GetQueue(Settings);
|
||||
}
|
||||
catch (DownloadClientException ex)
|
||||
{
|
||||
_logger.ErrorException(ex.Message, ex);
|
||||
return Enumerable.Empty<QueueItem>();
|
||||
}
|
||||
|
||||
var queueItems = new List<QueueItem>();
|
||||
|
||||
foreach (var nzbGetQueueItem in queue)
|
||||
{
|
||||
var queueItem = new QueueItem();
|
||||
queueItem.Id = nzbGetQueueItem.NzbId.ToString();
|
||||
|
@ -60,9 +73,10 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
|
|||
if (remoteEpisode.Series == null) continue;
|
||||
|
||||
queueItem.RemoteEpisode = remoteEpisode;
|
||||
|
||||
yield return queueItem;
|
||||
queueItems.Add(queueItem);
|
||||
}
|
||||
|
||||
return queueItems;
|
||||
}
|
||||
|
||||
public override IEnumerable<HistoryItem> GetHistory(int start = 0, int limit = 10)
|
||||
|
|
|
@ -60,11 +60,21 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
|||
{
|
||||
return _queueCache.Get("queue", () =>
|
||||
{
|
||||
var sabQueue = _sabnzbdProxy.GetQueue(0, 0, Settings).Items;
|
||||
SabnzbdQueue sabQueue;
|
||||
|
||||
try
|
||||
{
|
||||
sabQueue = _sabnzbdProxy.GetQueue(0, 0, Settings);
|
||||
}
|
||||
catch (DownloadClientException ex)
|
||||
{
|
||||
_logger.ErrorException(ex.Message, ex);
|
||||
return Enumerable.Empty<QueueItem>();
|
||||
}
|
||||
|
||||
var queueItems = new List<QueueItem>();
|
||||
|
||||
foreach (var sabQueueItem in sabQueue)
|
||||
foreach (var sabQueueItem in sabQueue.Items)
|
||||
{
|
||||
var queueItem = new QueueItem();
|
||||
queueItem.Id = sabQueueItem.Id;
|
||||
|
@ -91,10 +101,21 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
|||
|
||||
public override IEnumerable<HistoryItem> GetHistory(int start = 0, int limit = 10)
|
||||
{
|
||||
var items = _sabnzbdProxy.GetHistory(start, limit, Settings).Items;
|
||||
SabnzbdHistory sabHistory;
|
||||
|
||||
try
|
||||
{
|
||||
sabHistory = _sabnzbdProxy.GetHistory(start, limit, Settings);
|
||||
}
|
||||
catch (DownloadClientException ex)
|
||||
{
|
||||
_logger.ErrorException(ex.Message, ex);
|
||||
return Enumerable.Empty<HistoryItem>();
|
||||
}
|
||||
|
||||
var historyItems = new List<HistoryItem>();
|
||||
|
||||
foreach (var sabHistoryItem in items)
|
||||
foreach (var sabHistoryItem in sabHistory.Items)
|
||||
{
|
||||
var historyItem = new HistoryItem();
|
||||
historyItem.Id = sabHistoryItem.Id;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Download.Clients.Sabnzbd.Responses;
|
||||
using RestSharp;
|
||||
|
@ -112,14 +113,16 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
|||
{
|
||||
var protocol = settings.UseSsl ? "https" : "http";
|
||||
|
||||
var url = string.Format(@"{0}://{1}:{2}/api?{3}&apikey={4}&ma_username={5}&ma_password={6}&output=json",
|
||||
var authentication = settings.ApiKey.IsNullOrWhiteSpace() ?
|
||||
String.Format("ma_username={0}&ma_password={1}", settings.Username, settings.Password) :
|
||||
String.Format("apikey={0}", settings.ApiKey);
|
||||
|
||||
var url = string.Format(@"{0}://{1}:{2}/api?{3}&{4}&output=json",
|
||||
protocol,
|
||||
settings.Host,
|
||||
settings.Port,
|
||||
action,
|
||||
settings.ApiKey,
|
||||
settings.Username,
|
||||
settings.Password);
|
||||
authentication);
|
||||
|
||||
_logger.Trace(url);
|
||||
|
||||
|
@ -130,7 +133,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
|||
{
|
||||
if (response.ResponseStatus != ResponseStatus.Completed)
|
||||
{
|
||||
throw new ApplicationException("Unable to connect to SABnzbd, please check your settings");
|
||||
throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings");
|
||||
}
|
||||
|
||||
SabnzbdJsonError result;
|
||||
|
|
|
@ -81,7 +81,15 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
if (!_diskProvider.FolderExists(directoryName))
|
||||
{
|
||||
_diskProvider.CreateFolder(directoryName);
|
||||
try
|
||||
{
|
||||
_diskProvider.CreateFolder(directoryName);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
_logger.ErrorException("Unable to create directory: " + directoryName, ex);
|
||||
}
|
||||
|
||||
SetFolderPermissions(directoryName);
|
||||
|
||||
if (!directoryName.PathEquals(series.Path))
|
||||
|
|
Loading…
Reference in New Issue