Skip to content

Commit

Permalink
fix [OnePace] (aniyomiorg#858)
Browse files Browse the repository at this point in the history
* fix [OnePace]

* fix but more elegant [OnePace]
  • Loading branch information
Diegopyl1209 authored Sep 12, 2022
1 parent 4082065 commit be441f9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/all/onepace/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ ext {
extName = 'Onepace'
pkgNameSuffix = 'all.onepace'
extClass = '.OnepaceFactory'
extVersionCode = 7
extVersionCode = 8
libVersion = '13'
containsNsfw = false
}

dependencies {
compileOnly libs.bundles.coroutines
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,10 @@ open class Onepace(override val lang: String, override val name: String) : Confi
override fun episodeFromElement(element: Element) = throw Exception("not used")

override fun videoListParse(response: Response): List<Video> {
// This is a shit but work
val realUrl = "https:" + response.request.url.toString().substringAfter("%23")
val hostUrl = realUrl.substringBefore("/v/")
val document = client.newCall(GET(realUrl)).execute().asJsoup()
// ZippyShare Scraper
val jscript = document.selectFirst("script:containsData(asdasd)").data()
val a = jscript.substringAfter("var a = ").substringBefore(";").toInt()
val firstB = jscript.substringAfter(".substr(").substringBefore(",").toInt()
val b = jscript.substringAfter(".substr($firstB, ").substringBefore(")").toInt() - firstB

val videoId = realUrl.substringAfter("/v/").substringBefore("/file")
val videoName = jscript.substringAfter("+\"").substringBefore("\";")
val videoUrl = "$hostUrl/d/$videoId/${(Math.pow(a.toDouble(),b.toDouble()).toInt() + b)}$videoName"

val videoUrlD = ZippyExtractor().getVideoUrl(realUrl, json)
val videoUrl = hostUrl + videoUrlD
return listOf(Video(videoUrl, "ZippyShare", videoUrl))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package eu.kanade.tachiyomi.animeextension.all.onepace

import app.cash.quickjs.QuickJs
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.jsoup.Jsoup

class ZippyExtractor {
fun getVideoUrl(url: String, json: Json): String {
val document = Jsoup.connect(url).get()
val jscript = document.selectFirst("script:containsData(dlbutton)").data()
.replace("document.getElementById('dlbutton').href", "a")
.replace("document.getElementById('fimage').href", "b")
.replace("document.getElementById('fimage')", "false")
val quickjs = QuickJs.create()
val objectA = quickjs.evaluate(objectScript(jscript)).toString()
quickjs.close()
return json.decodeFromString<JsonObject>(objectA)["a"]!!.jsonPrimitive.content
}

private fun objectScript(script: String) = """
$script;
let return_object = {a:a};
JSON.stringify(return_object);
"""
}

0 comments on commit be441f9

Please sign in to comment.