From 8c87cd36bcaef238b1d1bbeef1488486afac7cbc Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:17:29 +0200 Subject: [PATCH 1/4] add unload log --- .../java/com/lagradost/cloudstream3/plugins/PluginManager.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt index f9aa7cdd..58151019 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -280,6 +280,7 @@ object PluginManager { } private suspend fun unloadPlugin(absolutePath: String) { + Log.i(TAG, "Unloading plugin: $absolutePath") var plugin = plugins.get(absolutePath) if (plugin == null) { Log.w(TAG, "Couldn't find plugin $absolutePath") From 38f251339d6384109c9c156d85d81d8ac7f28fd6 Mon Sep 17 00:00:00 2001 From: C10udburst <18114966+C10udburst@users.noreply.github.com> Date: Tue, 9 Aug 2022 17:03:58 +0200 Subject: [PATCH 2/4] fix online plugins and update unloading --- .../com/lagradost/cloudstream3/plugins/PluginManager.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt index 58151019..3b515e64 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -24,6 +24,7 @@ import com.lagradost.cloudstream3.ui.settings.extensions.REPOSITORIES_KEY import com.lagradost.cloudstream3.ui.settings.extensions.RepositoryData import com.lagradost.cloudstream3.utils.VideoDownloadManager.sanitizeFilename import com.lagradost.cloudstream3.APIHolder +import com.lagradost.cloudstream3.APIHolder.removePluginMapping import com.lagradost.cloudstream3.MainAPI import com.lagradost.cloudstream3.utils.ExtractorApi import com.lagradost.cloudstream3.utils.extractorApis @@ -139,7 +140,7 @@ object PluginManager { * 4. Else load the plugin normally **/ fun updateAllOnlinePluginsAndLoadThem(activity: Activity) { - val urls = getKey>(REPOSITORIES_KEY) ?: emptyArray() + val urls = (getKey>(REPOSITORIES_KEY) ?: emptyArray()) + PREBUILT_REPOSITORIES val onlinePlugins = urls.toList().apmap { getRepoPlugins(it.url)?.toList() ?: emptyList() @@ -294,9 +295,14 @@ object PluginManager { } // remove all registered apis + APIHolder.apis.filter { it -> it.sourcePlugin == plugin.__filename }.forEach { + removePluginMapping(it) + } APIHolder.allProviders.removeIf { provider: MainAPI -> provider.sourcePlugin == plugin.`__filename` } extractorApis.removeIf { provider: ExtractorApi -> provider.sourcePlugin == plugin.`__filename` } + classLoaders.values.removeIf { v -> v == plugin} + plugins.remove(absolutePath) } From 15f0ba12d1c6d1b717a189354f447b6ce12184f6 Mon Sep 17 00:00:00 2001 From: C10udburst <18114966+C10udburst@users.noreply.github.com> Date: Tue, 9 Aug 2022 17:19:26 +0200 Subject: [PATCH 3/4] smol cleanup --- .idea/codeStyles/Project.xml | 123 ++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .../lagradost/cloudstream3/plugins/Plugin.kt | 11 +- .../cloudstream3/plugins/PluginManager.kt | 7 +- .../cloudstream3/plugins/RepositoryManager.kt | 8 +- .../ui/settings/extensions/PluginAdapter.kt | 2 +- 6 files changed, 142 insertions(+), 14 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..7643783a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,123 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..79ee123c --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt index 204119de..08b20dd9 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt @@ -8,6 +8,7 @@ import com.lagradost.cloudstream3.APIHolder import com.lagradost.cloudstream3.utils.ExtractorApi import com.lagradost.cloudstream3.utils.extractorApis import android.util.Log +import com.fasterxml.jackson.annotation.JsonProperty const val PLUGIN_TAG = "PluginInstance" @@ -33,7 +34,7 @@ abstract class Plugin { */ fun registerMainAPI(element: MainAPI) { Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI") - element.sourcePlugin = this.`__filename` + element.sourcePlugin = this.__filename APIHolder.allProviders.add(element) APIHolder.addPluginMapping(element) } @@ -44,14 +45,14 @@ abstract class Plugin { */ fun registerExtractorAPI(element: ExtractorApi) { Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) ExtractorApi") - element.sourcePlugin = this.`__filename` + element.sourcePlugin = this.__filename extractorApis.add(element) } class Manifest { - var name: String? = null - var pluginClassName: String? = null - var pluginVersion: Int? = null + @JsonProperty("name") var name: String? = null + @JsonProperty("pluginClassName") var pluginClassName: String? = null + @JsonProperty("version") var version: Int? = null } var resources: Resources? = null diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt index 3b515e64..f293b153 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -1,6 +1,5 @@ package com.lagradost.cloudstream3.plugins -import android.content.Context import dalvik.system.PathClassLoader import com.google.gson.Gson import android.content.res.AssetManager @@ -237,7 +236,7 @@ object PluginManager { } val name: String = manifest.name ?: "NO NAME" - val version: Int = manifest.pluginVersion ?: PLUGIN_VERSION_NOT_SET + val version: Int = manifest.version ?: PLUGIN_VERSION_NOT_SET val pluginClass: Class<*> = loader.loadClass(manifest.pluginClassName) as Class val pluginInstance: Plugin = @@ -298,8 +297,8 @@ object PluginManager { APIHolder.apis.filter { it -> it.sourcePlugin == plugin.__filename }.forEach { removePluginMapping(it) } - APIHolder.allProviders.removeIf { provider: MainAPI -> provider.sourcePlugin == plugin.`__filename` } - extractorApis.removeIf { provider: ExtractorApi -> provider.sourcePlugin == plugin.`__filename` } + APIHolder.allProviders.removeIf { provider: MainAPI -> provider.sourcePlugin == plugin.__filename } + extractorApis.removeIf { provider: ExtractorApi -> provider.sourcePlugin == plugin.__filename } classLoaders.values.removeIf { v -> v == plugin} diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt index d218accc..e2209ab7 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/RepositoryManager.kt @@ -62,11 +62,11 @@ data class SitePlugin( // Might be used to go directly to the plugin repo in the future @JsonProperty("repositoryUrl") val repositoryUrl: String?, // These types are yet to be mapped and used, ignore for now - @JsonProperty("tvTypes") val tvTypes: List?, - @JsonProperty("language") val language: String?, - @JsonProperty("iconUrl") val iconUrl: String?, +// @JsonProperty("tvTypes") val tvTypes: List?, +// @JsonProperty("language") val language: String?, +// @JsonProperty("iconUrl") val iconUrl: String?, // Set to true to get an 18+ symbol next to the plugin - @JsonProperty("isAdult") val isAdult: Boolean?, + @JsonProperty("adult") val adult: Boolean?, ) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt index 6dce0682..196bc93d 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/extensions/PluginAdapter.kt @@ -73,7 +73,7 @@ class PluginAdapter( R.drawable.ic_baseline_delete_outline_24 else R.drawable.netflix_download - itemView.nsfw_marker?.isVisible = metadata.isAdult == true + itemView.nsfw_marker?.isVisible = metadata.adult == true itemView.action_button?.setImageResource(drawableInt) itemView.action_button?.setOnClickListener { From 90be3b3401b990203b6cb51833c887bdb88c1828 Mon Sep 17 00:00:00 2001 From: C10udburst <18114966+C10udburst@users.noreply.github.com> Date: Tue, 9 Aug 2022 18:14:36 +0200 Subject: [PATCH 4/4] resources loading --- app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt | 2 +- .../java/com/lagradost/cloudstream3/plugins/PluginManager.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt index 08b20dd9..89ebdaa0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/Plugin.kt @@ -53,9 +53,9 @@ abstract class Plugin { @JsonProperty("name") var name: String? = null @JsonProperty("pluginClassName") var pluginClassName: String? = null @JsonProperty("version") var version: Int? = null + @JsonProperty("requiresResources") var requiresResources: Boolean = false } var resources: Resources? = null - var needsResources = false var __filename: String? = null } \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt index f293b153..8a942522 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -251,7 +251,8 @@ object PluginManager { } pluginInstance.__filename = fileName - if (pluginInstance.needsResources) { + if (manifest.requiresResources) { + Log.d(TAG, "Loading resources for ${data.internalName}") // based on https://stackoverflow.com/questions/7483568/dynamic-resource-loading-from-other-apk val assets = AssetManager::class.java.newInstance() val addAssetPath =