Skip to content

Commit

Permalink
Merge branch 'Kohi-den:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefFStraka authored Jan 7, 2025
2 parents 63a007d + af5a62b commit 39d61a1
Show file tree
Hide file tree
Showing 54 changed files with 2,104 additions and 687 deletions.
1 change: 1 addition & 0 deletions lib/megacloud-extractor/src/main/assets/crypto-js.js

Large diffs are not rendered by default.

606 changes: 606 additions & 0 deletions lib/megacloud-extractor/src/main/assets/megacloud.decodedpng.js

Large diffs are not rendered by default.

714 changes: 714 additions & 0 deletions lib/megacloud-extractor/src/main/assets/megacloud.getsrcs.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MegaCloudExtractor(
private val json: Json by injectLazy()

private val playlistUtils by lazy { PlaylistUtils(client, headers) }
private val webViewResolver by lazy { WebViewResolver(headers) }

private val cacheControl = CacheControl.Builder().noStore().build()
private val noCacheClient = client.newBuilder()
Expand Down Expand Up @@ -141,10 +142,16 @@ class MegaCloudExtractor(

private fun getVideoDto(url: String): VideoDto {
val type = if (url.startsWith("https://megacloud.tv")) 0 else 1

val keyType = SOURCES_KEY[type]

val id = url.substringAfter(SOURCES_SPLITTER[type], "")
.substringBefore("?", "").ifEmpty { throw Exception("I HATE THE ANTICHRIST") }

if (type == 0) {
return webViewResolver.getSources(id)!!
}

val srcRes = client.newCall(GET(SERVER_URL[type] + SOURCES_URL[type] + id))
.execute()
.body.string()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package eu.kanade.tachiyomi.lib.megacloudextractor

import android.annotation.SuppressLint
import android.app.Application
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.webkit.ConsoleMessage
import android.webkit.JavascriptInterface
import android.webkit.WebChromeClient
import android.webkit.WebView
import android.webkit.WebViewClient
import eu.kanade.tachiyomi.lib.megacloudextractor.MegaCloudExtractor.VideoDto
import kotlinx.serialization.json.Json
import okhttp3.Headers
import uy.kohesive.injekt.injectLazy
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

class WebViewResolver(private val globalHeaders: Headers) {
private val context: Application by injectLazy()
private val handler by lazy { Handler(Looper.getMainLooper()) }
private val json: Json by injectLazy()
private val tag by lazy { javaClass.simpleName }

class JsInterface(private val latch: CountDownLatch) {
var result: String? = null

@JavascriptInterface
fun setResponse(response: String) {
Log.d("WebViewResolver", "script result: $response")
result = response
latch.countDown()
}
}

fun getJsContent(file: String): String {
return javaClass.getResource(file)!!.readText()
}

@SuppressLint("SetJavaScriptEnabled")
fun getSources(xrax: String): VideoDto? {
val latch = CountDownLatch(1)
var webView: WebView? = null
val jsi = JsInterface(latch)

handler.post {
val webview = WebView(context)
webView = webview
with(webview.settings) {
javaScriptEnabled = true
domStorageEnabled = true
databaseEnabled = true
useWideViewPort = false
loadWithOverviewMode = false
userAgentString = globalHeaders["User-Agent"]
}

webview.addJavascriptInterface(jsi, "jsinterface")

webview.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView?, url: String?) {
Log.d(tag, "onPageFinished $url")
super.onPageFinished(view, url)

Log.d(tag, "injecting scripts")
view?.evaluateJavascript(getJsContent("/assets/crypto-js.js")) {}
view?.evaluateJavascript(getJsContent("/assets/megacloud.decodedpng.js")) {}
view?.evaluateJavascript(getJsContent("/assets/megacloud.getsrcs.js")) {}

Log.d(tag, "running script")
view?.evaluateJavascript(
"getSources(\"${xrax}\")" +
".then( s => jsinterface.setResponse( JSON.stringify(s) ) )",
) {}
}
}

webview.webChromeClient = object : WebChromeClient() {
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
Log.d(
tag,
"Chrome: [${consoleMessage?.messageLevel()}]" +
"${consoleMessage?.message()}" +
" at ${consoleMessage?.lineNumber()}" +
" in ${consoleMessage?.sourceId()}",
)
return super.onConsoleMessage(consoleMessage)
}
}

val headers = mapOf("X-Requested-With" to "org.lineageos.jelly")

webView?.loadUrl("https://megacloud.tv/about", headers)
}

latch.await(TIMEOUT_SEC, TimeUnit.SECONDS)

handler.post {
webView?.stopLoading()
webView?.destroy()
webView = null
}

return jsi.result?.let { json.decodeFromString<VideoDto>(it) }
}

companion object {
const val TIMEOUT_SEC: Long = 30
}
}
5 changes: 3 additions & 2 deletions src/all/hikari/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ext {
extName = 'Hikari'
extClass = '.Hikari'
extVersionCode = 11
extVersionCode = 12
}

apply from: "$rootDir/common.gradle"

dependencies {
implementation(project(':lib:chillx-extractor'))
implementation(project(':lib:filemoon-extractor'))
implementation(project(':lib:streamwish-extractor'))
implementation(project(':lib:vidhide-extractor'))
implementation(project(':lib:chillx-extractor'))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
import eu.kanade.tachiyomi.lib.chillxextractor.ChillxExtractor
import eu.kanade.tachiyomi.lib.filemoonextractor.FilemoonExtractor
import eu.kanade.tachiyomi.lib.streamwishextractor.StreamWishExtractor
import eu.kanade.tachiyomi.lib.vidhideextractor.VidHideExtractor
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
Expand Down Expand Up @@ -220,6 +221,7 @@ class Hikari : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
private val filemoonExtractor by lazy { FilemoonExtractor(client) }
private val vidHideExtractor by lazy { VidHideExtractor(client, headers) }
private val chillxExtractor by lazy { ChillxExtractor(client, headers) }
private val streamwishExtractor by lazy { StreamWishExtractor(client, headers) }
private val embedRegex = Regex("""getEmbed\(\s*(\d+)\s*,\s*(\d+)\s*,\s*'(\d+)'""")

override fun videoListRequest(episode: SEpisode): Request {
Expand Down Expand Up @@ -328,17 +330,19 @@ class Hikari : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
}.filter { it.first.isNotEmpty() }
}

val embedUrls = sdEmbedUrls.ifEmpty {
subEmbedUrls + dubEmbedUrls
}
return embedUrls.parallelCatchingFlatMapBlocking {
return sdEmbedUrls.parallelCatchingFlatMapBlocking {
getVideosFromEmbed(it.first, it.second)
}.ifEmpty {
(subEmbedUrls + dubEmbedUrls).parallelCatchingFlatMapBlocking {
getVideosFromEmbed(it.first, it.second)
}
}
}

private fun getVideosFromEmbed(embedUrl: String, name: String): List<Video> = when {
name.contains("vidhide", true) -> vidHideExtractor.videosFromUrl(embedUrl, videoNameGen = { s -> "$name - $s" })
embedUrl.contains("filemoon", true) -> filemoonExtractor.videosFromUrl(embedUrl, prefix = "$name - ", headers = headers)
name.contains("streamwish", true) -> streamwishExtractor.videosFromUrl(embedUrl, prefix = "$name - ")
else -> chillxExtractor.videoFromUrl(embedUrl, referer = baseUrl, prefix = "$name - ")
}

Expand Down
2 changes: 1 addition & 1 deletion src/all/jable/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Jable'
extClass = '.JableFactory'
extVersionCode = 1
extVersionCode = 2
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Jable(override val lang: String) : AnimeHttpSource() {
private var tagsUpdated = false

override fun animeDetailsRequest(anime: SAnime): Request {
return GET("$baseUrl${anime.url}?lang=$lang", headers)
return GET("$baseUrl${anime.url}?lang=${lang.toRequestLang()}", headers)
}

override fun animeDetailsParse(response: Response): SAnime {
Expand Down Expand Up @@ -88,7 +88,7 @@ class Jable(override val lang: String) : AnimeHttpSource() {
title = it.select(".detail .title").text()
}
},
doc.select(".container .pagination .page-item .page-link.disabled").isNullOrEmpty(),
true,
)
}

Expand Down Expand Up @@ -125,7 +125,7 @@ class Jable(override val lang: String) : AnimeHttpSource() {
): Request {
val urlBuilder = baseUrl.toHttpUrl().newBuilder()
.addPathSegments("$path/")
.addQueryParameter("lang", lang)
.addQueryParameter("lang", lang.toRequestLang())
if (tagsUpdated) {
// load whole page for update filter tags info
urlBuilder.addQueryParameter("mode", "async")
Expand Down Expand Up @@ -204,6 +204,11 @@ class Jable(override val lang: String) : AnimeHttpSource() {
return false
}

private fun String.toRequestLang(): String {
if (this == "ja") return "jp"
return this
}

private val intl by lazy {
JableIntl(lang)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class JableFactory : AnimeSourceFactory {
return listOf(
Jable("zh"),
Jable("en"),
Jable("jp"),
Jable("ja"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class JableIntl private constructor(delegate: Intl) : Intl by delegate
constructor(lang: String) : this(
when (lang) {
"zh" -> ZH()
"jp" -> JP()
"ja" -> JA()
"en" -> EN()
else -> ZH()
},
Expand All @@ -43,7 +43,7 @@ internal class ZH : Intl {
override val filterTagTitle: String = "標籤"
}

internal class JP : Intl {
internal class JA : Intl {
override val popular: String = "人気優先"
override val latestUpdate: String = "新作優先"
override val sortLatestUpdate: String = "最近更新"
Expand Down
4 changes: 2 additions & 2 deletions src/de/serienstream/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Serienstream'
extClass = '.Serienstream'
extVersionCode = 19
extVersionCode = 20
}

apply from: "$rootDir/common.gradle"
Expand All @@ -10,4 +10,4 @@ dependencies {
implementation(project(':lib:voe-extractor'))
implementation(project(':lib:streamtape-extractor'))
implementation(project(':lib:dood-extractor'))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Serienstream : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val name = "Serienstream"

override val baseUrl = "http://186.2.175.5"
override val baseUrl = "https://s.to"

override val lang = "de"

Expand Down Expand Up @@ -91,7 +91,7 @@ class Serienstream : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val headers = Headers.Builder()
.add("Referer", "http://186.2.175.5/search")
.add("Referer", "https://s.to/search")
.add("origin", baseUrl)
.add("connection", "keep-alive")
.add("user-agent", "Mozilla/5.0 (Linux; Android 12; Pixel 5 Build/SP2A.220405.004; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/100.0.4896.127 Safari/537.36")
Expand Down
2 changes: 1 addition & 1 deletion src/en/kaido/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext {
extClass = '.Kaido'
themePkg = 'zorotheme'
baseUrl = 'https://kaido.to'
overrideVersionCode = 6
overrideVersionCode = 7
}

apply from: "$rootDir/common.gradle"
2 changes: 1 addition & 1 deletion src/en/rule34video/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Rule34Video'
extClass = '.Rule34Video'
extVersionCode = 8
extVersionCode = 9
isNsfw = true
}

Expand Down
Loading

0 comments on commit 39d61a1

Please sign in to comment.