Skip to content

Commit a45b9d4

Browse files
committed
refactor(extractors): simplify and combine jwplayer extraction
1 parent 5c0f715 commit a45b9d4

File tree

23 files changed

+274
-790
lines changed

23 files changed

+274
-790
lines changed

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/AsianLoad.kt

Lines changed: 0 additions & 50 deletions
This file was deleted.

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/Bigwarp.kt

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,44 @@
11
package com.lagradost.cloudstream3.extractors
22

3+
import com.lagradost.cloudstream3.SubtitleFile
34
import com.lagradost.cloudstream3.amap
45
import com.lagradost.cloudstream3.app
6+
import com.lagradost.cloudstream3.extractors.helper.JwPlayerHelper
57
import com.lagradost.cloudstream3.utils.ExtractorApi
68
import com.lagradost.cloudstream3.utils.ExtractorLink
7-
import com.lagradost.cloudstream3.utils.M3u8Helper.Companion.generateM3u8
89
import com.lagradost.cloudstream3.utils.getAndUnpack
9-
import org.jsoup.nodes.Document
10+
import com.lagradost.cloudstream3.utils.getPacked
1011

11-
open class Fastream: ExtractorApi() {
12+
open class Fastream : ExtractorApi() {
1213
override var mainUrl = "https://fastream.to"
1314
override var name = "Fastream"
1415
override val requiresReferer = false
15-
suspend fun getstream(
16-
response: Document,
17-
sources: ArrayList<ExtractorLink>): Boolean{
18-
response.select("script").amap { script ->
19-
if (script.data().contains(Regex("eval\\(function\\(p,a,c,k,e,[rd]"))) {
20-
val unpacked = getAndUnpack(script.data())
21-
//val m3u8regex = Regex("((https:|http:)\\/\\/.*\\.m3u8)")
22-
val newm3u8link = unpacked.substringAfter("file:\"").substringBefore("\"")
23-
//val m3u8link = m3u8regex.find(unpacked)?.value ?: return@forEach
24-
generateM3u8(
25-
name,
26-
newm3u8link,
27-
mainUrl
28-
).forEach { link ->
29-
sources.add(link)
30-
}
31-
}
32-
}
33-
return true
34-
}
3516

36-
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink> {
37-
val sources = ArrayList<ExtractorLink>()
17+
override suspend fun getUrl(
18+
url: String,
19+
referer: String?,
20+
subtitleCallback: (SubtitleFile) -> Unit,
21+
callback: (ExtractorLink) -> Unit
22+
) {
3823
val idregex = Regex("emb.html\\?(.*)=")
39-
if (url.contains(Regex("(emb.html.*fastream)"))) {
24+
val response = if (url.contains(Regex("(emb.html.*fastream)"))) {
4025
val id = idregex.find(url)?.destructured?.component1() ?: ""
41-
val response = app.post("https://fastream.to/dl", allowRedirects = false,
26+
app.post(
27+
"$mainUrl/dl", allowRedirects = false,
4228
data = mapOf(
4329
"op" to "embed",
4430
"file_code" to id,
4531
"auto" to "1"
4632
)
4733
).document
48-
getstream(response, sources)
34+
} else {
35+
app.get(url, referer = url).document
36+
}
37+
response.select("script").amap { script ->
38+
if (getPacked(script.data()) != null) {
39+
val unPacked = getAndUnpack(script.data())
40+
JwPlayerHelper.getStreamLinks(unPacked, name, mainUrl, callback, subtitleCallback)
41+
}
4942
}
50-
val response = app.get(url, referer = url).document
51-
getstream(response, sources)
52-
return sources
5343
}
5444
}

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/Filegram.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package com.lagradost.cloudstream3.extractors
33
import com.lagradost.cloudstream3.SubtitleFile
44
import com.lagradost.cloudstream3.USER_AGENT
55
import com.lagradost.cloudstream3.app
6+
import com.lagradost.cloudstream3.extractors.helper.JwPlayerHelper
67
import com.lagradost.cloudstream3.utils.ExtractorApi
78
import com.lagradost.cloudstream3.utils.ExtractorLink
8-
import com.lagradost.cloudstream3.utils.M3u8Helper
9-
import com.lagradost.cloudstream3.utils.fixUrl
109
import com.lagradost.cloudstream3.utils.getAndUnpack
1110
import org.jsoup.nodes.Element
1211

@@ -35,15 +34,8 @@ open class Filegram : ExtractorApi() {
3534

3635
val doc = app.get(getEmbedUrl(url), referer = referer).document
3736
val unpackedJs = unpackJs(doc).toString()
38-
val videoUrl = Regex("""file:\s*"([^"]+\.m3u8[^"]*)"""").find(unpackedJs)?.groupValues?.get(1)
39-
if (videoUrl != null) {
40-
M3u8Helper.generateM3u8(
41-
this.name,
42-
fixUrl(videoUrl),
43-
"$mainUrl/",
44-
headers = header
45-
).forEach(callback)
46-
}
37+
38+
JwPlayerHelper.getStreamLinks(unpackedJs, name, mainUrl, callback, subtitleCallback, headers = header)
4739
}
4840

4941
private fun unpackJs(script: Element): String? {

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/Filemoon.kt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lagradost.cloudstream3.extractors
33
import com.lagradost.api.Log
44
import com.lagradost.cloudstream3.SubtitleFile
55
import com.lagradost.cloudstream3.app
6+
import com.lagradost.cloudstream3.extractors.helper.JwPlayerHelper
67
import com.lagradost.cloudstream3.network.WebViewResolver
78
import com.lagradost.cloudstream3.utils.ExtractorApi
89
import com.lagradost.cloudstream3.utils.ExtractorLink
@@ -54,18 +55,16 @@ open class FilemoonV2 : ExtractorApi() {
5455
?.data().orEmpty()
5556
val unpackedScript = JsUnpacker(fallbackScriptData).unpack()
5657

57-
val videoUrl = unpackedScript?.let {
58-
Regex("""sources:\[\{file:"(.*?)"""").find(it)?.groupValues?.get(1)
59-
}
58+
val linkFound = JwPlayerHelper.getStreamLinks(
59+
unpackedScript.orEmpty(),
60+
name,
61+
mainUrl,
62+
callback,
63+
subtitleCallback,
64+
defaultHeaders
65+
)
6066

61-
if (!videoUrl.isNullOrEmpty()) {
62-
M3u8Helper.generateM3u8(
63-
name,
64-
videoUrl,
65-
mainUrl,
66-
headers = defaultHeaders
67-
).forEach(callback)
68-
} else {
67+
if (!linkFound) {
6968
Log.d("FilemoonV2", "No iframe and no video URL found in script fallback.")
7069
}
7170
return
@@ -81,18 +80,15 @@ open class FilemoonV2 : ExtractorApi() {
8180

8281
val unpackedScript = JsUnpacker(iframeScriptData).unpack()
8382

84-
val videoUrl = unpackedScript?.let {
85-
Regex("""sources:\[\{file:"(.*?)"""").find(it)?.groupValues?.get(1)
86-
}
83+
val linkFound = JwPlayerHelper.getStreamLinks(
84+
unpackedScript.orEmpty(),
85+
name,
86+
mainUrl,
87+
callback,
88+
subtitleCallback
89+
)
8790

88-
if (!videoUrl.isNullOrEmpty()) {
89-
M3u8Helper.generateM3u8(
90-
name,
91-
videoUrl,
92-
mainUrl,
93-
headers = defaultHeaders
94-
).forEach(callback)
95-
} else {
91+
if (!linkFound) {
9692
// Last-resort fallback using WebView interception
9793
val resolver = WebViewResolver(
9894
interceptUrl = Regex("""(m3u8|master\.txt)"""),

library/src/commonMain/kotlin/com/lagradost/cloudstream3/extractors/Filesim.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.lagradost.cloudstream3.SubtitleFile
44
import com.lagradost.cloudstream3.app
55
import com.lagradost.cloudstream3.utils.*
66
import com.lagradost.api.Log
7+
import com.lagradost.cloudstream3.extractors.helper.JwPlayerHelper
78
import com.lagradost.cloudstream3.network.WebViewResolver
89

910

@@ -76,17 +77,9 @@ open class Filesim : ExtractorApi() {
7677
pageResponse.document.selectFirst("script:containsData(sources:)")?.data()
7778
}
7879

79-
val m3u8Url = scriptData?.let {
80-
Regex("""file:\s*"(.*?m3u8.*?)"""").find(it)?.groupValues?.getOrNull(1)
81-
}
80+
val linkFound = JwPlayerHelper.getStreamLinks(scriptData.orEmpty(), name, mainUrl, callback, subtitleCallback)
8281

83-
if (!m3u8Url.isNullOrEmpty()) {
84-
M3u8Helper.generateM3u8(
85-
name,
86-
m3u8Url,
87-
mainUrl
88-
).forEach(callback)
89-
} else {
82+
if (!linkFound) {
9083
// Fallback using WebViewResolver
9184
val resolver = WebViewResolver(
9285
interceptUrl = Regex("""(m3u8|master\.txt)"""),
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.lagradost.cloudstream3.extractors
22

3+
import com.lagradost.cloudstream3.SubtitleFile
34
import com.lagradost.cloudstream3.app
4-
import com.lagradost.cloudstream3.utils.*
5+
import com.lagradost.cloudstream3.extractors.helper.JwPlayerHelper
6+
import com.lagradost.cloudstream3.utils.ExtractorApi
7+
import com.lagradost.cloudstream3.utils.ExtractorLink
58

69

710
open class GamoVideo : ExtractorApi() {
@@ -11,21 +14,13 @@ open class GamoVideo : ExtractorApi() {
1114

1215
override suspend fun getUrl(
1316
url: String,
14-
referer: String?
15-
): List<ExtractorLink>? {
16-
return app.get(url, referer = referer).document.select("script")
17-
.firstOrNull { it.html().contains("sources:") }!!.html().substringAfter("file: \"")
18-
.substringBefore("\",").let {
19-
listOf(
20-
newExtractorLink(
21-
name,
22-
name,
23-
it,
24-
) {
25-
this.referer = url
26-
this.quality = Qualities.Unknown.value
27-
}
28-
)
29-
}
17+
referer: String?,
18+
subtitleCallback: (SubtitleFile) -> Unit,
19+
callback: (ExtractorLink) -> Unit
20+
) {
21+
app.get(url, referer = referer).document.select("script")
22+
.firstOrNull { JwPlayerHelper.canParseJwScript(it.data()) }!!.let {
23+
JwPlayerHelper.getStreamLinks(it.data(), name, mainUrl, callback, subtitleCallback)
24+
}
3025
}
3126
}

0 commit comments

Comments
 (0)