Skip to content

Commit

Permalink
Update M3u8Helper.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjixWasTaken authored Sep 4, 2021
1 parent e4e0534 commit c0f8d84
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/src/main/java/com/lagradost/cloudstream3/utils/M3u8Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.math.pow
class M3u8Helper {
private val ENCRYPTION_DETECTION_REGEX = Regex("#EXT-X-KEY:METHOD=([^,]+),")
private val ENCRYPTION_URL_IV_REGEX = Regex("#EXT-X-KEY:METHOD=([^,]+),URI=\"([^\"]+)\"(?:,IV=(.*))?")
private val QUALITY_REGEX = Regex("""#EXT-X-STREAM-INF:.*(?:RESOLUTION=\d+x(\d+))?.*\s+(.*)""")
private val QUALITY_REGEX = Regex("""#EXT-X-STREAM-INF:(?:(?:.*?(?:RESOLUTION=\d+x(\d+)).*?\s+(.*))|(?:.*?\s+(.*)))""")
private val TS_EXTENSION_REGEX = Regex("""(.*\.ts.*)""")

fun absoluteExtensionDetermination(url: String): String? {
Expand Down Expand Up @@ -62,7 +62,7 @@ class M3u8Helper {
if (it.quality != null && it.quality <= 1080) it.quality else 0
}.filter {
listOf("m3u", "m3u8").contains(absoluteExtensionDetermination(it.streamUrl))
}.reversed()
}
return result.getOrNull(0)
}

Expand All @@ -82,11 +82,15 @@ class M3u8Helper {
val response = khttp.get(m3u8.streamUrl, headers = m3u8.headers)

for (match in QUALITY_REGEX.findAll(response.text)) {
var (quality, m3u8Link) = match.destructured
var (quality, m3u8Link, m3u8Link2) = match.destructured
if (m3u8Link.isNullOrEmpty()) m3u8Link = m3u8Link2
if (absoluteExtensionDetermination(m3u8Link) == "m3u8") {
if (isNotCompleteUrl(m3u8Link)) {
m3u8Link = "$m3u8Parent/$m3u8Link"
}
if (quality.isEmpty()) {
println(m3u8.streamUrl)
}
yieldAll(
m3u8Generation(
M3u8Stream(
Expand Down

0 comments on commit c0f8d84

Please sign in to comment.