qBittorrent Kotlin
Multiplatform Kotlin wrapper for the qBittorrent Web API using Ktor.
Features
- Targets qBittorrent WebUI API v2.8.3
- Two modules:
client
contains all the HTTP code, models
contains only the serializable data models - Automatic authentication handling when interacting with the API
- Coroutine Flow APIs wrapping the syncing endpoints
- Add torrents with HTTP/Magnet URLs and file paths
Usage
For a comprehensive list of available endpoints and to understand the returned data, see the qBittorrent API Docs.
QBittorrentClient only requires baseUrl
assuming default credentials are used.
val client = QBittorrentClient(
baseUrl = "http://localhost:8080",
username = "admin",
password = "adminadmin",
mainDataSyncMs = 5000L,
httpClient = HttpClient(),
dispatcher = Dispatchers.Default,
)
Add a new torrent:
client.addTorrent {
urls.add("magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a")
torrents.add("~/Downloads/my.torrent")
rawTorrents["my.torrent"] = getFileBytes()
savepath = "/downloads"
}
Subscribe to torrent updates:
client.torrentFlow("c12fe1c06bba254a9dc9f519b335aa7c1367a88a")
.collect { torrent ->
println("${torrent.name} : ${torrent.state}")
}
Download
repositories {
mavenCentral()
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
implementation("org.drewcarlson:qbittorrent-client:$qbittorrent_version")
implementation("org.drewcarlson:qbittorrent-models:$qbittorrent_version")
}
Note: it is required to specify a Ktor client engine implementation.
(Documentation)
dependencies {
implementation("io.ktor:ktor-client-okhttp:$ktor_version")
implementation("io.ktor:ktor-client-android:$ktor_version")
implementation("io.ktor:ktor-client-darwin:$ktor_version")
implementation("io.ktor:ktor-client-curl:$ktor_version")
implementation("io.ktor:ktor-client-js:$ktor_version")
}
License
Copyright (c) 2020 Andrew Carlson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.