Add qBittorrent endpoint transfer/info.
This commit is contained in:
parent
3ed80909de
commit
ce223d3e2c
4 changed files with 103 additions and 16 deletions
30
server/RdtClient.Data/Models/QBittorrent/TransferInfo.cs
Normal file
30
server/RdtClient.Data/Models/QBittorrent/TransferInfo.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace RdtClient.Data.Models.QBittorrent;
|
||||||
|
|
||||||
|
public class TransferInfo
|
||||||
|
{
|
||||||
|
[JsonPropertyName("connection_status")]
|
||||||
|
public String ConnectionStatus { get; set; } = default!;
|
||||||
|
|
||||||
|
[JsonPropertyName("dht_nodes")]
|
||||||
|
public Int64 DhtNodes { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("dl_info_data")]
|
||||||
|
public Int64 DlInfoData { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("dl_info_speed")]
|
||||||
|
public Int64 DlInfoSpeed { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("dl_rate_limit")]
|
||||||
|
public Int64 DlRateLimit { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("up_info_data")]
|
||||||
|
public Int64 UpInfoData { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("up_info_speed")]
|
||||||
|
public Int64 UpInfoSpeed { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("up_rate_limit")]
|
||||||
|
public Int64 UpRateLimit { get; set; }
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,9 @@ namespace RdtClient.Service.Services;
|
||||||
|
|
||||||
public class DownloadClient(Download download, Torrent torrent, String destinationPath, String? category)
|
public class DownloadClient(Download download, Torrent torrent, String destinationPath, String? category)
|
||||||
{
|
{
|
||||||
|
private static Int64 _totalBytesDownloadedThisSession;
|
||||||
|
private static readonly Lock TotalBytesDownloadedLock = new();
|
||||||
|
|
||||||
public IDownloader? Downloader;
|
public IDownloader? Downloader;
|
||||||
|
|
||||||
public Data.Enums.DownloadClient Type { get; private set; }
|
public Data.Enums.DownloadClient Type { get; private set; }
|
||||||
|
|
@ -18,6 +21,8 @@ public class DownloadClient(Download download, Torrent torrent, String destinati
|
||||||
public Int64 BytesTotal { get; private set; }
|
public Int64 BytesTotal { get; private set; }
|
||||||
public Int64 BytesDone { get; private set; }
|
public Int64 BytesDone { get; private set; }
|
||||||
|
|
||||||
|
private Int64 LastBytesDone { get; set; }
|
||||||
|
|
||||||
public async Task<String> Start()
|
public async Task<String> Start()
|
||||||
{
|
{
|
||||||
BytesDone = 0;
|
BytesDone = 0;
|
||||||
|
|
@ -66,6 +71,12 @@ public class DownloadClient(Download download, Torrent torrent, String destinati
|
||||||
Speed = args.Speed;
|
Speed = args.Speed;
|
||||||
BytesDone = args.BytesDone;
|
BytesDone = args.BytesDone;
|
||||||
BytesTotal = args.BytesTotal;
|
BytesTotal = args.BytesTotal;
|
||||||
|
|
||||||
|
var bytesAdded = BytesDone - LastBytesDone;
|
||||||
|
|
||||||
|
LastBytesDone = BytesDone;
|
||||||
|
|
||||||
|
AddToTotalBytesDownloadedThisSession(bytesAdded);
|
||||||
};
|
};
|
||||||
|
|
||||||
var result = await Downloader.Download();
|
var result = await Downloader.Download();
|
||||||
|
|
@ -114,4 +125,20 @@ public class DownloadClient(Download download, Torrent torrent, String destinati
|
||||||
}
|
}
|
||||||
await Downloader.Resume();
|
await Downloader.Resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Int64 GetTotalBytesDownloadedThisSession()
|
||||||
|
{
|
||||||
|
lock (TotalBytesDownloadedLock)
|
||||||
|
{
|
||||||
|
return _totalBytesDownloadedThisSession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddToTotalBytesDownloadedThisSession(Int64 bytes)
|
||||||
|
{
|
||||||
|
lock (TotalBytesDownloadedLock)
|
||||||
|
{
|
||||||
|
_totalBytesDownloadedThisSession += bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -636,7 +636,7 @@ public class QBittorrent(ILogger<QBittorrent> logger, Settings settings, Authent
|
||||||
|
|
||||||
public async Task<SyncMetaData> SyncMainData()
|
public async Task<SyncMetaData> SyncMainData()
|
||||||
{
|
{
|
||||||
var torrents = await TorrentInfo();
|
var torrentInfo = await TorrentInfo();
|
||||||
|
|
||||||
var categories = await TorrentsCategories();
|
var categories = await TorrentsCategories();
|
||||||
|
|
||||||
|
|
@ -649,7 +649,7 @@ public class QBittorrent(ILogger<QBittorrent> logger, Settings settings, Authent
|
||||||
Rid = 0,
|
Rid = 0,
|
||||||
Tags = null,
|
Tags = null,
|
||||||
Trackers = new Dictionary<String, List<String>>(),
|
Trackers = new Dictionary<String, List<String>>(),
|
||||||
Torrents = torrents.ToDictionary(m => m.Hash, m => m),
|
Torrents = torrentInfo.ToDictionary(m => m.Hash, m => m),
|
||||||
ServerState = new()
|
ServerState = new()
|
||||||
{
|
{
|
||||||
DlInfoSpeed = activeDownloads,
|
DlInfoSpeed = activeDownloads,
|
||||||
|
|
@ -657,4 +657,17 @@ public class QBittorrent(ILogger<QBittorrent> logger, Settings settings, Authent
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TransferInfo TransferInfo()
|
||||||
|
{
|
||||||
|
var activeDownloads = TorrentRunner.ActiveDownloadClients.Sum(m => m.Value.Speed);
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
ConnectionStatus = "connected",
|
||||||
|
DlInfoData = DownloadClient.GetTotalBytesDownloadedThisSession(),
|
||||||
|
DlInfoSpeed = activeDownloads,
|
||||||
|
DlRateLimit = Settings.Get.DownloadClient.MaxSpeed
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -322,21 +322,22 @@ public class QBittorrentController(ILogger<QBittorrentController> logger, QBitto
|
||||||
|
|
||||||
foreach (var url in urls)
|
foreach (var url in urls)
|
||||||
{
|
{
|
||||||
try{
|
try
|
||||||
if (url.StartsWith("magnet"))
|
|
||||||
{
|
{
|
||||||
await qBittorrent.TorrentsAddMagnet(url.Trim(), request.Category, null);
|
if (url.StartsWith("magnet"))
|
||||||
}
|
{
|
||||||
else if (url.StartsWith("http"))
|
await qBittorrent.TorrentsAddMagnet(url.Trim(), request.Category, null);
|
||||||
{
|
}
|
||||||
var httpClient = new HttpClient();
|
else if (url.StartsWith("http"))
|
||||||
var result = await httpClient.GetByteArrayAsync(url);
|
{
|
||||||
await qBittorrent.TorrentsAddFile(result, request.Category, null);
|
var httpClient = new HttpClient();
|
||||||
}
|
var result = await httpClient.GetByteArrayAsync(url);
|
||||||
else
|
await qBittorrent.TorrentsAddFile(result, request.Category, null);
|
||||||
{
|
}
|
||||||
return BadRequest($"Invalid torrent link format {url}");
|
else
|
||||||
}
|
{
|
||||||
|
return BadRequest($"Invalid torrent link format {url}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (RDNET.RealDebridException ex)
|
catch (RDNET.RealDebridException ex)
|
||||||
{
|
{
|
||||||
|
|
@ -507,6 +508,22 @@ public class QBittorrentController(ILogger<QBittorrentController> logger, QBitto
|
||||||
{
|
{
|
||||||
return await SyncMainData();
|
return await SyncMainData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize(Policy = "AuthSetting")]
|
||||||
|
[Route("transfer/info")]
|
||||||
|
[HttpGet]
|
||||||
|
public ActionResult TransferInfo()
|
||||||
|
{
|
||||||
|
return Ok(QBittorrent.TransferInfo());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Authorize(Policy = "AuthSetting")]
|
||||||
|
[Route("transfer/info")]
|
||||||
|
[HttpPost]
|
||||||
|
public ActionResult TransferInfoPost()
|
||||||
|
{
|
||||||
|
return TransferInfo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QBAuthLoginRequest
|
public class QBAuthLoginRequest
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue