qbittorrent_api
Dart wrapper for qBittorrent Web API.
Overview
This package provides a Dart wrapper for qBittorrent Web API.
To use this package, you will need a qBittorrent server running with the Web API enabled.
Web API Version
Supported Web API version: qBittorrent v4.1+
Setup
Create a QBittorrentApiV2
instance by providing the URL of your qBittorrent server.
final qbittorrent = QBittorrentApiV2(
baseUrl: 'http://localhost:8080',
cookiesStrategy: const DiskCookiesStrategy(directory: '.cookies'),
logger: true,
);
Cookies Strategy
InMemoryCookiesStrategy
: Stores cookies in memory. (Default)DiskCookiesStrategy
: Stores cookies in files on disk.WebCookiesStrategy
: Dummy strategy for not managing cookies (for Flutter Web).
For Flutter Web Application
- set
cookiesStrategy
toWebCookiesStrategy
as cookies are managed by the browser.
final qbittorrent = QBittorrentApiV2(
baseUrl: 'http://localhost:8080',
cookiesStrategy: UniversalPlatform.isWeb ? const WebCookiesStrategy() : const InMemoryCookiesStrategy(),
logger: kDebugMode,
);
Basic Usage
This package provides methods to interact with various API endpoints. Belows are some of the examples.
To see all available methods, check out qBittorrent WebUI API Documentation.
Login
await qbittorent.auth.login(username: 'username', password: 'password');
Add New Torrent
// Add torrents by urls.
final torrents = NewTorrents.urls(urls: ['https://example.torrent', 'https://example-2.torrent']);
await qbittorrent.torrents.addNewTorrents(torrents: torrents);
// Add torrents by files.
final torrents = NewTorrents.files(files: [File('./example.torrent')]);
await qbittorrent.torrents.addNewTorrents(torrents: torrents);
// Add torrent by bytes.
final newTorrents = NewTorrents.bytes(bytes: [FileBytes(filename: 'example.torrent', bytes: bytes)]);
await qbittorrent.torrents.addNewTorrents(torrents: torrents);
Subscribe to Torrent List
const interval = Duration(seconds: 3); // Refresh interval
final stream = qbittorrent.sync.subscribeMainData(interval: interval).listen((data) {
// Handle main data update
});
Subscribe to Torrent Properties
const hash = "123123"; // Torrent hash
const interval = Duration(seconds: 3); // Refresh interval
final stream = qbittorrent.torrents.subscribeProperties(hash: hash, interval: interval).listen((data) {
// Handle torrent properties update
});
Having Bugs?
- This package is under active development. If you find any bug, please create an issue on Github.