More changes to add Torrents automatically; Modified cache to 8 days; Modified season finale lookups for edge case

This commit is contained in:
2026-10-24 14:37:51 -04:00
parent 32aca8b197
commit dcadf31192
5 changed files with 164 additions and 4 deletions
@@ -0,0 +1,57 @@
using Transmission.API.RPC;
using Transmission.API.RPC.Arguments;
using Transmission.API.RPC.Entity;
namespace AnimeAnnouncer.Torrents
{
/// <summary>
/// Thin wrapper around the Transmission RPC client for adding torrents to the server.
/// </summary>
public class TransmissionService
{
public Client Client { get; }
private TransmissionService(Client client)
{
Client = client;
}
/// <summary>
/// Creates a client and verifies the server is reachable by requesting session information.
/// Throws <see cref="InvalidOperationException"/> if the server doesn't respond with a valid session.
/// </summary>
public static async Task<TransmissionService> ConnectAsync(String host, String? username, String? password)
{
var client = new Client(host, null, username, password);
var sessionInformation = await client.GetSessionInformationAsync();
if (sessionInformation == null || String.IsNullOrEmpty(sessionInformation.Version))
throw new InvalidOperationException($"An error occurred while receiving session information from the rpc server at {host}");
return new TransmissionService(client);
}
/// <summary>
/// Adds a .torrent file to the server, saving to <paramref name="saveLocation"/>, and applies a seed ratio limit.
/// </summary>
public async Task<NewTorrentInfo> AddNewTorrentFileToServerAsync(byte[] torrentFileData, String saveLocation, bool paused = true, double seedRatioLimit = 1.0)
{
NewTorrent newTorrent = new()
{
DownloadDirectory = saveLocation,
Paused = paused,
Metainfo = Convert.ToBase64String(torrentFileData)
};
var torrentInfo = await Client.TorrentAddAsync(newTorrent);
var seedSettings = new TorrentSettings()
{
SeedRatioLimit = seedRatioLimit,
SeedRatioMode = 1,
IDs = [torrentInfo.ID]
};
// TorrentSetAsync returns void in Transmission.API.RPC 2.1.2, so it can't be awaited
Client.TorrentSet(seedSettings);
return torrentInfo;
}
}
}