|
|
@ -129,49 +129,59 @@ class Rtorrent(private val configuration: Configuration) : |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun start(torrent: Torrent): Single<Torrent> { |
|
|
|
override fun start(torrent: Torrent): Single<Torrent> { |
|
|
|
return service.start( |
|
|
|
return service.open(configuration.endpoint, torrent.uniqueId) |
|
|
|
configuration.endpoint, |
|
|
|
.flatMap { service.start(configuration.endpoint, torrent.uniqueId) } |
|
|
|
torrent.uniqueId).toSingle { torrent.mimicStart() } |
|
|
|
.map { torrent.mimicStart() } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun stop(torrent: Torrent): Single<Torrent> { |
|
|
|
override fun stop(torrent: Torrent): Single<Torrent> { |
|
|
|
return service.stop( |
|
|
|
return service.stop(configuration.endpoint, torrent.uniqueId) |
|
|
|
configuration.endpoint, |
|
|
|
.flatMap { service.close(configuration.endpoint, torrent.uniqueId) } |
|
|
|
torrent.uniqueId).toSingle { torrent.mimicStop() } |
|
|
|
.map { torrent.mimicStop() } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun resume(torrent: Torrent): Single<Torrent> { |
|
|
|
|
|
|
|
return service.start(configuration.endpoint, torrent.uniqueId) |
|
|
|
|
|
|
|
.map { torrent.mimicResume() } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun pause(torrent: Torrent): Single<Torrent> { |
|
|
|
|
|
|
|
return service.stop(configuration.endpoint, torrent.uniqueId) |
|
|
|
|
|
|
|
.map { torrent.mimicPause() } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun addByUrl(url: String): Completable { |
|
|
|
override fun addByUrl(url: String): Completable { |
|
|
|
return clientVersion().asVersionInt().flatMapCompletable { integer -> |
|
|
|
return clientVersion().asVersionInt().flatMap { integer -> |
|
|
|
if (integer >= 904) { |
|
|
|
if (integer >= 904) { |
|
|
|
service.loadStart(configuration.endpoint, "", url) |
|
|
|
service.loadStart(configuration.endpoint, "", url) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
service.loadStart(configuration.endpoint, url) |
|
|
|
service.loadStart(configuration.endpoint, url) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.toCompletable() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun addByMagnet(magnet: String): Completable { |
|
|
|
override fun addByMagnet(magnet: String): Completable { |
|
|
|
return clientVersion().asVersionInt().flatMapCompletable { integer -> |
|
|
|
return clientVersion().asVersionInt().flatMap { integer -> |
|
|
|
if (integer >= 904) { |
|
|
|
if (integer >= 904) { |
|
|
|
service.loadStart(configuration.endpoint, "", magnet) |
|
|
|
service.loadStart(configuration.endpoint, "", magnet) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
service.loadStart(configuration.endpoint, magnet) |
|
|
|
service.loadStart(configuration.endpoint, magnet) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.toCompletable() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun addByFile(file: InputStream): Completable { |
|
|
|
override fun addByFile(file: InputStream): Completable { |
|
|
|
return clientVersion().asVersionInt().flatMapCompletable { integer -> |
|
|
|
return clientVersion().asVersionInt().flatMap { integer -> |
|
|
|
val bytes = file.readBytes() |
|
|
|
val bytes = file.readBytes() |
|
|
|
val size = Math.max(bytes.size, xmlrpcSizeMinimum) + xmlrpcSizePadding |
|
|
|
val size = Math.max(bytes.size, xmlrpcSizeMinimum) + xmlrpcSizePadding |
|
|
|
if (integer >= 904) { |
|
|
|
if (integer >= 904) { |
|
|
|
service.networkSizeLimitSet(configuration.endpoint, "", size) |
|
|
|
service.networkSizeLimitSet(configuration.endpoint, "", size) |
|
|
|
.flatMapCompletable { service.loadRawStart(configuration.endpoint, "", bytes) } |
|
|
|
.flatMap { service.loadRawStart(configuration.endpoint, "", bytes) } |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
service.networkSizeLimitSet(configuration.endpoint, size) |
|
|
|
service.networkSizeLimitSet(configuration.endpoint, size) |
|
|
|
.flatMapCompletable { service.loadRawStart(configuration.endpoint, bytes) } |
|
|
|
.flatMap { service.loadRawStart(configuration.endpoint, bytes) } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.toCompletable() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun torrentStatus(state: Long, complete: Long, active: Long, checking: Long): TorrentStatus { |
|
|
|
private fun torrentStatus(state: Long, complete: Long, active: Long, checking: Long): TorrentStatus { |
|
|
|