QBittorrentClient

class QBittorrentClient(baseUrl: String, username: String = "admin", password: String = "adminadmin", syncInterval: Duration = 5.seconds, httpClient: HttpClient = HttpClient(), dispatcher: CoroutineDispatcher = Default)

qBittorrent Web API wrapper.

https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)

Parameters

baseUrl

The base URL of qBittorrent, ex. http://localhost:9000

username

The qBittorrent username, default: admin

password

The qBittorrent password, default: adminadmin

syncInterval

The sync endpoint polling rate when subscribed to a Flow, defaults to 5 seconds.

httpClient

Custom HTTPClient, useful when a default client engine is not used

dispatcher

Coroutine dispatcher for flow API processing, defaults to Dispatchers.Default.

Constructors

Link copied to clipboard
fun QBittorrentClient(baseUrl: String, username: String = "admin", password: String = "adminadmin", syncInterval: Duration = 5.seconds, httpClient: HttpClient = HttpClient(), dispatcher: CoroutineDispatcher = Default)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun addPeers(hashes: List<String>, peers: List<String>)
Link copied to clipboard
suspend fun addTorrent(configure: AddTorrentBody.() -> Unit)

This method can add torrents from server local file or from URLs. http://, https://, magnet: and bc://bt/ links are supported.

Link copied to clipboard
suspend fun addTorrentTags(hashes: List<String> = allList, tags: List<String>)
Link copied to clipboard
suspend fun addTrackers(hash: String, urls: List<String>)
Link copied to clipboard
suspend fun banPeers(peers: List<String>)
Link copied to clipboard
suspend fun createCategory(name: String, savePath: String)
Link copied to clipboard
suspend fun createTags(tags: List<String>)
Link copied to clipboard
suspend fun decreasePriority(hashes: List<String> = allList)
Link copied to clipboard
suspend fun deleteTags(tags: List<String>)
Link copied to clipboard
suspend fun deleteTorrents(hashes: List<String>, deleteFiles: Boolean = false)

Delete one or more torrents.

Link copied to clipboard
suspend fun editCategory(name: String, savePath: String)
Link copied to clipboard
suspend fun editTrackers(hash: String, originalUrl: String, newUrl: String)
Link copied to clipboard
suspend fun getApiVersion(): String

Get the Web API version.

Link copied to clipboard
suspend fun getBuildInfo(): BuildInfo

Get the build info

Link copied to clipboard
suspend fun getCategories(): List<Category>
Link copied to clipboard
suspend fun getDefaultSavePath(): String

Get the default torrent save path, ex. /user/home/downloads

Link copied to clipboard

The response is the value of current global download speed limit in bytes/second; this value will be zero if no limit is applied.

Link copied to clipboard
Link copied to clipboard
suspend fun getGlobalUploadLimit(): Int

The response is the value of current global upload speed limit in bytes/second; this value will be zero if no limit is applied.

Link copied to clipboard
suspend fun getLogs(normal: Boolean = true, info: Boolean = true, warning: Boolean = true, critical: Boolean = true, lastKnownId: Int = -1): List<LogEntry>
Link copied to clipboard
suspend fun getPeerLogs(lastKnownId: Int = -1): List<PeerLog>
Link copied to clipboard
suspend fun getPieceHashes(hash: String): List<String>

Get piece hashes for the torrent at hash.

Link copied to clipboard
suspend fun getPieceStates(hash: String): List<PieceState>

Get piece states for the torrent at hash.

Link copied to clipboard
suspend fun getPreferences(): JsonObject

Get the qBittorrent application preferences.

Link copied to clipboard
suspend fun getSpeedLimitsMode(): Int

The response is 1 if alternative speed limits are enabled, 0 otherwise.

Link copied to clipboard
suspend fun getTags(): List<String>
Link copied to clipboard
suspend fun getTorrentDownloadLimit(hashes: List<String> = allList): Map<String, Long>
Link copied to clipboard
suspend fun getTorrentFiles(hash: String, indexes: List<Int> = emptyList()): List<TorrentFile>

Get the TorrentFiles for hash or an empty list if not yet not available.

Link copied to clipboard
Link copied to clipboard
suspend fun getTorrents(filter: TorrentFilter = TorrentFilter.ALL, category: String = "", sort: String = "", reverse: Boolean = false, limit: Int = 0, offset: Int = 0, tag: String? = null, hashes: List<String> = emptyList()): List<Torrent>
Link copied to clipboard
suspend fun getTorrentUploadLimit(hashes: List<String> = allList): Map<String, Long>
Link copied to clipboard
suspend fun getTrackers(hash: String): List<TorrentTracker>?
Link copied to clipboard
suspend fun getVersion(): String

Get the application version.

Link copied to clipboard
suspend fun getWebseeds(hash: String): List<Webseed>
Link copied to clipboard
suspend fun increasePriority(hashes: List<String> = allList)
Link copied to clipboard
suspend fun login()

Create a session with the username and password provided in the constructor.

Link copied to clipboard
suspend fun logout()

End the current session.

Link copied to clipboard
suspend fun maxPriority(hashes: List<String> = allList)
Link copied to clipboard
suspend fun minPriority(hashes: List<String> = allList)
Link copied to clipboard

Emits the next MainData every syncInterval while subscribed.

Link copied to clipboard
fun observeTorrent(hash: String, waitIfMissing: Boolean = false): Flow<Torrent>

Emits the latest Torrent data for the hash. If the torrent is removed or not found, the flow will complete unless waitIfMissing is true.

Link copied to clipboard

Emits the latest TorrentPeers data for the hash. If the torrent is removed or not found, the flow will complete.

Link copied to clipboard
suspend fun pauseTorrents(hashes: List<String> = allList)

Pause one or more torrents

Link copied to clipboard
suspend fun reannounceTorrents(hashes: List<String> = allList)

Reannounce a torrent.

Link copied to clipboard
suspend fun recheckTorrents(hashes: List<String> = allList)

Recheck a torrent in qBittorrent.

Link copied to clipboard
suspend fun removeCategories(names: List<String>)
Link copied to clipboard
suspend fun removeTorrentTags(hashes: List<String> = allList, tags: List<String>)
Link copied to clipboard
suspend fun removeTrackers(hash: String, urls: List<String>)
Link copied to clipboard
suspend fun renameFile(hash: String, id: Int, newName: String)
Link copied to clipboard
suspend fun renameFolder(hash: String, id: Int, newName: String)
Link copied to clipboard
suspend fun resumeTorrents(hashes: List<String> = allList)

Resume one or more torrents

Link copied to clipboard
suspend fun setAutoTorrentManagement(hashes: List<String> = allList, enabled: Boolean)
Link copied to clipboard
suspend fun setFilePriority(hash: String, ids: List<Int>, priority: Int)
Link copied to clipboard
suspend fun setForceStart(hashes: List<String> = allList, value: Boolean)
Link copied to clipboard
suspend fun setGlobalDownloadLimit(limit: Int)
Link copied to clipboard
suspend fun setGlobalUploadLimit(limit: Int)
Link copied to clipboard
suspend fun setPreferences(prefs: JsonObject)

Set one or more qBittorrent application preferences.

Link copied to clipboard
suspend fun setSuperSeeding(hashes: List<String> = allList, value: Boolean)
Link copied to clipboard
suspend fun setTorrentCategory(hashes: List<String> = allList, category: String)
Link copied to clipboard
suspend fun setTorrentDownloadLimit(hashes: List<String> = allList)
Link copied to clipboard
suspend fun setTorrentLocation(hashes: List<String> = allList, location: String)
Link copied to clipboard
suspend fun setTorrentName(hash: String, name: String)
Link copied to clipboard
suspend fun setTorrentShareLimits(hashes: List<String> = allList, ratioLimit: Float, seedingTimeLimit: Duration)
Link copied to clipboard
suspend fun setTorrentUploadLimit(hashes: List<String> = allList, limit: Long)
Link copied to clipboard
suspend fun shutdown()

Shutdown qBittorrent

Link copied to clipboard
suspend fun toggleFirstLastPriority(hashes: List<String> = allList)
Link copied to clipboard
suspend fun toggleSequentialDownload(hashes: List<String> = allList)
Link copied to clipboard
suspend fun toggleSpeedLimitsMode()

Properties

Link copied to clipboard

Returns true when observeMainData or observeTorrent have at least one subscriber, meaning the syncing endpoint is being polled at syncInterval.