Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.lagradost.cloudstream3.extractors
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.utils.ExtractorApi
import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.JsContext
import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.evalJs
import com.lagradost.cloudstream3.utils.newExtractorLink

class Watchadsontape : StreamTape() {
Expand Down Expand Up @@ -33,11 +33,8 @@ open class StreamTape : ExtractorApi() {
val result =
this.document.select("script").firstOrNull { it.html().contains("botlink').innerHTML") }
?.html()?.lines()?.firstOrNull { it.contains("botlink').innerHTML") }?.let {
val scriptContent =
it.substringAfter(").innerHTML").replaceFirst("=", "var url =")
val ctx = JsContext()
ctx.eval(scriptContent)
ctx["url"]?.toString() ?: ""
val scriptContent = it.substringAfter(").innerHTML").replaceFirst("=", "var url =")
evalJs(scriptContent, "url")?.toString()
}

if (!result.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,22 @@ class JsContext {
}

/**
* Evaluate [js] and return its last value. Convenience wrapper for one-shot
* evaluations, equivalent to the old `rhino.evaluateString(scope, js, ...)`.
* Evaluate [js] and return its last value, or the value of [variable] if specified.
* Convenience wrapper for one-shot evaluations, equivalent to the old
* `rhino.evaluateString(scope, js, ...)`.
*
* @param js The JavaScript code to evaluate.
* @param variable Optional variable name to retrieve from the scope after evaluation.
* @return The last expression value, or the named variable value if [variable] is specified.
* Returns [Unit] on evaluation failure or when the result is JS undefined.
* JS null is represented as Kotlin null. Use [jsValueToString] to convert to a JS string.
*/
@Prerelease
fun evalJs(js: String): Any? = JsInterpreter().eval(js)
fun evalJs(js: String, variable: String? = null): Any? {
val interpreter = JsInterpreter()
val result = interpreter.eval(js)
return if (variable != null) interpreter.getVar(variable) else result
}

private enum class TT {
NUMBER, STRING, IDENT, PLUS, MINUS, STAR, SLASH, PERCENT, EQ, EQEQ, EQEQEQ,
Expand Down