1+ package com.lagradost.cloudstream3.extractors
2+
3+ import com.lagradost.api.Log
4+ import com.lagradost.cloudstream3.app
5+ import com.lagradost.cloudstream3.utils.ExtractorApi
6+ import com.lagradost.cloudstream3.utils.ExtractorLink
7+ import com.lagradost.cloudstream3.utils.JsUnpacker
8+ import com.lagradost.cloudstream3.utils.Qualities
9+ import com.lagradost.cloudstream3.utils.fixUrl
10+ import com.lagradost.cloudstream3.utils.newExtractorLink
11+ import kotlinx.coroutines.delay
12+
13+ class Up4FunTop : Up4Stream () {
14+ override var mainUrl: String = " https://up4fun.top"
15+ }
16+
17+ open class Up4Stream : ExtractorApi () {
18+ override var name = " Up4Stream"
19+ override var mainUrl = " https://up4stream.com"
20+ override val requiresReferer = true
21+
22+ override suspend fun getUrl (url : String , referer : String? ): List <ExtractorLink >? {
23+ val movieId = url.substringAfterLast(" /" ).substringBefore(" .html" )
24+
25+ // redirect from "wait 5 seconds" page to actual movie page
26+ val redirectResponse = app.get(url, cookies = mapOf (" id" to movieId))
27+ val redirectForm = redirectResponse.document.selectFirst(" form[method=POST]" ) ? : return null
28+ val redirectUrl = fixUrl(redirectForm.attr(" action" ))
29+ val redirectParams = redirectForm.select(" input[type=hidden]" ).associate { input ->
30+ input.attr(" name" ) to input.attr(" value" )
31+ }
32+
33+ // wait for 5 seconds, otherwise the below md5 hash is invalid
34+ delay(5000 )
35+ val response = app.post(redirectUrl, data = redirectParams).document
36+
37+ // starting here, this works similar to many other extractors like StreamWish
38+ val extractedpack =
39+ response.selectFirst(" script:containsData(function(p,a,c,k,e,d))" )?.data()
40+ if (extractedpack == null ) {
41+ Log .e(" up4stream" , " file not ready: delay too short" )
42+ }
43+
44+ JsUnpacker (extractedpack).unpack()?.let { unPacked ->
45+ Regex (" sources:\\ [\\ {file:\" (.*?)\" " ).find(unPacked)?.groupValues?.get(1 )?.let { link ->
46+ return listOf (
47+ newExtractorLink(
48+ this .name,
49+ this .name,
50+ link,
51+ ) {
52+ this .referer = referer.orEmpty()
53+ this .quality = Qualities .Unknown .value
54+ }
55+ )
56+ }
57+ }
58+ return null
59+ }
60+ }
0 commit comments