Update ExtractorApi.kt

This commit is contained in:
CranberrySoup 2024-04-13 17:57:29 +00:00 committed by GitHub
parent 9f8bbed6c1
commit bd52d40773
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -407,6 +407,26 @@ open class ExtractorLink constructor(
val isM3u8: Boolean get() = type == ExtractorLinkType.M3U8 val isM3u8: Boolean get() = type == ExtractorLinkType.M3U8
val isDash: Boolean get() = type == ExtractorLinkType.DASH 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 @JsonIgnore
fun getAllHeaders() : Map<String, String> { fun getAllHeaders() : Map<String, String> {
if (referer.isBlank()) { if (referer.isBlank()) {