Make syntax compatible
This commit is contained in:
parent
2eb24d494b
commit
cd162f83c2
|
@ -1,3 +1,4 @@
|
||||||
|
/*
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -9,6 +10,7 @@ using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||||
using NzbDrone.Core.Download;
|
using NzbDrone.Core.Download;
|
||||||
using NzbDrone.Core.Download.Clients.Putio;
|
using NzbDrone.Core.Download.Clients.Putio;
|
||||||
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
@ -336,3 +338,5 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.PutioTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using FluentValidation.Results;
|
||||||
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Common.Http;
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NLog;
|
|
||||||
using FluentValidation.Results;
|
|
||||||
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||||
using NzbDrone.Core.Validation;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using NzbDrone.Core.RemotePathMappings;
|
using NzbDrone.Core.RemotePathMappings;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.Clients.Putio
|
namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
|
@ -37,6 +37,7 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
return "put.io";
|
return "put.io";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string hash, string magnetLink)
|
protected override string AddFromMagnetLink(RemoteEpisode remoteEpisode, string hash, string magnetLink)
|
||||||
{
|
{
|
||||||
_proxy.AddTorrentFromUrl(magnetLink, Settings);
|
_proxy.AddTorrentFromUrl(magnetLink, Settings);
|
||||||
|
@ -69,14 +70,16 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
// If totalsize == 0 the torrent is a magnet downloading metadata
|
// If totalsize == 0 the torrent is a magnet downloading metadata
|
||||||
if (torrent.Size == 0)
|
if (torrent.Size == 0)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var item = new DownloadClientItem();
|
var item = new DownloadClientItem();
|
||||||
item.DownloadId = "putio-" + torrent.Id;
|
item.DownloadId = "putio-" + torrent.Id;
|
||||||
item.Category = Settings.SaveParentId;
|
item.Category = Settings.SaveParentId;
|
||||||
item.Title = torrent.Name;
|
item.Title = torrent.Name;
|
||||||
|
|
||||||
item.DownloadClient = Definition.Name;
|
// item.DownloadClient = Definition.Name;
|
||||||
|
|
||||||
item.TotalSize = torrent.Size;
|
item.TotalSize = torrent.Size;
|
||||||
item.RemainingSize = torrent.Size - torrent.Downloaded;
|
item.RemainingSize = torrent.Size - torrent.Downloaded;
|
||||||
|
@ -93,7 +96,10 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
if (Settings.SaveParentId.IsNotNullOrWhiteSpace())
|
if (Settings.SaveParentId.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
var directories = outputPath.FullPath.Split('\\', '/');
|
var directories = outputPath.FullPath.Split('\\', '/');
|
||||||
if (!directories.Contains(string.Format("{0}", Settings.SaveParentId))) continue;
|
if (!directories.Contains(string.Format("{0}", Settings.SaveParentId)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item.OutputPath = outputPath; // + torrent.Name;
|
item.OutputPath = outputPath; // + torrent.Name;
|
||||||
|
@ -135,16 +141,11 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void RemoveItem(string downloadId, bool deleteData)
|
public override DownloadClientInfo GetStatus()
|
||||||
{
|
|
||||||
_proxy.RemoveTorrent(downloadId.ToLower(), Settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override DownloadClientStatus GetStatus()
|
|
||||||
{
|
{
|
||||||
var destDir = string.Format("{0}", Settings.SaveParentId);
|
var destDir = string.Format("{0}", Settings.SaveParentId);
|
||||||
|
|
||||||
return new DownloadClientStatus
|
return new DownloadClientInfo
|
||||||
{
|
{
|
||||||
IsLocalhost = false,
|
IsLocalhost = false,
|
||||||
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Url, new OsPath(destDir)) }
|
OutputRootFolders = new List<OsPath> { _remotePathMappingService.RemapRemoteToLocal(Settings.Url, new OsPath(destDir)) }
|
||||||
|
@ -154,7 +155,11 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
protected override void Test(List<ValidationFailure> failures)
|
protected override void Test(List<ValidationFailure> failures)
|
||||||
{
|
{
|
||||||
failures.AddIfNotNull(TestConnection());
|
failures.AddIfNotNull(TestConnection());
|
||||||
if (failures.Any()) return;
|
if (failures.Any())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
failures.AddIfNotNull(TestGetTorrents());
|
failures.AddIfNotNull(TestGetTorrents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,5 +192,10 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void RemoveItem(DownloadClientItem item, bool deleteData)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.Clients.Putio
|
namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
public class PutioException : DownloadClientException
|
public class PutioException : DownloadClientException
|
||||||
|
@ -7,7 +5,6 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
public PutioException(string message)
|
public PutioException(string message)
|
||||||
: base(message)
|
: base(message)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
namespace NzbDrone.Core.Download.Clients.Putio
|
namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
public class PutioFileResponse : PutioGenericResponse
|
public class PutioFileResponse : PutioGenericResponse
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NzbDrone.Core.Rest;
|
using System.Net;
|
||||||
using NLog;
|
using NLog;
|
||||||
using RestSharp;
|
using NzbDrone.Common.Http;
|
||||||
using RestSharp.Deserializers;
|
using NzbDrone.Common.Serializer;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.Clients.Putio
|
namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
|
@ -18,90 +17,98 @@ namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
void GetAccountSettings(PutioSettings settings);
|
void GetAccountSettings(PutioSettings settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PutioProxy: IPutioProxy
|
public class PutioProxy : IPutioProxy
|
||||||
{
|
{
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
private readonly IHttpClient _httpClient;
|
||||||
|
|
||||||
public PutioProxy(Logger logger)
|
public PutioProxy(Logger logger, IHttpClient client)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_httpClient = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PutioTorrent> GetTorrents(PutioSettings settings)
|
public List<PutioTorrent> GetTorrents(PutioSettings settings)
|
||||||
{
|
{
|
||||||
var result = ProcessRequest<PutioTransfersResponse>(Method.GET, "transfers/list", null, settings);
|
// var result = ProcessRequest<PutioTransfersResponse>(Method.GET, "transfers/list", null, settings);
|
||||||
return result.Transfers;
|
// return result.Transfers;
|
||||||
|
return new List<PutioTorrent>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PutioFile GetFile(long fileId, PutioSettings settings)
|
public PutioFile GetFile(long fileId, PutioSettings settings)
|
||||||
{
|
{
|
||||||
var result = ProcessRequest<PutioFileResponse>(Method.GET, "files/" + fileId, null, settings);
|
// var result = ProcessRequest<PutioFileResponse>(Method.GET, "files/" + fileId, null, settings);
|
||||||
return result.File;
|
// return result.File;
|
||||||
|
return new PutioFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTorrentFromUrl(string torrentUrl, PutioSettings settings)
|
public void AddTorrentFromUrl(string torrentUrl, PutioSettings settings)
|
||||||
{
|
{
|
||||||
var arguments = new Dictionary<string, object>();
|
// var arguments = new Dictionary<string, object>();
|
||||||
arguments.Add("url", torrentUrl);
|
// arguments.Add("url", torrentUrl);
|
||||||
ProcessRequest<PutioGenericResponse>(Method.POST, "transfers/add", arguments, settings);
|
// ProcessRequest<PutioGenericResponse>(Method.POST, "transfers/add", arguments, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTorrentFromData(byte[] torrentData, PutioSettings settings)
|
public void AddTorrentFromData(byte[] torrentData, PutioSettings settings)
|
||||||
{
|
{
|
||||||
var arguments = new Dictionary<string, object>();
|
// var arguments = new Dictionary<string, object>();
|
||||||
arguments.Add("metainfo", Convert.ToBase64String(torrentData));
|
// arguments.Add("metainfo", Convert.ToBase64String(torrentData));
|
||||||
ProcessRequest<PutioGenericResponse>(Method.POST, "transfers/add", arguments, settings);
|
// ProcessRequest<PutioGenericResponse>(Method.POST, "transfers/add", arguments, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveTorrent(string hashString, PutioSettings settings)
|
public void RemoveTorrent(string hashString, PutioSettings settings)
|
||||||
{
|
{
|
||||||
var arguments = new Dictionary<string, object>();
|
// var arguments = new Dictionary<string, object>();
|
||||||
arguments.Add("transfer_ids", new string[] { hashString });
|
// arguments.Add("transfer_ids", new string[] { hashString });
|
||||||
ProcessRequest<PutioGenericResponse>(Method.POST, "torrents/cancel", arguments, settings);
|
// ProcessRequest<PutioGenericResponse>(Method.POST, "torrents/cancel", arguments, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetAccountSettings(PutioSettings settings)
|
public void GetAccountSettings(PutioSettings settings)
|
||||||
{
|
{
|
||||||
ProcessRequest<PutioGenericResponse>(Method.GET, "account/settings", null, settings);
|
// ProcessRequest<PutioGenericResponse>(Method.GET, "account/settings", null, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TResponseType ProcessRequest<TResponseType>(Method method, string resource, Dictionary<string, object> arguments, PutioSettings settings) where TResponseType : PutioGenericResponse
|
private HttpRequestBuilder BuildRequest(PutioSettings settings)
|
||||||
{
|
{
|
||||||
var client = BuildClient(settings);
|
var requestBuilder = new HttpRequestBuilder("https://api.put.io/v2")
|
||||||
|
|
||||||
var request = new RestRequest(resource, method);
|
|
||||||
request.RequestFormat = DataFormat.Json;
|
|
||||||
request.AddQueryParameter("oauth_token", settings.OAuthToken);
|
|
||||||
|
|
||||||
if (arguments != null)
|
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, object> e in arguments)
|
LogResponseContent = true
|
||||||
|
};
|
||||||
|
requestBuilder.SetHeader("Authorization", "Bearer " + settings.OAuthToken);
|
||||||
|
return requestBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string ProcessRequest(HttpRequestBuilder requestBuilder)
|
||||||
|
{
|
||||||
|
var request = requestBuilder.Build();
|
||||||
|
request.LogResponseContent = true;
|
||||||
|
request.SuppressHttpErrorStatusCodes = new[] { HttpStatusCode.Forbidden };
|
||||||
|
|
||||||
|
HttpResponse response;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
response = _httpClient.Execute(request);
|
||||||
|
|
||||||
|
if (response.StatusCode == HttpStatusCode.Forbidden)
|
||||||
{
|
{
|
||||||
request.AddParameter(e.Key, e.Value);
|
throw new DownloadClientException("Invalid credentials. Check your OAuthToken");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
_logger.Debug("Method: {0} Url: {1}", method, client.BuildUri(request));
|
|
||||||
|
|
||||||
var restResponse = client.Execute(request);
|
|
||||||
|
|
||||||
var json = new JsonDeserializer();
|
|
||||||
|
|
||||||
TResponseType output = json.Deserialize<TResponseType>(restResponse);
|
|
||||||
|
|
||||||
if (output.Status != "OK")
|
|
||||||
{
|
{
|
||||||
throw new PutioException(output.ErrorMessage);
|
throw new DownloadClientException("Failed to connect to put.io.", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return response.Content;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRestClient BuildClient(PutioSettings settings)
|
private TResult ProcessRequest<TResult>(HttpRequestBuilder requestBuilder)
|
||||||
|
where TResult : new()
|
||||||
{
|
{
|
||||||
var restClient = RestClientFactory.BuildClient(settings.Url);
|
var responseContent = ProcessRequest(requestBuilder);
|
||||||
restClient.FollowRedirects = false;
|
|
||||||
return restClient;
|
return Json.Deserialize<TResult>(responseContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download.Clients.Putio
|
namespace NzbDrone.Core.Download.Clients.Putio
|
||||||
{
|
{
|
||||||
public sealed class PutioTorrentStatus
|
public sealed class PutioTorrentStatus
|
||||||
{
|
{
|
||||||
public static readonly String Completed = "COMPLETED";
|
public static readonly string Completed = "COMPLETED";
|
||||||
public static readonly String Downloading = "DOWNLOADING";
|
public static readonly string Downloading = "DOWNLOADING";
|
||||||
public static readonly String Error = "ERROR";
|
public static readonly string Error = "ERROR";
|
||||||
public static readonly String InQueue = "IN_QUEUE";
|
public static readonly string InQueue = "IN_QUEUE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue