cloudstream icon indicating copy to clipboard operation
cloudstream copied to clipboard

Extractor: new VidSrcTo extractor

Open rushi-chavan opened this issue 1 year ago • 4 comments

This also creates NewVidplay extractor which is adaptive as you can pass hostUrl to it before calling getUrl to migrate changing domain URLs. NewVidplay().getUrl(.....)

rushi-chavan avatar Apr 16 '24 04:04 rushi-chavan

@fire-light42 can you please have a look now? I tried to reduce few if statements but if(status == 200) seems mandatory cause there is nothing to return when status != 200. so I don't understand the need of if (res.status != 200) return

rushi-chavan avatar Apr 17 '24 17:04 rushi-chavan

@fire-light42 can you please have a look now? I tried to reduce few if statements but if(status == 200) seems mandatory cause there is nothing to return when status != 200. so I don't understand the need of if (res.status != 200) return

You want to flatten the code as much as possible, here is an example on how I would do it

app.get(url).document.selectFirst("ul.episodes li a")?.attr("data-id")?.let { mediaId ->
    val res = app.get("$mainUrl/ajax/embed/episode/$mediaId/sources").parsedSafe<VidsrctoEpisodeSources>()
    if (res?.status == 200) {
        res.result?.amap { source ->
            val embedRes = app.get("$mainUrl/ajax/embed/source/${source.id}").parsedSafe<VidsrctoEmbedSource>()
            val finalUrl = DecryptUrl(embedRes?.result?.encUrl ?: "")
            when (source.title) {
                "Vidplay" -> AnyVidplay(finalUrl.substringBefore("/e/")).getUrl(finalUrl, referer, subtitleCallback, callback)
                "Filemoon" -> FileMoon().getUrl(finalUrl, referer, subtitleCallback, callback)
            }
        }
    }
}

into

val mediaId = app.get(url).document.selectFirst("ul.episodes li a")?.attr("data-id") ?: return
val res = app.get("$mainUrl/ajax/embed/episode/$mediaId/sources").parsedSafe<VidsrctoEpisodeSources>() ?: return
if (res.status != 200) return
res.result?.amap { source ->
    val embedRes = app.get("$mainUrl/ajax/embed/source/${source.id}").parsedSafe<VidsrctoEmbedSource>() ?: return@amap
    val finalUrl = DecryptUrl(embedRes.result.encUrl)
    when (source.title) {
        "Vidplay" -> AnyVidplay(finalUrl.substringBefore("/e/")).getUrl(finalUrl, referer, subtitleCallback, callback)
        "Filemoon" -> FileMoon().getUrl(finalUrl, referer, subtitleCallback, callback)
    }
}

fire-light42 avatar Apr 17 '24 18:04 fire-light42

@fire-light42 Thank you so much for telling me how to flat the code> I really appreciate your help. Please have a look at the updated changes and let me know if any issue with it.

Also, I am including another change related to TmdbProvider in this PR. https://github.com/recloudstream/cloudstream/pull/1044/commits/c363596d4f7fbf7afcd9ff5cf0cc2efff7e4ad85 Please have a look at this as well.

rushi-chavan avatar Apr 25 '24 01:04 rushi-chavan

Your commit to the TmdbProvider looks good, but I dont see the pr.

fire-light42 avatar Apr 25 '24 22:04 fire-light42

Good to go

rushi-chavan avatar May 04 '24 09:05 rushi-chavan