1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2025-03-12 07:07:47 +00:00

Remove parsing of infohash trough InfoHash

Corrections after inspection.
This commit is contained in:
Jesper Utoft 2024-08-22 08:14:57 +02:00
parent d646af2f88
commit 054c04aae8
2 changed files with 7 additions and 19 deletions

View file

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using MonoTorrent;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
@ -66,7 +65,7 @@ namespace NzbDrone.Core.Download.Clients.Tribler
var item = new DownloadClientItem
{
DownloadId = InfoHash.FromHex(download.Infohash).ToHex(),
DownloadId = download.Infohash,
Title = download.Name,
DownloadClientInfo = DownloadClientItemClientInfo.FromDownloadClient(this, false) // TODO: WHAT IS POST-IMPORT
@ -152,7 +151,7 @@ namespace NzbDrone.Core.Download.Clients.Tribler
break;
}
// override status' if completed but progress is not finished
// Override status if completed, but not finished downloading
if (download.Status == DownloadStatus.Stopped && download.Progress < 1)
{
item.Status = DownloadItemStatus.Paused;
@ -162,6 +161,7 @@ namespace NzbDrone.Core.Download.Clients.Tribler
if (download.Error != null && download.Error.Length > 0)
{
item.Status = DownloadItemStatus.Warning; // maybe this should be an error?
item.Message = download.Error;
}
// done (finished seeding & stopped, guessed)
@ -302,7 +302,7 @@ namespace NzbDrone.Core.Download.Clients.Tribler
{
_logger.Error(ex, ex.Message);
return new ValidationFailure("APIKey", _localizationService.GetLocalizedString("DownloadClientValidationApiKeyIncorrect"));
return new ValidationFailure("ApiKey", _localizationService.GetLocalizedString("DownloadClientValidationApiKeyIncorrect"));
}
catch (DownloadClientUnavailableException ex)
{

View file

@ -9,13 +9,9 @@ namespace NzbDrone.Core.Download.Clients.Tribler
public interface ITriblerDownloadClientProxy
{
ICollection<Download> GetDownloads(TriblerDownloadSettings settings);
ICollection<File> GetDownloadFiles(TriblerDownloadSettings settings, Download downloadItem);
GetTriblerSettingsResponse GetConfig(TriblerDownloadSettings settings);
void RemoveDownload(TriblerDownloadSettings settings, DownloadClientItem item, bool deleteData);
string AddFromMagnetLink(TriblerDownloadSettings settings, AddDownloadRequest downloadRequest);
}
@ -61,13 +57,12 @@ namespace NzbDrone.Core.Download.Clients.Tribler
{
var httpRequest = requestBuilder;
HttpResponse response;
_logger.Debug("Url: {0}", httpRequest.Url);
try
{
response = _httpClient.Execute(httpRequest);
var response = _httpClient.Execute(httpRequest);
return Json.Deserialize<T>(response.Content);
}
catch (HttpException ex)
{
@ -79,7 +74,6 @@ namespace NzbDrone.Core.Download.Clients.Tribler
throw new DownloadClientUnavailableException("Unable to connect to Tribler. Status Code: {0}", ex.Response.StatusCode, ex);
}
return Json.Deserialize<T>(response.Content);
}
public GetTriblerSettingsResponse GetConfig(TriblerDownloadSettings settings)
@ -111,7 +105,6 @@ namespace NzbDrone.Core.Download.Clients.Tribler
var deleteRequestBuilder = getRequestBuilder(settings, "downloads/" + item.DownloadId.ToLower());
deleteRequestBuilder.Method = System.Net.Http.HttpMethod.Delete;
// manually set content of delete request.
var deleteRequest = deleteRequestBuilder.Build();
deleteRequest.SetContent(Json.ToJson(deleteDownloadRequestObject));
@ -123,15 +116,10 @@ namespace NzbDrone.Core.Download.Clients.Tribler
var addDownloadRequestBuilder = getRequestBuilder(settings, "downloads");
addDownloadRequestBuilder.Method = System.Net.Http.HttpMethod.Put;
// manually set content of download request.
var addDownloadRequest = addDownloadRequestBuilder.Build();
addDownloadRequest.SetContent(Json.ToJson(downloadRequest));
var infoHashAsString = ProcessRequest<AddDownloadResponse>(addDownloadRequest).Infohash;
// run hash through InfoHash class to ensure the correct casing.
var infoHash = MonoTorrent.InfoHash.FromHex(infoHashAsString);
return infoHash.ToHex();
return ProcessRequest<AddDownloadResponse>(addDownloadRequest).Infohash;
}
}
}