mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Show download size on videos (#1038)
This commit is contained in:
parent
afdc4988ac
commit
aa8972870c
2 changed files with 30 additions and 5 deletions
|
@ -5,6 +5,7 @@ import android.content.*
|
|||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.format.Formatter.formatFileSize
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.MainThread
|
||||
|
@ -20,7 +21,6 @@ import com.lagradost.cloudstream3.APIHolder.apis
|
|||
import com.lagradost.cloudstream3.APIHolder.getId
|
||||
import com.lagradost.cloudstream3.APIHolder.unixTime
|
||||
import com.lagradost.cloudstream3.APIHolder.unixTimeMS
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.context
|
||||
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
||||
import com.lagradost.cloudstream3.CommonActivity.activity
|
||||
import com.lagradost.cloudstream3.CommonActivity.getCastSession
|
||||
|
@ -1280,9 +1280,14 @@ class ResultViewModel2 : ViewModel() {
|
|||
callback: (Pair<LinkLoadingResult, Int>) -> Unit,
|
||||
) {
|
||||
loadLinks(result, isVisible = true, type) { links ->
|
||||
// Could not find a better way to do this
|
||||
val context = AcraApplication.context
|
||||
postPopup(
|
||||
text,
|
||||
links.links.map { txt("${it.name} ${Qualities.getStringByInt(it.quality)}") }) {
|
||||
links.links.apmap {
|
||||
val size = it.getVideoSize()?.let { size -> " " + formatFileSize(context, size) } ?: ""
|
||||
txt("${it.name} ${Qualities.getStringByInt(it.quality)}$size")
|
||||
}) {
|
||||
callback.invoke(links to (it ?: return@postPopup))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -407,6 +407,26 @@ open class ExtractorLink constructor(
|
|||
val isM3u8: Boolean get() = type == ExtractorLinkType.M3U8
|
||||
val isDash: Boolean get() = type == ExtractorLinkType.DASH
|
||||
|
||||
// Cached video size
|
||||
private var videoSize: Long? = null
|
||||
|
||||
/**
|
||||
* Get video size in bytes with one head request. Only available for ExtractorLinkType.Video
|
||||
* @param timeoutSeconds timeout of the head request.
|
||||
*/
|
||||
suspend fun getVideoSize(timeoutSeconds: Long = 3L): Long? {
|
||||
// Content-Length is not applicable to other types of formats
|
||||
if (this.type != ExtractorLinkType.VIDEO) return null
|
||||
|
||||
videoSize = videoSize ?: runCatching {
|
||||
val response =
|
||||
app.head(this.url, headers = headers, referer = referer, timeout = timeoutSeconds)
|
||||
response.headers["Content-Length"]?.toLong()
|
||||
}.getOrNull()
|
||||
|
||||
return videoSize
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
fun getAllHeaders() : Map<String, String> {
|
||||
if (referer.isBlank()) {
|
||||
|
|
Loading…
Reference in a new issue