mirror of
https://github.com/tachiyomiorg/tachiyomi-extensions-inspector.git
synced 2025-01-13 17:29:07 +01:00
BaseUrl and Nsfw support, and bugfixes (#2)
* Better logging * Fix jq rounding errors * Add baseUrl and nsfw support * Add support for SourceFactory Nsfw annotation
This commit is contained in:
parent
737b74af2a
commit
dbf6996744
@ -7,14 +7,17 @@ package suwayomi.tachidesk
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import mu.KotlinLogging
|
||||||
|
import suwayomi.tachidesk.manga.impl.extension.Extension
|
||||||
import suwayomi.tachidesk.manga.impl.extension.Extension.installAPK
|
import suwayomi.tachidesk.manga.impl.extension.Extension.installAPK
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object InspectorMain {
|
object InspectorMain {
|
||||||
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
suspend fun inspectorMain(args: Array<String>) {
|
suspend fun inspectorMain(args: Array<String>) {
|
||||||
if (args.size < 3) {
|
if (args.size < 3) {
|
||||||
throw RuntimeException("Inspector must be given the path of apks directory, output json, and a tmp dir")
|
throw RuntimeException("Inspector must be given the path of apks directory, output json, and a tmp dir")
|
||||||
@ -27,7 +30,7 @@ object InspectorMain {
|
|||||||
val tmpDir = File(tmpDirPath, "tmp").also { it.mkdir() }
|
val tmpDir = File(tmpDirPath, "tmp").also { it.mkdir() }
|
||||||
val extensions = File(apksPath).listFiles().orEmpty().mapNotNull {
|
val extensions = File(apksPath).listFiles().orEmpty().mapNotNull {
|
||||||
if (it.extension == "apk") {
|
if (it.extension == "apk") {
|
||||||
println("Installing ${it.absolutePath}")
|
logger.info("Installing ${it.absolutePath}")
|
||||||
|
|
||||||
val (pkgName, sources) = installAPK(tmpDir) {
|
val (pkgName, sources) = installAPK(tmpDir) {
|
||||||
it
|
it
|
||||||
@ -43,9 +46,17 @@ object InspectorMain {
|
|||||||
data class SourceJson(
|
data class SourceJson(
|
||||||
val name: String,
|
val name: String,
|
||||||
val lang: String,
|
val lang: String,
|
||||||
val id: Long
|
val id: String,
|
||||||
|
val baseUrl: String,
|
||||||
|
val nsfw: Boolean
|
||||||
) {
|
) {
|
||||||
constructor(source: CatalogueSource) :
|
constructor(loadedSource: Extension.LoadedSource) :
|
||||||
this(source.name, source.lang, source.id)
|
this(
|
||||||
|
loadedSource.source.name,
|
||||||
|
loadedSource.source.lang,
|
||||||
|
loadedSource.source.id.toString(),
|
||||||
|
loadedSource.source.baseUrl,
|
||||||
|
loadedSource.isNsfw
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ package suwayomi.tachidesk.manga.impl.extension
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
import eu.kanade.tachiyomi.annotations.Nsfw
|
||||||
import eu.kanade.tachiyomi.source.Source
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.source.SourceFactory
|
import eu.kanade.tachiyomi.source.SourceFactory
|
||||||
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import mu.KotlinLogging
|
import mu.KotlinLogging
|
||||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.EXTENSION_FEATURE
|
import suwayomi.tachidesk.manga.impl.util.PackageTools.EXTENSION_FEATURE
|
||||||
import suwayomi.tachidesk.manga.impl.util.PackageTools.LIB_VERSION_MAX
|
import suwayomi.tachidesk.manga.impl.util.PackageTools.LIB_VERSION_MAX
|
||||||
@ -23,7 +24,22 @@ import java.io.File
|
|||||||
object Extension {
|
object Extension {
|
||||||
private val logger = KotlinLogging.logger {}
|
private val logger = KotlinLogging.logger {}
|
||||||
|
|
||||||
suspend fun installAPK(tmpDir: File, fetcher: suspend () -> File): Pair<String, List<CatalogueSource>> {
|
fun isNsfw(sourceInstance: Any): Boolean {
|
||||||
|
// Annotations are proxied, hence this janky way of checking for them
|
||||||
|
return sourceInstance.javaClass.annotations
|
||||||
|
.flatMap { it.javaClass.interfaces.map { it.simpleName } }
|
||||||
|
.firstOrNull { it == Nsfw::class.java.simpleName } != null
|
||||||
|
}
|
||||||
|
|
||||||
|
data class LoadedSource(
|
||||||
|
val source: HttpSource,
|
||||||
|
val isNsfw: Boolean
|
||||||
|
) {
|
||||||
|
constructor(source: HttpSource) :
|
||||||
|
this(source, isNsfw(source))
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun installAPK(tmpDir: File, fetcher: suspend () -> File): Pair<String, List<LoadedSource>> {
|
||||||
val apkFile = fetcher()
|
val apkFile = fetcher()
|
||||||
|
|
||||||
val jarFile = File(tmpDir, "${apkFile.nameWithoutExtension}.jar")
|
val jarFile = File(tmpDir, "${apkFile.nameWithoutExtension}.jar")
|
||||||
@ -60,9 +76,20 @@ object Extension {
|
|||||||
|
|
||||||
// collect sources from the extension
|
// collect sources from the extension
|
||||||
return packageInfo.packageName to when (val instance = loadExtensionSources(jarFile.absolutePath, className)) {
|
return packageInfo.packageName to when (val instance = loadExtensionSources(jarFile.absolutePath, className)) {
|
||||||
is Source -> listOf(instance)
|
is Source -> listOf(instance).filterIsInstance<HttpSource>()
|
||||||
is SourceFactory -> instance.createSources()
|
.map { LoadedSource(it) }
|
||||||
|
is SourceFactory -> {
|
||||||
|
val isNsfw = isNsfw(instance)
|
||||||
|
instance.createSources().filterIsInstance<HttpSource>()
|
||||||
|
.map {
|
||||||
|
if (isNsfw) {
|
||||||
|
LoadedSource(it, true)
|
||||||
|
} else {
|
||||||
|
LoadedSource(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}")
|
else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}")
|
||||||
}.filterIsInstance<CatalogueSource>()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ object PackageTools {
|
|||||||
dBuilder.parse(it)
|
dBuilder.parse(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(parsed.manifestXml)
|
logger.trace(parsed.manifestXml)
|
||||||
|
|
||||||
applicationInfo.metaData = Bundle().apply {
|
applicationInfo.metaData = Bundle().apply {
|
||||||
val appTag = doc.getElementsByTagName("application").item(0)
|
val appTag = doc.getElementsByTagName("application").item(0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user