From 75968ff09515d80dea47d39ea70e825ac5fc9ea9 Mon Sep 17 00:00:00 2001 From: Jace <54625750+Jacekun@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:03:14 +0800 Subject: [PATCH] Update PluginManager.kt --- .../cloudstream3/plugins/PluginManager.kt | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) 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 0dee57eb..3f0054f5 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/plugins/PluginManager.kt @@ -289,7 +289,7 @@ object PluginManager { * 2. Fetch all not downloaded plugins * 3. Download them and reload plugins **/ - fun downloadNotExistingPluginsAndLoad(activity: Activity) { + fun downloadNotExistingPluginsAndLoad(activity: Activity, mode: AutoDownloadMode) { val newDownloadPlugins = mutableListOf() val urls = (getKey>(REPOSITORIES_KEY) ?: emptyArray()) + PREBUILT_REPOSITORIES @@ -303,6 +303,8 @@ object PluginManager { // Iterate online repos and returns not downloaded plugins val notDownloadedPlugins = onlinePlugins.mapNotNull { onlineData -> val sitePlugin = onlineData.second + val tvtypes = sitePlugin.tvTypes ?: listOf() + //Don't include empty urls if (sitePlugin.url.isBlank()) { return@mapNotNull null @@ -317,22 +319,29 @@ object PluginManager { return@mapNotNull null } - //Omit lang not selected on language setting - val lang = sitePlugin.language ?: return@mapNotNull null - //If set to 'universal', don't skip any language - if (!providerLang.contains(AllLanguagesName) && !providerLang.contains(lang)) { - return@mapNotNull null - } - //Log.i(TAG, "sitePlugin lang => $lang") - - //Omit NSFW, if disabled - sitePlugin.tvTypes?.let { tvtypes -> - if (!settingsForProvider.enableAdult) { - if (tvtypes.contains(TvType.NSFW.name)) { - return@mapNotNull null - } + //Omit non-NSFW if mode is set to NSFW only + if (mode == AutoDownloadMode.NsfwOnly) { + if (tvtypes.contains(TvType.NSFW.name) == false) { + return@mapNotNull null } } + //Omit NSFW, if disabled + if (!settingsForProvider.enableAdult) { + if (tvtypes.contains(TvType.NSFW.name)) { + return@mapNotNull null + } + } + + //Omit lang not selected on language setting + if (mode == AutoDownloadMode.FilterByLang) { + val lang = sitePlugin.language ?: return@mapNotNull null + //If set to 'universal', don't skip any language + if (!providerLang.contains(AllLanguagesName) && !providerLang.contains(lang)) { + return@mapNotNull null + } + //Log.i(TAG, "sitePlugin lang => $lang") + } + val savedData = PluginData( url = sitePlugin.url, internalName = sitePlugin.internalName, @@ -692,4 +701,4 @@ object PluginManager { return null } } -} \ No newline at end of file +}