Skip to content

Commit

Permalink
resend dropped torrent requests
Browse files Browse the repository at this point in the history
  • Loading branch information
LagradOst committed Oct 31, 2024
1 parent 0b1399f commit 76184e0
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import android.net.Uri
import androidx.core.net.toUri
import com.lagradost.api.Log
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.ErrorLoadingException
import com.lagradost.cloudstream3.TvType
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.fetchbutton.aria2c.Aria2Args
import com.lagradost.fetchbutton.aria2c.Aria2Settings
Expand Down Expand Up @@ -117,7 +117,7 @@ object Torrent {
connections = metadata.items.sumOf { it.connections }
)
)
if(metadata.status != DownloadStatusTell.Complete) {
if (metadata.status != DownloadStatusTell.Complete) {
extraWait = defaultWait
}
when (metadata.status) {
Expand Down Expand Up @@ -336,7 +336,31 @@ object Torrent {

when (metadata?.status) {
DownloadStatusTell.Removed, DownloadStatusTell.Error, null -> {
Aria2Starter.download(uriReq)
var isValid = false
// use incremental delay in the case of weird behavior of startup time or something
for (i in 0..10) {
val response = Aria2Starter.instance?.client?.sendUri(uriReq)
DownloadListener.sessionIdToLastRequest[requestId] = uriReq
// instance not started
if (response == null) {
Aria2Starter.refresh()
delay(100L * i)
continue
}
// send error, due to closed or timeout
val gid = response.getOrNull()
if (gid == null) {
Aria2Starter.refresh()
delay(100L * i)
continue
}
DownloadListener.insert(gid, requestId)
isValid = true
break
}
if (!isValid) {
throw ErrorLoadingException("Unable to connect to internal server")
}
}

else -> Unit
Expand Down

0 comments on commit 76184e0

Please sign in to comment.