Skip to content

Commit

Permalink
NEW! Add AddTorrentByUrl()
Browse files Browse the repository at this point in the history
- TorrentExtended
- Calls
- Test
- Readme
  • Loading branch information
rafaelkan committed Oct 29, 2024
1 parent f6e920c commit d80ffb6
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 1 deletion.
19 changes: 19 additions & 0 deletions DelugeRPCClient.Net.Tests/TorrentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ public async Task ListAndGetTorrent()
Assert.IsTrue(logoutResult);
}

[TestMethod]
public async Task ListAndGetTorrentExtended()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);

List<TorrentExtended> torrents = await client.ListTorrentsExtended();
Assert.IsNotNull(torrents);
Assert.AreNotEqual(0, torrents.Count);

TorrentExtended torrent = await client.GetTorrentExtended(torrents[0].Hash);
Assert.IsNotNull(torrent);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
}

[TestMethod]
public async Task AddRemoveTorrentByMagnet()
{
Expand Down
24 changes: 24 additions & 0 deletions DelugeRPCClient.Net/DelugeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ public async Task<List<Torrent>> ListTorrents(Dictionary<string, string> filters
return result.Values.ToList();
}

/// <summary>
/// List all torrents with details optionnaly filtered
/// </summary>
/// <param name="filters">optional filters</param>
/// <returns>List of torrents</returns>
public async Task<List<TorrentExtended>> ListTorrentsExtended(Dictionary<string, string> filters = null)
{
filters = filters ?? new Dictionary<string, string>();
var keys = typeof(TorrentExtended).GetAllJsonPropertyFromType();
Dictionary<string, TorrentExtended> result = await SendRequest<Dictionary<string, TorrentExtended>>("core.get_torrents_status", filters, keys);
return result.Values.ToList();
}

/// <summary>
/// Get torrent informations by torrent hash
/// </summary>
Expand All @@ -80,6 +93,17 @@ public async Task<Torrent> GetTorrent(string hash)
return torrents.Count > 0 ? torrents[0] : null;
}

/// <summary>
/// Get torrent informations with details by torrent hash
/// </summary>
/// <param name="hash">The requested torrent hash</param>
/// <returns>the torrent object</returns>
public async Task<TorrentExtended> GetTorrentExtended(string hash)
{
List<TorrentExtended> torrents = await ListTorrentsExtended(new Dictionary<string, string>() { { "hash", hash } });
return torrents.Count > 0 ? torrents[0] : null;
}

/// <summary>
/// Add a new torrent by magnet information
/// </summary>
Expand Down
118 changes: 118 additions & 0 deletions DelugeRPCClient.Net/Models/TorrentExtended.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace DelugeRPCClient.Net.Models
{
public class TorrentExtended : Torrent
{
[JsonProperty(PropertyName = "total_done")]
public long TotalDone { get; set; }

[JsonProperty(PropertyName = "total_payload_download")]
public long TotalPayloadDownload { get; set; }

[JsonProperty(PropertyName = "total_uploaded")]
public long TotalUploaded { get; set; }

[JsonProperty(PropertyName = "next_announce")]
public int NextAnnounce { get; set; }

[JsonProperty(PropertyName = "tracker_status")]
public string TrackerStatus { get; set; }

[JsonProperty(PropertyName = "num_pieces")]
public int NumPieces { get; set; }

[JsonProperty(PropertyName = "piece_length")]
public long PieceLength { get; set; }

[JsonProperty(PropertyName = "is_auto_managed")]
public bool IsAutoManaged { get; set; }

[JsonProperty(PropertyName = "active_time")]
public long ActiveTime { get; set; }

[JsonProperty(PropertyName = "seeding_time")]
public long SeedingTime { get; set; }

[JsonProperty(PropertyName = "time_since_transfer")]
public long TimeSinceTransfer { get; set; }

[JsonProperty(PropertyName = "seed_rank")]
public int SeedRank { get; set; }

[JsonProperty(PropertyName = "last_seen_complete")]
public long LastSeenComplete { get; set; }

[JsonProperty(PropertyName = "completed_time")]
public long CompletedTime { get; set; }

[JsonProperty(PropertyName = "owner")]
public string Owner { get; set; }

[JsonProperty(PropertyName = "public")]
public bool Public { get; set; }

[JsonProperty(PropertyName = "shared")]
public bool Shared { get; set; }

[JsonProperty(PropertyName = "queue")]
public int Queue { get; set; }

[JsonProperty(PropertyName = "total_wanted")]
public long TotalWanted { get; set; }

[JsonProperty(PropertyName = "state")]
public string State { get; set; }

[JsonProperty(PropertyName = "progress")]
public float Progress { get; set; }

[JsonProperty(PropertyName = "num_seeds")]
public int NumSeeds { get; set; }

[JsonProperty(PropertyName = "total_seeds")]
public int TotalSeeds { get; set; }

[JsonProperty(PropertyName = "num_peers")]
public int NumPeers { get; set; }

[JsonProperty(PropertyName = "total_peers")]
public int TotalPeers { get; set; }

[JsonProperty(PropertyName = "download_payload_rate")]
public long DownloadPayloadRate { get; set; }

[JsonProperty(PropertyName = "upload_payload_rate")]
public long UploadPayloadRate { get; set; }

[JsonProperty(PropertyName = "eta")]
public long Eta { get; set; }

[JsonProperty(PropertyName = "distributed_copies")]
public float DistributedCopies { get; set; }

[JsonProperty(PropertyName = "time_added")]
public int TimeAdded { get; set; }

[JsonProperty(PropertyName = "tracker_host")]
public string TrackerHost { get; set; }

[JsonProperty(PropertyName = "download_location")]
public string DownloadLocation { get; set; }

[JsonProperty(PropertyName = "total_remaining")]
public long TotalRemaining { get; set; }

[JsonProperty(PropertyName = "max_download_speed")]
public long MaxDownloadSpeed { get; set; }

[JsonProperty(PropertyName = "max_upload_speed")]
public long MaxUploadSpeed { get; set; }

[JsonProperty(PropertyName = "seeds_peers_ratio")]
public float SeedsPeersRatio { get; set; }
}
}
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,21 @@ List torrents
List<Torrent> torrents = await client.ListTorrents();
```

List torrents extended
```C#
List<TorrentExtended> torrents = await client.ListTorrentsExtended();
```

Get torrent by hash
```C#
Torrent torrent = await client.GetTorrent(torrentHash);
```

Get torrent extended by hash
```C#
TorrentExtended torrent = await client.GetTorrentExtended(torrentHash);
```

#### Add Torrent

Add a torrent by magnet uri
Expand All @@ -62,7 +72,6 @@ Add a torrent by .torrent file
```C#
Torrent torrent = await client.AddTorrentByFile(torrentFilename);
```
```

Add a torrent by .torrent url
```C#
Expand Down

0 comments on commit d80ffb6

Please sign in to comment.