Skip to content

Commit

Permalink
chore(lib/StreamWishExtractor): Update StreamWishExtractor (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark25 authored Aug 15, 2024
1 parent 2419e31 commit c1a2d05
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -25,7 +25,6 @@ class StreamWishExtractor(private val client: OkHttpClient, private val headers:
script
}
}

val masterUrl = scriptBody
?.substringAfter("source", "")
?.substringAfter("file:\"", "")
Expand All @@ -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
}
}
}

0 comments on commit c1a2d05

Please sign in to comment.