download fix

This commit is contained in:
LagradOst 2021-08-11 19:40:23 +02:00
parent dd97f5f881
commit f5d7da43ed

View file

@ -24,6 +24,7 @@ import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.mvvm.normalSafeApiCall import com.lagradost.cloudstream3.mvvm.normalSafeApiCall
import com.lagradost.cloudstream3.services.VideoDownloadService import com.lagradost.cloudstream3.services.VideoDownloadService
import com.lagradost.cloudstream3.utils.Coroutines.main import com.lagradost.cloudstream3.utils.Coroutines.main
import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread
import com.lagradost.cloudstream3.utils.DataStore.getKey import com.lagradost.cloudstream3.utils.DataStore.getKey
import com.lagradost.cloudstream3.utils.DataStore.removeKey import com.lagradost.cloudstream3.utils.DataStore.removeKey
import com.lagradost.cloudstream3.utils.DataStore.setKey import com.lagradost.cloudstream3.utils.DataStore.setKey
@ -510,13 +511,20 @@ object VideoDownloadManager {
connection.setRequestProperty("Accept-Encoding", "identity") connection.setRequestProperty("Accept-Encoding", "identity")
connection.setRequestProperty("User-Agent", USER_AGENT) connection.setRequestProperty("User-Agent", USER_AGENT)
if (link.referer.isNotEmpty()) connection.setRequestProperty("Referer", link.referer) if (link.referer.isNotEmpty()) connection.setRequestProperty("Referer", link.referer)
connection.setRequestProperty("Range", "bytes=${(if (resume) fileLength else 0)}-") if (resume)
connection.setRequestProperty("Range", "bytes=${fileLength}-")
val resumeLength = (if (resume) fileLength else 0) val resumeLength = (if (resume) fileLength else 0)
// ON CONNECTION // ON CONNECTION
connection.connect() connection.connect()
val contentLength = connection.contentLength
val contentLength = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // fuck android
connection.contentLengthLong
} else {
connection.getHeaderField("content-length").toLongOrNull() ?: connection.contentLength.toLong()
}
val bytesTotal = contentLength + resumeLength val bytesTotal = contentLength + resumeLength
if (bytesTotal < 5000000) return ERROR_TOO_SMALL_CONNECTION // DATA IS LESS THAN 5MB, SOMETHING IS WRONG if (bytesTotal < 5000000) return ERROR_TOO_SMALL_CONNECTION // DATA IS LESS THAN 5MB, SOMETHING IS WRONG
context.setKey(KEY_DOWNLOAD_INFO, ep.id.toString(), DownloadedFileInfo(bytesTotal, relativePath, displayName)) context.setKey(KEY_DOWNLOAD_INFO, ep.id.toString(), DownloadedFileInfo(bytesTotal, relativePath, displayName))