
Enables downloading of magnet URIs with optimized memory usage and performance for mobile contexts. Features a small, efficient footprint suitable for web and Android applications.
The Loki Bittorrent library implements the download of magnet URIs.
The implemented DHT based on Mainline DHT. The specification can be found here Bittorrent.
kotlin {
sourceSets {
commonMain.dependencies {
...
implementation("io.github.remmerw:loki:0.5.1")
}
...
}
}
fun downloadMagnetUri(): Unit = runBlocking(Dispatchers.IO) {
val uri =
"magnet:?xt=urn:btih:..." // needs a valid magnet Uri
val magnetUri = parseMagnetUri(uri)
// temp directory where to store intermediate files
val cacheDir = SystemTemporaryDirectory
val storage =
download(magnetUri, cacheDir) { torrentState: State ->
val completePieces = torrentState.piecesComplete
val totalPieces = torrentState.piecesTotal
println(" pieces : $completePieces/$totalPieces")
}
val dataDir = Path( cacheDir, magnetUri.displayName ?: "empty")
SystemFileSystem.createDirectories(dataDir)
storage.storeTo(dataDir) // store files in the final directory
storage.finish() // cleanup of intermediate files
}
The Loki Bittorrent library implements the download of magnet URIs.
The implemented DHT based on Mainline DHT. The specification can be found here Bittorrent.
kotlin {
sourceSets {
commonMain.dependencies {
...
implementation("io.github.remmerw:loki:0.5.1")
}
...
}
}
fun downloadMagnetUri(): Unit = runBlocking(Dispatchers.IO) {
val uri =
"magnet:?xt=urn:btih:..." // needs a valid magnet Uri
val magnetUri = parseMagnetUri(uri)
// temp directory where to store intermediate files
val cacheDir = SystemTemporaryDirectory
val storage =
download(magnetUri, cacheDir) { torrentState: State ->
val completePieces = torrentState.piecesComplete
val totalPieces = torrentState.piecesTotal
println(" pieces : $completePieces/$totalPieces")
}
val dataDir = Path( cacheDir, magnetUri.displayName ?: "empty")
SystemFileSystem.createDirectories(dataDir)
storage.storeTo(dataDir) // store files in the final directory
storage.finish() // cleanup of intermediate files
}