A Lazarus component to access the qBitTorrent Web UI
Documentation on v2.6.0: https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)
This component depends on the Ararat Synapse Network Lib.
You can get it from one of these options:
- The main page of the author: http://synapse.ararat.cz/doku.php/download
- From Source Forge: https://sourceforge.net/projects/synalist/
- If you are using the Online Package Manager that comes with Lazarus, it's listed with 2 versions:
- Version 40.
- Version 40.1.
I'm using the Online Package Manager and I'm testing this with version 40.1 of the Synapse Network lib.
The package itself has a dependency on laz_synapse
.
Since I'm building and testing this with GitHub Actions I'm usin the setup-lazarus action to setup the environment with all the necessary packages.
Retrieves the torrent list.
uses
qBitTorrentWebUI;
type
TForm1 = class(TForm)
{...}
Fqb: TqBitTorrentWebUI;
{...}
public
{...}
procedure GetTorrentsExecute(Sender: TObject);
{...}
end;
var
Form1: TForm1;
implementation
prodecure TForm1.GetTorrentsExecute(Sender: TObject);
begin
try
Fqb.Active := True;
if Fqb.GetTorrents then
begin
// Do something after a successfull torrents retrival
end;
except
on E:Exception do
begin
// If torrents retrieval fails it will raise an exception
end;
Fqb.Active := False;
end;
end;
Retrieves the properties for a torrent
uses
qBitTorrentWebUI;
type
TForm1 = class(TForm)
{...}
Fqb: TqBitTorrentWebUI;
{...}
public
{...}
procedure GetTorrentPropertiesExecute(Sender: TObject);
{...}
end;
var
Form1: TForm1;
implementation
prodecure TForm1.GetTorrentPropertiesExecute(Sender: TObject);
var
oFilter: TqBTorrentsFilter;
begin
try
try
Fqb.Active := True;
oFilter := TqBTorrentsFilter.Create;
try
oFilter
.withFilter('all')
.withSort('priority')
.withLimit(10);
if Fqb.GetTorrentsFiltered(oFilter) then
begin
if Fqb.Items.Count > 0 then
begin
if Fqb.GetTorrentProperties(Fqb[0].Hash) then
begin
// Do something after a successfull torrent's properties retrieval
end;
end;
end;
finally
oFilter.Free;
end;
except
on E:Exception do
begin
// If torrents retrieval fails it will raise an exception
end;
end;
finally
Fqb.Active := False;
end;
end;
Retrieves the trackers for a torrent
uses
qBitTorrentWebUI;
type
TForm1 = class(TForm)
{...}
Fqb: TqBitTorrentWebUI;
{...}
public
{...}
procedure GetTorrentTrackersExecute(Sender: TObject);
{...}
end;
var
Form1: TForm1;
implementation
prodecure TForm1.GetTorrentTrackersExecute(Sender: TObject);
var
oFilter: TqBTorrentsFilter;
begin
try
try
Fqb.Active := True;
oFilter := TqBTorrentsFilter.Create;
try
oFilter
.withFilter('all')
.withSort('priority')
.withLimit(10);
if Fqb.GetTorrentsFiltered(oFilter) then
begin
if Fqb.Items.Count > 0 then
begin
if Fqb.GetTorrentTrackers(Fqb[0].Hash) then
begin
// Do something after a successfull torrent's trackers retrieval
end;
end;
end;
finally
oFilter.Free;
end;
except
on E:Exception do
begin
// If torrents retrieval fails it will raise an exception
end;
end;
finally
Fqb.Active := False;
end;
end;
Retrieves the web seeds for a torrent
uses
qBitTorrentWebUI;
type
TForm1 = class(TForm)
{...}
Fqb: TqBitTorrentWebUI;
{...}
public
{...}
procedure GetTorrentWebSeedsExecute(Sender: TObject);
{...}
end;
var
Form1: TForm1;
implementation
prodecure TForm1.GetTorrentWebSeedsExecute(Sender: TObject);
var
oFilter: TqBTorrentsFilter;
begin
try
try
Fqb.Active := True;
oFilter := TqBTorrentsFilter.Create;
try
oFilter
.withFilter('all')
.withSort('priority')
.withLimit(10);
if Fqb.GetTorrentsFiltered(oFilter) then
begin
if Fqb.Items.Count > 0 then
begin
if Fqb.GetTorrentWebSeeds(Fqb[0].Hash) then
begin
// Do something after a successfull torrent's trackers retrieval
end;
end;
end;
finally
oFilter.Free;
end;
except
on E:Exception do
begin
// If torrents retrieval fails it will raise an exception
end;
end;
finally
Fqb.Active := False;
end;
end;
Retrieves the files for a torrent
uses
qBitTorrentWebUI;
type
TForm1 = class(TForm)
{...}
Fqb: TqBitTorrentWebUI;
{...}
public
{...}
procedure GetTorrentFilesExecute(Sender: TObject);
{...}
end;
var
Form1: TForm1;
implementation
prodecure TForm1.GetTorrentFilesExecute(Sender: TObject);
var
oFilter: TqBTorrentsFilter;
begin
try
try
Fqb.Active := True;
oFilter := TqBTorrentsFilter.Create;
try
oFilter
.withFilter('all')
.withSort('priority')
.withLimit(10);
if Fqb.GetTorrentsFiltered(oFilter) then
begin
if Fqb.Items.Count > 0 then
begin
if Fqb.GetTorrentFiles(Fqb[0].Hash) then
begin
// Do something after a successfull torrent's files retrieval
end;
end;
end;
finally
oFilter.Free;
end;
except
on E:Exception do
begin
// If torrents retrieval fails it will raise an exception
end;
end;
finally
Fqb.Active := False;
end;
end;
This send a command to shutdown(close) the qBitTorrent client.
It also sets Active
to False
.
uses
qBitTorrentWebUI;
type
TForm1 = class(TForm)
{...}
Fqb: TqBitTorrentWebUI;
{...}
public
{...}
procedure ExecShutdownExecute(Sender: TObject);
{...}
end;
var
Form1: TForm1;
implementation
prodecure TForm1.ExecShutdownExecute(Sender: TObject);
begin
try
Fqb.Active := True;
if Fqb.ExecShutdown then
begin
// Do something after a successfull shutdown
end;
except
on E:Exception do
begin
// If shutdown fails it will raise an exception
end;
Fqb.Active := False;
end;
end;