Add QBittorrent API sync/maindata endpoint for home assistant integration.
This commit is contained in:
parent
aae367d673
commit
f75ac43e49
5 changed files with 157 additions and 9 deletions
14
client/package-lock.json
generated
14
client/package-lock.json
generated
|
|
@ -35,7 +35,7 @@
|
|||
"@angular/language-service": "~13.2.6",
|
||||
"@types/file-saver": "^2.0.5",
|
||||
"@types/node": "^17.0.21",
|
||||
"typescript": "~4.6.2"
|
||||
"typescript": "~4.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
|
|
@ -10290,9 +10290,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz",
|
||||
"integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==",
|
||||
"version": "4.5.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz",
|
||||
"integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
|
@ -18520,9 +18520,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz",
|
||||
"integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==",
|
||||
"version": "4.5.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz",
|
||||
"integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==",
|
||||
"dev": true
|
||||
},
|
||||
"unicode-canonical-property-names-ecmascript": {
|
||||
|
|
|
|||
106
server/RdtClient.Data/Models/QBittorrent/SyncMetaData.cs
Normal file
106
server/RdtClient.Data/Models/QBittorrent/SyncMetaData.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using RdtClient.Data.Models.QBittorrent.QuickType;
|
||||
|
||||
namespace RdtClient.Data.Models.QBittorrent
|
||||
{
|
||||
public class SyncMetaData
|
||||
{
|
||||
[JsonPropertyName("categories")]
|
||||
public IDictionary<String, TorrentCategory> Categories { get; set; }
|
||||
|
||||
[JsonPropertyName("full_update")]
|
||||
public Boolean FullUpdate { get; set; }
|
||||
|
||||
[JsonPropertyName("rid")]
|
||||
public Int64 Rid { get; set; }
|
||||
|
||||
[JsonPropertyName("server_state")]
|
||||
public SyncMetaDataServerState ServerState { get; set; }
|
||||
|
||||
[JsonPropertyName("tags")]
|
||||
public IList<Object> Tags { get; set; }
|
||||
|
||||
[JsonPropertyName("torrents")]
|
||||
public IDictionary<String, TorrentInfo> Torrents { get; set; }
|
||||
|
||||
[JsonPropertyName("trackers")]
|
||||
public IDictionary<String, List<String>> Trackers { get; set; }
|
||||
}
|
||||
|
||||
public class SyncMetaDataServerState
|
||||
{
|
||||
[JsonPropertyName("alltime_dl")]
|
||||
public Int64 AlltimeDl { get; set; }
|
||||
|
||||
[JsonPropertyName("alltime_ul")]
|
||||
public Int64 AlltimeUl { get; set; }
|
||||
|
||||
[JsonPropertyName("average_time_queue")]
|
||||
public Int64 AverageTimeQueue { get; set; }
|
||||
|
||||
[JsonPropertyName("connection_status")]
|
||||
public String ConnectionStatus { get; set; }
|
||||
|
||||
[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("free_space_on_disk")]
|
||||
public Int64 FreeSpaceOnDisk { get; set; }
|
||||
|
||||
[JsonPropertyName("global_ratio")]
|
||||
public String GlobalRatio { get; set; }
|
||||
|
||||
[JsonPropertyName("queued_io_jobs")]
|
||||
public Int64 QueuedIoJobs { get; set; }
|
||||
|
||||
[JsonPropertyName("queueing")]
|
||||
public Boolean Queueing { get; set; }
|
||||
|
||||
[JsonPropertyName("read_cache_hits")]
|
||||
public String ReadCacheHits { get; set; }
|
||||
|
||||
[JsonPropertyName("read_cache_overload")]
|
||||
public String ReadCacheOverload { get; set; }
|
||||
|
||||
[JsonPropertyName("refresh_interval")]
|
||||
public Int64 RefreshInterval { get; set; }
|
||||
|
||||
[JsonPropertyName("total_buffers_size")]
|
||||
public Int64 TotalBuffersSize { get; set; }
|
||||
|
||||
[JsonPropertyName("total_peer_connections")]
|
||||
public Int64 TotalPeerConnections { get; set; }
|
||||
|
||||
[JsonPropertyName("total_queued_size")]
|
||||
public Int64 TotalQueuedSize { get; set; }
|
||||
|
||||
[JsonPropertyName("total_wasted_session")]
|
||||
public Int64 TotalWastedSession { 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; }
|
||||
|
||||
[JsonPropertyName("use_alt_speed_limits")]
|
||||
public Boolean UseAltSpeedLimits { get; set; }
|
||||
|
||||
[JsonPropertyName("write_cache_overload")]
|
||||
public String WriteCacheOverload { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -497,7 +497,7 @@ namespace RdtClient.Service.Services
|
|||
m => new TorrentCategory
|
||||
{
|
||||
Name = m,
|
||||
SavePath = ""
|
||||
SavePath = Path.Combine(AppDefaultSavePath(), m)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -594,5 +594,29 @@ namespace RdtClient.Service.Services
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<SyncMetaData> SyncMainData()
|
||||
{
|
||||
var torrents = await TorrentInfo();
|
||||
|
||||
var categories = await TorrentsCategories();
|
||||
|
||||
var activeDownloads = TorrentRunner.ActiveDownloadClients.Sum(m => m.Value.Speed);
|
||||
|
||||
return new SyncMetaData
|
||||
{
|
||||
Categories = categories,
|
||||
FullUpdate = true,
|
||||
Rid = 0,
|
||||
Tags = null,
|
||||
Trackers = new Dictionary<String, List<String>>(),
|
||||
Torrents = torrents.ToDictionary(m => m.Hash, m => m),
|
||||
ServerState = new SyncMetaDataServerState
|
||||
{
|
||||
DlInfoSpeed = activeDownloads,
|
||||
UpInfoSpeed = 0
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -272,7 +272,7 @@ namespace RdtClient.Service.Services
|
|||
}
|
||||
}
|
||||
|
||||
if (deleteLocalFiles)
|
||||
if (deleteLocalFiles && !String.IsNullOrWhiteSpace(torrent.RdName))
|
||||
{
|
||||
var downloadPath = DownloadPath(torrent);
|
||||
downloadPath = Path.Combine(downloadPath, torrent.RdName);
|
||||
|
|
|
|||
|
|
@ -421,6 +421,24 @@ namespace RdtClient.Web.Controllers
|
|||
{
|
||||
return await TorrentsTopPrio(request);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[Route("sync/maindata")]
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> SyncMainData()
|
||||
{
|
||||
var result = await _qBittorrent.SyncMainData();
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[Route("sync/maindata")]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> SyncMainDataPost()
|
||||
{
|
||||
return await SyncMainData();
|
||||
}
|
||||
}
|
||||
|
||||
public class QBAuthLoginRequest
|
||||
|
|
|
|||
Loading…
Reference in a new issue