diff --git a/inspector/build.gradle.kts b/inspector/build.gradle.kts index 20c9004..8555d25 100644 --- a/inspector/build.gradle.kts +++ b/inspector/build.gradle.kts @@ -40,7 +40,7 @@ sourceSets { } // should be bumped with each stable release -val inspectorVersion = "v1.4.3" +val inspectorVersion = "v1.4.4" // counts commit count on master val inspectorRevision = runCatching { diff --git a/inspector/src/main/kotlin/eu/kanade/tachiyomi/animesource/UnmeteredSource.kt b/inspector/src/main/kotlin/eu/kanade/tachiyomi/animesource/UnmeteredSource.kt new file mode 100644 index 0000000..840a223 --- /dev/null +++ b/inspector/src/main/kotlin/eu/kanade/tachiyomi/animesource/UnmeteredSource.kt @@ -0,0 +1,8 @@ +package eu.kanade.tachiyomi.animesource + +/** + * A source that explicitly doesn't require traffic considerations. + * + * This typically applies for self-hosted sources. + */ +interface UnmeteredSource diff --git a/inspector/src/main/kotlin/inspector/Main.kt b/inspector/src/main/kotlin/inspector/Main.kt index 55be0e5..03cd558 100644 --- a/inspector/src/main/kotlin/inspector/Main.kt +++ b/inspector/src/main/kotlin/inspector/Main.kt @@ -12,6 +12,9 @@ import eu.kanade.tachiyomi.App import eu.kanade.tachiyomi.animesource.online.AnimeHttpSource import inspector.util.AnimeExtension import io.github.oshai.kotlinlogging.KotlinLogging +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -47,11 +50,15 @@ suspend fun main(args: Array) { logger.info { "Found ${extensions.size} extensions" } - val extensionsInfo = extensions.associate { - logger.debug { "Installing $it" } - val (pkgName, sources) = AnimeExtension.installApk(tmpDir) { it.toFile() } - pkgName to sources.map(::SourceJson) - } + val extensionsInfo = coroutineScope { + extensions.map { + async { + logger.debug { "Installing $it" } + val (pkgName, sources) = AnimeExtension.installApk(tmpDir) { it.toFile() } + pkgName to sources.map(::SourceJson) + } + }.awaitAll() + }.toMap() File(outputPath).writeText(Json.encodeToString(extensionsInfo)) } diff --git a/inspector/src/main/kotlin/inspector/util/AnimeExtension.kt b/inspector/src/main/kotlin/inspector/util/AnimeExtension.kt index 55a27b2..7504759 100644 --- a/inspector/src/main/kotlin/inspector/util/AnimeExtension.kt +++ b/inspector/src/main/kotlin/inspector/util/AnimeExtension.kt @@ -57,7 +57,7 @@ object AnimeExtension { dex2jar(apkFile, jarFile) // 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, className)) { is AnimeSource -> listOf(instance).filterIsInstance() is AnimeSourceFactory -> instance.createSources().filterIsInstance() else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}") diff --git a/inspector/src/main/kotlin/inspector/util/PackageTools.kt b/inspector/src/main/kotlin/inspector/util/PackageTools.kt index 198932e..afa38a4 100644 --- a/inspector/src/main/kotlin/inspector/util/PackageTools.kt +++ b/inspector/src/main/kotlin/inspector/util/PackageTools.kt @@ -21,7 +21,6 @@ import org.w3c.dom.Node import xyz.nulldev.androidcompat.pm.InstalledPackage.Companion.toList import xyz.nulldev.androidcompat.pm.toPackageInfo import java.io.File -import java.net.URL import java.net.URLClassLoader import java.nio.file.Files import javax.xml.parsers.DocumentBuilderFactory @@ -107,8 +106,8 @@ object PackageTools { * loads the extension main class called $className from the jar located at $jarPath * It may return an instance of AnimeHttpSource or AnimeSourceFactory depending on the extension. */ - fun loadExtensionSources(jarPath: String, className: String): Any { - val classLoader = URLClassLoader(arrayOf(URL("file:$jarPath"))) + fun loadExtensionSources(jarFile: File, className: String): Any { + val classLoader = URLClassLoader(arrayOf(jarFile.toURI().toURL())) val classToLoad = Class.forName(className, false, classLoader) return classToLoad.getDeclaredConstructor().newInstance() }