https://github.com/borisgerretzen/torznabclient
C# Torznab client compatible with Jackett
https://github.com/borisgerretzen/torznabclient
csharp jackett torrent torrents torznab
Last synced: 2 months ago
JSON representation
C# Torznab client compatible with Jackett
- Host: GitHub
- URL: https://github.com/borisgerretzen/torznabclient
- Owner: BorisGerretzen
- License: lgpl-3.0
- Created: 2024-03-11T12:28:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-12T22:46:51.000Z (about 1 year ago)
- Last Synced: 2025-02-07T23:49:17.705Z (4 months ago)
- Topics: csharp, jackett, torrent, torrents, torznab
- Language: C#
- Homepage:
- Size: 99.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TorznabClient
[](https://www.nuget.org/packages/TorznabClient/)
[](https://github.com/BorisGerretzen/TorznabClient/actions/workflows/test.yml)This is a C# client for the [Torznab](https://torznab.github.io/spec-1.3-draft/torznab/) protocol, it also works with [Jackett](https://github.com/Jackett/Jackett).
## Usage Jackett
You can use the `AddJackettClient` extension method to add the `IJackettClient` to the service collection.
The configuration is expected to be in the `JackettClient` section of the configuration, but you can change that by passing a `sectionName` to the `AddJackettClient` method.Additionally you can take a look at the `TorznabClient.Demo` project for a complete example.
```csharp
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using TorznabClient;var builder = Host.CreateApplicationBuilder();
// Load configuration, in this case from an in-memory collection.
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(new Dictionary
{
["JackettClient:Url"] = "http://localhost:9117/", // Note, only put the base url here.
["JackettClient:ApiKey"] = "your_api_key"
});
builder.Configuration.AddConfiguration(configurationBuilder.Build());// Add Torznab client to the service collection.
builder.Services.AddJackettClient(builder.Configuration);var host = builder.Build();
var client = host.Services.GetRequiredService();
var indexers = await client.GetIndexersAsync();Console.WriteLine(indexers);
```## Usage Torznab
You can use the `AddTorznabClient` extension method to add the `ITorznabClient` to the service collection.
The configuration is expected to be in the `TorznabClient` section of the configuration, but like in the previous section, you can change that by passing a `sectionName` to the `AddTorznabClient` method.```csharp
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using TorznabClient;var builder = Host.CreateApplicationBuilder();
// Load configuration, in this case from an in-memory collection.
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(new Dictionary
{
["TorznabClient:Url"] = "http://localhost:9117/api/v2.0/indexers/all/results/torznab",
["TorznabClient:ApiKey"] = "your_api_key"
});
builder.Configuration.AddConfiguration(configurationBuilder.Build());// Add Torznab client to the service collection.
builder.Services.AddTorznabClient(builder.Configuration);var host = builder.Build();
var client = host.Services.GetRequiredService();
var caps = await client.GetCapsAsync();Console.WriteLine(caps);
```### Customizing the client
This works for both the Jackett as well as the Torznab client.
```csharp
// Specify a custom section name.
builder.Services.AddTorznabClient(builder.Configuration, sectionName: "CustomSectionName");// Customize the HttpClient
builder.Services.AddTorznabClient(builder.Configuration, configureClient: (IServiceProvider provider, HttpClient httpClient) =>
{
httpClient.Timeout = TimeSpan.FromSeconds(10);
httpClient.DefaultRequestHeaders.Add("User-Agent", "TorznabClient.Demo");
});// Use a Polly policy
builder.Services.AddTorznabClient(builder.Configuration, configureClientBuilder: (IHttpClientBuilder clientBuilder) =>
{
clientBuilder.AddPolicyHandler(GetRetryPolicy());
});static IAsyncPolicy GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2,
retryAttempt)));
}
```