diff --git a/app/src/main/kotlin/ir/armor/tachidesk/Main.kt b/app/src/main/kotlin/ir/armor/tachidesk/Main.kt index 1e78d99..213a79a 100644 --- a/app/src/main/kotlin/ir/armor/tachidesk/Main.kt +++ b/app/src/main/kotlin/ir/armor/tachidesk/Main.kt @@ -1,56 +1,64 @@ package ir.armor.tachidesk +import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi +import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.model.MangasPage +import kotlinx.coroutines.runBlocking import okhttp3.Request +import okio.BufferedSink +import okio.buffer +import okio.sink import rx.Observable import java.io.File import java.net.URL import java.net.URLClassLoader +import kotlin.system.exitProcess class Main { companion object { @JvmStatic fun main(args: Array) { + val contentRoot = "/tmp/tachidesk" + File(contentRoot).mkdirs() + // get list of extensions var apkToDownload: String = "" -// runBlocking { -// val api = ExtensionGithubApi() -// apkToDownload = api.getApkUrl(api.findExtensions().first { -// api.getApkUrl(it).endsWith("killsixbilliondemons-v1.2.3.apk") -// }) -// } + runBlocking { + val api = ExtensionGithubApi() + apkToDownload = api.getApkUrl(api.findExtensions().first { + api.getApkUrl(it).endsWith("killsixbilliondemons-v1.2.3.apk") + }) + } apkToDownload = "https://raw.githubusercontent.com/inorichi/tachiyomi-extensions/repo/apk/tachiyomi-en.killsixbilliondemons-v1.2.3.apk" println(apkToDownload) val apkFileName = apkToDownload.split("/").last() - val apkFileDir = apkFileName.substringBefore(".apk") - val apkFileDirAbsolutePath = File("$apkFileDir.jar").absolutePath + val apkFilePath = "$contentRoot/$apkFileName" + val zipDirPath = apkFilePath.substringBefore(".apk") + val jarFilePath = "$contentRoot/$zipDirPath.jar" - val request = Request.Builder().url(apkToDownload) -// .addHeader("Content-Type", "application/json") - .build(); -// val response = NetworkHelper().client.newCall(request).execute(); -// println(response.code) -// -// val downloadedFile = File(apkFileName) -// val sink: BufferedSink = downloadedFile.sink().buffer() -// sink.writeAll(response.body!!.source()) -// sink.close() + val request = Request.Builder().url(apkToDownload).build() + val response = NetworkHelper().client.newCall(request).execute(); + println(response.code) -// Runtime.getRuntime().exec("unzip $apkFileName -d $apkFileDir") -// Runtime.getRuntime().exec("dex2jar $apkFileDir/classes.dex -o $apkFileDir.jar") + val downloadedFile = File(apkFilePath) + val sink: BufferedSink = downloadedFile.sink().buffer() + sink.writeAll(response.body!!.source()) + sink.close() - val child = URLClassLoader(arrayOf(URL("file:$apkFileDirAbsolutePath")), this.javaClass.classLoader) + Runtime.getRuntime().exec("unzip ${downloadedFile.absolutePath} -d $zipDirPath").waitFor() + Runtime.getRuntime().exec("dex2jar $zipDirPath/classes.dex -o $jarFilePath").waitFor() + + val child = URLClassLoader(arrayOf(URL("file:$jarFilePath")), this.javaClass.classLoader) val classToLoad = Class.forName("eu.kanade.tachiyomi.extension.en.killsixbilliondemons.KillSixBillionDemons", true, child) -// val method = classToLoad.getDeclaredMethod("fetchPopularManga") val instance = classToLoad.newInstance() as CatalogueSource -// val result = method.invoke(instance, 1) as Observable val result = instance.fetchPopularManga(1) val mangasPage = result.toBlocking().first() as MangasPage mangasPage.mangas.forEach{ println(it.title) } + exitProcess(0) } }