Skip to content

Commit f5cd549

Browse files
authored
feat(Extensions): newExtractorLink for developers (#1632)
* feat(Extensions): newExtractorLink for developers * remove isM3u8 and use type
1 parent 4c610aa commit f5cd549

78 files changed

Lines changed: 742 additions & 525 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class DownloadFragment : Fragment() {
352352
LinkGenerator(
353353
listOf(BasicLink(url)),
354354
extract = true,
355-
referer = referer,
355+
refererUrl = referer,
356356
isM3u8 = binding.hlsSwitch.isChecked
357357
)
358358
)

app/src/main/java/com/lagradost/cloudstream3/ui/player/LinkGenerator.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.utils.ExtractorLinkType
88
import com.lagradost.cloudstream3.utils.INFER_TYPE
99
import com.lagradost.cloudstream3.utils.Qualities
1010
import com.lagradost.cloudstream3.utils.loadExtractor
11+
import com.lagradost.cloudstream3.utils.newExtractorLink
1112
import com.lagradost.cloudstream3.utils.unshortenLinkSafe
1213

1314
data class ExtractorUri(
@@ -36,7 +37,7 @@ data class BasicLink(
3637
class LinkGenerator(
3738
private val links: List<BasicLink>,
3839
private val extract: Boolean = true,
39-
private val referer: String? = null,
40+
private val refererUrl: String? = null,
4041
private val isM3u8: Boolean? = null
4142
) : IGenerator {
4243
override val hasCache = false
@@ -77,22 +78,23 @@ class LinkGenerator(
7778
isCasting: Boolean
7879
): Boolean {
7980
links.amap { link ->
80-
if (!extract || !loadExtractor(link.url, referer, {
81+
if (!extract || !loadExtractor(link.url, refererUrl, {
8182
subtitleCallback(PlayerSubtitleHelper.getSubtitleData(it))
8283
}) {
8384
callback(it to null)
8485
}) {
8586

8687
// if don't extract or if no extractor found simply return the link
8788
callback(
88-
ExtractorLink(
89+
newExtractorLink(
8990
"",
9091
link.name ?: link.url,
9192
unshortenLinkSafe(link.url), // unshorten because it might be a raw link
92-
referer ?: "",
93-
Qualities.Unknown.value,
9493
type = INFER_TYPE,
95-
) to null
94+
) {
95+
this.referer = refererUrl ?: ""
96+
this.quality = Qualities.Unknown.value
97+
} to null
9698
)
9799
}
98100
}

app/src/main/java/com/lagradost/cloudstream3/ui/result/ResultViewModel2.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,15 +2486,16 @@ class ResultViewModel2 : ViewModel() {
24862486
{ links.add(it) }) && trailerData.raw
24872487
) {
24882488
arrayListOf(
2489-
ExtractorLink(
2489+
newExtractorLink(
24902490
"",
24912491
"Trailer",
24922492
trailerData.extractorUrl,
2493-
trailerData.referer ?: "",
2494-
Qualities.Unknown.value,
2495-
headers = trailerData.headers,
24962493
type = INFER_TYPE
2497-
)
2494+
) {
2495+
this.referer = trailerData.referer ?: ""
2496+
this.quality = Qualities.Unknown.value
2497+
this.headers = trailerData.headers
2498+
}
24982499
) to arrayListOf()
24992500
} else {
25002501
links to subs

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import com.lagradost.api.Log
44
import com.lagradost.cloudstream3.app
55
import com.lagradost.cloudstream3.utils.ExtractorApi
66
import com.lagradost.cloudstream3.utils.ExtractorLink
7+
import com.lagradost.cloudstream3.utils.ExtractorLinkType
78
import com.lagradost.cloudstream3.utils.Qualities
9+
import com.lagradost.cloudstream3.utils.newExtractorLink
810

911
open class AStreamHub : ExtractorApi() {
1012
override val name = "AStreamHub"
@@ -22,14 +24,15 @@ open class AStreamHub : ExtractorApi() {
2224
Log.i("Dev", "m3link => $m3link")
2325
if (m3link.isNotBlank()) {
2426
sources.add(
25-
ExtractorLink(
27+
newExtractorLink(
2628
name = name,
2729
source = name,
2830
url = m3link,
29-
isM3u8 = true,
30-
quality = Qualities.Unknown.value,
31-
referer = referer ?: url
32-
)
31+
type = ExtractorLinkType.M3U8
32+
) {
33+
this.quality = Qualities.Unknown.value
34+
this.referer = referer ?: url
35+
}
3336
)
3437
}
3538
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ open class Acefile : ExtractorApi() {
2424
val video = app.get(serverUrl ?: return, referer = "$mainUrl/").parsedSafe<Source>()?.data
2525

2626
callback.invoke(
27-
ExtractorLink(
27+
newExtractorLink(
2828
this.name,
2929
this.name,
30-
video ?: return,
31-
"",
32-
Qualities.Unknown.value,
33-
INFER_TYPE
30+
video ?: return
3431
)
3532
)
3633

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.lagradost.cloudstream3.utils.ExtractorApi
55
import com.lagradost.cloudstream3.utils.ExtractorLink
66
import com.lagradost.cloudstream3.utils.M3u8Helper
77
import com.lagradost.cloudstream3.utils.getQualityFromName
8+
import com.lagradost.cloudstream3.utils.newExtractorLink
89
import java.net.URI
910

1011
open class AsianLoad : ExtractorApi() {
@@ -30,13 +31,14 @@ open class AsianLoad : ExtractorApi() {
3031
}
3132
} else if (extractedUrl.endsWith(".mp4")) {
3233
extractedLinksList.add(
33-
ExtractorLink(
34-
name,
35-
name,
36-
extractedUrl,
37-
url.replace(" ", "%20"),
38-
getQualityFromName(sourceMatch.groupValues[2]),
39-
)
34+
newExtractorLink(
35+
source = name,
36+
name = name,
37+
url = extractedUrl,
38+
) {
39+
this.referer = url.replace(" ", "%20")
40+
this.quality = getQualityFromName(sourceMatch.groupValues[2])
41+
}
4042
)
4143
}
4244
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ open class Blogger : ExtractorApi() {
1919
.substringBefore("]")
2020
tryParseJson<List<ResponseSource>>("[$data]")?.map {
2121
sources.add(
22-
ExtractorLink(
22+
newExtractorLink(
2323
name,
2424
name,
2525
it.play_url,
26-
referer = "https://www.youtube.com/",
27-
quality = when (it.format_id) {
26+
) {
27+
this.referer = "https://www.youtube.com/"
28+
this.quality = when (it.format_id) {
2829
18 -> 360
2930
22 -> 720
3031
else -> Qualities.Unknown.value
3132
}
32-
)
33+
}
3334
)
3435
}
3536
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ open class ByteShare : ExtractorApi() {
1010
override suspend fun getUrl(url: String, referer: String?): List<ExtractorLink> {
1111
val sources = mutableListOf<ExtractorLink>()
1212
sources.add(
13-
ExtractorLink(
14-
name,
15-
name,
16-
url.replace("/embed/", "/download/"),
17-
"",
18-
Qualities.Unknown.value,
13+
newExtractorLink(
14+
source = name,
15+
name = name,
16+
url = url.replace("/embed/", "/download/"),
1917
)
2018
)
2119
return sources

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
66
import com.lagradost.cloudstream3.utils.ExtractorApi
77
import com.lagradost.cloudstream3.utils.ExtractorLink
88
import com.lagradost.cloudstream3.utils.Qualities
9+
import com.lagradost.cloudstream3.utils.newExtractorLink
910
import java.net.URLDecoder
1011

11-
open class Cda: ExtractorApi() {
12+
open class Cda : ExtractorApi() {
1213
override var mainUrl = "https://ebd.cda.pl"
1314
override var name = "Cda"
1415
override val requiresReferer = false
@@ -18,20 +19,25 @@ open class Cda: ExtractorApi() {
1819
val mediaId = url
1920
.split("/").last()
2021
.split("?").first()
21-
val doc = app.get("https://ebd.cda.pl/647x500/$mediaId", headers=mapOf(
22-
"Referer" to "https://ebd.cda.pl/647x500/$mediaId",
23-
"User-Agent" to USER_AGENT,
24-
"Cookie" to "cda.player=html5"
25-
)).document
22+
val doc = app.get(
23+
"https://ebd.cda.pl/647x500/$mediaId", headers = mapOf(
24+
"Referer" to "https://ebd.cda.pl/647x500/$mediaId",
25+
"User-Agent" to USER_AGENT,
26+
"Cookie" to "cda.player=html5"
27+
)
28+
).document
2629
val dataRaw = doc.selectFirst("[player_data]")?.attr("player_data") ?: return null
2730
val playerData = tryParseJson<PlayerData>(dataRaw) ?: return null
28-
return listOf(ExtractorLink(
29-
name,
30-
name,
31-
getFile(playerData.video.file),
32-
referer = "https://ebd.cda.pl/647x500/$mediaId",
33-
quality = Qualities.Unknown.value
34-
))
31+
return listOf(
32+
newExtractorLink(
33+
source = name,
34+
name = name,
35+
url = getFile(playerData.video.file),
36+
) {
37+
this.referer = "https://ebd.cda.pl/647x500/$mediaId"
38+
this.quality = Qualities.Unknown.value
39+
}
40+
)
3541
}
3642

3743
private fun rot13(a: String): String {
@@ -46,7 +52,7 @@ open class Cda: ExtractorApi() {
4652

4753
private fun cdaUggc(a: String): String {
4854
val decoded = rot13(a)
49-
return if (decoded.endsWith("adc.mp4")) decoded.replace("adc.mp4",".mp4")
55+
return if (decoded.endsWith("adc.mp4")) decoded.replace("adc.mp4", ".mp4")
5056
else decoded
5157
}
5258

@@ -72,7 +78,7 @@ open class Cda: ExtractorApi() {
7278
.replace(".2cda.pl", ".cda.pl")
7379
.replace(".3cda.pl", ".cda.pl")
7480
return if (a.contains("/upstream")) "https://" + a.replace("/upstream", ".mp4/upstream")
75-
else "https://${a}.mp4"
81+
else "https://${a}.mp4"
7682
}
7783

7884
private fun getFile(a: String) = when {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.lagradost.cloudstream3.utils.ExtractorApi
99
import com.lagradost.cloudstream3.utils.ExtractorLink
1010
import com.lagradost.cloudstream3.utils.INFER_TYPE
1111
import com.lagradost.cloudstream3.utils.Qualities
12+
import com.lagradost.cloudstream3.utils.newExtractorLink
1213
import java.security.MessageDigest
1314

1415

@@ -106,15 +107,15 @@ open class Chillx : ExtractorApi() {
106107
"user-agent" to USER_AGENT,
107108
)
108109
callback.invoke(
109-
ExtractorLink(
110-
name,
111-
name,
112-
m3u8,
113-
mainUrl,
114-
Qualities.P1080.value,
115-
INFER_TYPE,
116-
headers = header
117-
)
110+
newExtractorLink(
111+
source = name,
112+
name = name,
113+
url = m3u8,
114+
) {
115+
this.referer = mainUrl
116+
this.quality = Qualities.P1080.value
117+
this.headers = header
118+
}
118119
)
119120

120121
val subtitles = extractSrtSubtitles(decoded)

0 commit comments

Comments
 (0)