Skip to content

Commit 4291c88

Browse files
author
Meyn
committed
try
1 parent 318cf4b commit 4291c88

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

Tubifarry/Download/Clients/Soulseek/SlskdClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NzbDrone.Common.Extensions;
55
using NzbDrone.Common.Http;
66
using NzbDrone.Core.Configuration;
7+
using NzbDrone.Core.History;
78
using NzbDrone.Core.Indexers;
89
using NzbDrone.Core.Parser.Model;
910
using NzbDrone.Core.RemotePathMappings;
@@ -15,13 +16,15 @@ namespace NzbDrone.Core.Download.Clients.Soulseek
1516
public class SlskdClient : DownloadClientBase<SlskdProviderSettings>
1617
{
1718
private readonly IHttpClient _httpClient;
19+
private readonly IHistoryService _historyService;
20+
1821
private static readonly Dictionary<DownloadKey, SlskdDownloadItem> _downloadMappings = new();
1922

2023
public override string Name => "Slskd";
2124
public override string Protocol => nameof(SoulseekDownloadProtocol);
2225

23-
public SlskdClient(IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider, IRemotePathMappingService remotePathMappingService, Logger logger)
24-
: base(configService, diskProvider, remotePathMappingService, logger) => _httpClient = httpClient;
26+
public SlskdClient(IHttpClient httpClient, IConfigService configService, IDiskProvider diskProvider,IHistoryService history, IRemotePathMappingService remotePathMappingService, Logger logger)
27+
: base(configService, diskProvider, remotePathMappingService, logger) { _httpClient = httpClient; _historyService = history; }
2528

2629

2730
public override async Task<string> Download(RemoteAlbum remoteAlbum, IIndexer indexer)

Tubifarry/Download/Clients/Soulseek/SlskdModels.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public SlskdDownloadItem(RemoteAlbum remoteAlbum)
2222
{
2323
RemoteAlbum = remoteAlbum;
2424
FileData = JsonSerializer.Deserialize<List<SlskdFileData>>(RemoteAlbum.Release.Source) ?? new();
25-
_downloadClientItem = new() { DownloadId = ID.ToString(), CanBeRemoved = true, CanMoveFiles = true };
2625
_lastUpdateTime = DateTime.UtcNow;
2726
_lastDownloadedSize = 0;
2827
HashCode hash = new();
2928
foreach (SlskdFileData file in FileData)
3029
hash.Add(file.Filename);
3130
ID = hash.ToHashCode();
31+
_downloadClientItem = new() { DownloadId = ID.ToString(), CanBeRemoved = true, CanMoveFiles = true };
3232
}
3333

3434
public DownloadClientItem GetDownloadClientItem(string downloadPath)
@@ -38,7 +38,6 @@ public DownloadClientItem GetDownloadClientItem(string downloadPath)
3838
.TrimEnd('/')
3939
.Split('/')
4040
.LastOrDefault() ?? ""));
41-
NzbDroneLogger.GetLogger(true).Info(_downloadClientItem.OutputPath);
4241
_downloadClientItem.Title = RemoteAlbum.Release.Title;
4342

4443
if (SlskdDownloadDirectory?.Files == null)

Tubifarry/Indexers/Soulseek/SlskdRequestGenerator.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NzbDrone.Common.Instrumentation;
55
using NzbDrone.Core.IndexerSearch.Definitions;
66
using System.Net;
7+
using System.Text;
78

89
namespace NzbDrone.Core.Indexers.Soulseek
910
{
@@ -69,7 +70,12 @@ private IEnumerable<IndexerRequest> GetRequests(string artist, string? album = n
6970
_logger.Trace($"Generated search initiation request: {searchRequest.Url}");
7071

7172
HttpRequest request = new HttpRequestBuilder($"{Settings.BaseUrl}/api/v0/searches/{searchData.Id}")
72-
.AddQueryParam("includeResponses", true).SetHeader("X-API-KEY", Settings.ApiKey).SetHeader("X-ALBUM", album).SetHeader("X-ARTIST", artist).SetHeader("X-INTERACTIVE", interactive.ToString()).Build();
73+
.AddQueryParam("includeResponses", true)
74+
.SetHeader("X-API-KEY", Settings.ApiKey)
75+
.SetHeader("X-ALBUM", Convert.ToBase64String(Encoding.UTF8.GetBytes(album ?? "")))
76+
.SetHeader("X-ARTIST", Convert.ToBase64String(Encoding.UTF8.GetBytes(artist)))
77+
.SetHeader("X-INTERACTIVE", interactive.ToString())
78+
.Build();
7379
yield return new IndexerRequest(request);
7480
}
7581

@@ -88,7 +94,7 @@ private async Task WaitOnSearchCompletionAsync(string searchId, TimeSpan timeout
8894
if (elapsed > timeout && !hasTimedOut)
8995
{
9096
hasTimedOut = true;
91-
timeoutEndTime = DateTime.UtcNow.AddSeconds(8);
97+
timeoutEndTime = DateTime.UtcNow.AddSeconds(20);
9298
}
9399
else if (hasTimedOut && timeoutEndTime < DateTime.UtcNow)
94100
break;
@@ -104,10 +110,7 @@ private async Task WaitOnSearchCompletionAsync(string searchId, TimeSpan timeout
104110
double delay;
105111

106112
if (hasTimedOut && DateTime.UtcNow < timeoutEndTime)
107-
{
108-
await Task.Delay(1000);
109-
delay = 0.5;
110-
}
113+
delay = 1;
111114
else
112115
delay = CalculateQuadraticDelay(progress);
113116

Tubifarry/Indexers/Soulseek/SlskdSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class SlskdSettings : IIndexerSettings
9999
public int ResponseLimit { get; set; } = 100;
100100

101101
[FieldDefinition(11, Type = FieldType.Number, Label = "Timeout", Unit = "seconds", HelpText = "Timeout for search requests in seconds.", Advanced = true)]
102-
public double TimeoutInSeconds { get; set; } = 15;
102+
public double TimeoutInSeconds { get; set; } = 5;
103103

104104
public NzbDroneValidationResult Validate() => new(Validator.Validate(this));
105105
}

Tubifarry/Indexers/Soulseek/SoulseekModels.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.Json;
1+
using System.Text;
2+
using System.Text.Json;
23
using System.Text.RegularExpressions;
34
using Tubifarry.Core;
45

@@ -110,8 +111,9 @@ public int CalculatePriority()
110111
public record SlskdSearchData(string? Artist, string? Album)
111112
{
112113
public static SlskdSearchData ParseSearchText(IndexerRequest request) => new(
113-
Artist: request.HttpRequest.Headers.GetSingleValue("X-ARTIST"),
114-
Album: request.HttpRequest.Headers.GetSingleValue("X-ALBUM"));
114+
Artist: Encoding.UTF8.GetString(Convert.FromBase64String(request.HttpRequest.Headers["X-ARTIST"] ?? "")),
115+
Album: Encoding.UTF8.GetString(Convert.FromBase64String(request.HttpRequest.Headers["X-ALBUM"] ?? ""))
116+
);
115117
}
116118
}
117119

0 commit comments

Comments
 (0)