Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge upstream #2

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inspector/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
17 changes: 12 additions & 5 deletions inspector/src/main/kotlin/inspector/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,11 +50,15 @@ suspend fun main(args: Array<String>) {

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))
}
Expand Down
2 changes: 1 addition & 1 deletion inspector/src/main/kotlin/inspector/util/AnimeExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnimeHttpSource>()
is AnimeSourceFactory -> instance.createSources().filterIsInstance<AnimeHttpSource>()
else -> throw RuntimeException("Unknown source class type! ${instance.javaClass}")
Expand Down
5 changes: 2 additions & 3 deletions inspector/src/main/kotlin/inspector/util/PackageTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>(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()
}
Expand Down
Loading