chore(lib/StreamWishExtractor): Update StreamWishExtractor (#140)

This commit is contained in:
Dark25 2024-08-15 18:16:39 +01:00 committed by GitHub
parent 2419e31671
commit c1a2d05a32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,9 +14,9 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers:
fun videosFromUrl(url: String, prefix: String) = videosFromUrl(url) { "$prefix - $it" }
fun videosFromUrl(url: String, videoNameGen: (String) -> String = { quality -> "StreamWish - $quality" }): List<Video> {
val doc = client.newCall(GET(url, headers)).execute()
.asJsoup()
// Sometimes the script body is packed, sometimes it isn't
val doc = client.newCall(GET(getEmbedUrl(url), headers)).execute().asJsoup()
val scriptBody = doc.selectFirst("script:containsData(m3u8)")?.data()
?.let { script ->
if (script.contains("eval(function(p,a,c")) {
@ -25,7 +25,6 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers:
script
}
}
val masterUrl = scriptBody
?.substringAfter("source", "")
?.substringAfter("file:\"", "")
@ -35,4 +34,13 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers:
return playlistUtils.extractFromHls(masterUrl, url, videoNameGen = videoNameGen)
}
private fun getEmbedUrl(url: String): String {
return if (url.contains("/f/")) {
val videoId = url.substringAfter("/f/")
"https://streamwish.com/$videoId"
} else {
url
}
}
}