Skip to content

Commit 76184e0

Browse files
committed
resend dropped torrent requests
1 parent 0b1399f commit 76184e0

File tree

1 file changed

+27
-3
lines changed
  • app/src/main/java/com/lagradost/cloudstream3/ui/player

1 file changed

+27
-3
lines changed

app/src/main/java/com/lagradost/cloudstream3/ui/player/Torrent.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import android.net.Uri
44
import androidx.core.net.toUri
55
import com.lagradost.api.Log
66
import com.lagradost.cloudstream3.CommonActivity
7+
import com.lagradost.cloudstream3.ErrorLoadingException
78
import com.lagradost.cloudstream3.TvType
89
import com.lagradost.cloudstream3.mvvm.logError
9-
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
1010
import com.lagradost.cloudstream3.utils.ExtractorLink
1111
import com.lagradost.fetchbutton.aria2c.Aria2Args
1212
import com.lagradost.fetchbutton.aria2c.Aria2Settings
@@ -117,7 +117,7 @@ object Torrent {
117117
connections = metadata.items.sumOf { it.connections }
118118
)
119119
)
120-
if(metadata.status != DownloadStatusTell.Complete) {
120+
if (metadata.status != DownloadStatusTell.Complete) {
121121
extraWait = defaultWait
122122
}
123123
when (metadata.status) {
@@ -336,7 +336,31 @@ object Torrent {
336336

337337
when (metadata?.status) {
338338
DownloadStatusTell.Removed, DownloadStatusTell.Error, null -> {
339-
Aria2Starter.download(uriReq)
339+
var isValid = false
340+
// use incremental delay in the case of weird behavior of startup time or something
341+
for (i in 0..10) {
342+
val response = Aria2Starter.instance?.client?.sendUri(uriReq)
343+
DownloadListener.sessionIdToLastRequest[requestId] = uriReq
344+
// instance not started
345+
if (response == null) {
346+
Aria2Starter.refresh()
347+
delay(100L * i)
348+
continue
349+
}
350+
// send error, due to closed or timeout
351+
val gid = response.getOrNull()
352+
if (gid == null) {
353+
Aria2Starter.refresh()
354+
delay(100L * i)
355+
continue
356+
}
357+
DownloadListener.insert(gid, requestId)
358+
isValid = true
359+
break
360+
}
361+
if (!isValid) {
362+
throw ErrorLoadingException("Unable to connect to internal server")
363+
}
340364
}
341365

342366
else -> Unit

0 commit comments

Comments
 (0)