mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Feature: Refactor autodownload plugin to have multiple modes. (#518)
This commit is contained in:
parent
a8ed8773de
commit
827cbbb0b5
7 changed files with 78 additions and 27 deletions
|
@ -813,6 +813,18 @@ enum class TvType(value: Int?) {
|
||||||
Others(12)
|
Others(12)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum class AutoDownloadMode(val value: Int) {
|
||||||
|
Disable(0),
|
||||||
|
FilterByLang(1),
|
||||||
|
All(2),
|
||||||
|
NsfwOnly(3)
|
||||||
|
;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
infix fun getEnum(value: Int): AutoDownloadMode? = AutoDownloadMode.values().firstOrNull { it.value == value }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// IN CASE OF FUTURE ANIME MOVIE OR SMTH
|
// IN CASE OF FUTURE ANIME MOVIE OR SMTH
|
||||||
fun TvType.isMovieType(): Boolean {
|
fun TvType.isMovieType(): Boolean {
|
||||||
return this == TvType.Movie || this == TvType.AnimeMovie || this == TvType.Torrent || this == TvType.Live
|
return this == TvType.Movie || this == TvType.AnimeMovie || this == TvType.Torrent || this == TvType.Live
|
||||||
|
|
|
@ -1092,13 +1092,10 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
||||||
loadAllOnlinePlugins(this@MainActivity)
|
loadAllOnlinePlugins(this@MainActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Automatically download not existing plugins
|
//Automatically download not existing plugins, using mode specified.
|
||||||
if (settingsManager.getBoolean(
|
val auto_download_plugin = AutoDownloadMode.getEnum(settingsManager.getInt(getString(R.string.auto_download_plugins_key), 0)) ?: AutoDownloadMode.Disable
|
||||||
getString(R.string.auto_download_plugins_key),
|
if (auto_download_plugin != AutoDownloadMode.Disable) {
|
||||||
false
|
PluginManager.downloadNotExistingPluginsAndLoad(this@MainActivity, auto_download_plugin)
|
||||||
)
|
|
||||||
) {
|
|
||||||
PluginManager.downloadNotExistingPluginsAndLoad(this@MainActivity)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,7 @@ object PluginManager {
|
||||||
* 2. Fetch all not downloaded plugins
|
* 2. Fetch all not downloaded plugins
|
||||||
* 3. Download them and reload plugins
|
* 3. Download them and reload plugins
|
||||||
**/
|
**/
|
||||||
fun downloadNotExistingPluginsAndLoad(activity: Activity) {
|
fun downloadNotExistingPluginsAndLoad(activity: Activity, mode: AutoDownloadMode) {
|
||||||
val newDownloadPlugins = mutableListOf<String>()
|
val newDownloadPlugins = mutableListOf<String>()
|
||||||
val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY)
|
val urls = (getKey<Array<RepositoryData>>(REPOSITORIES_KEY)
|
||||||
?: emptyArray()) + PREBUILT_REPOSITORIES
|
?: emptyArray()) + PREBUILT_REPOSITORIES
|
||||||
|
@ -304,6 +304,8 @@ object PluginManager {
|
||||||
// Iterate online repos and returns not downloaded plugins
|
// Iterate online repos and returns not downloaded plugins
|
||||||
val notDownloadedPlugins = onlinePlugins.mapNotNull { onlineData ->
|
val notDownloadedPlugins = onlinePlugins.mapNotNull { onlineData ->
|
||||||
val sitePlugin = onlineData.second
|
val sitePlugin = onlineData.second
|
||||||
|
val tvtypes = sitePlugin.tvTypes ?: listOf()
|
||||||
|
|
||||||
//Don't include empty urls
|
//Don't include empty urls
|
||||||
if (sitePlugin.url.isBlank()) {
|
if (sitePlugin.url.isBlank()) {
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
|
@ -318,22 +320,29 @@ object PluginManager {
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
}
|
}
|
||||||
|
|
||||||
//Omit lang not selected on language setting
|
//Omit non-NSFW if mode is set to NSFW only
|
||||||
val lang = sitePlugin.language ?: return@mapNotNull null
|
if (mode == AutoDownloadMode.NsfwOnly) {
|
||||||
//If set to 'universal', don't skip any language
|
if (tvtypes.contains(TvType.NSFW.name) == false) {
|
||||||
if (!providerLang.contains(AllLanguagesName) && !providerLang.contains(lang)) {
|
return@mapNotNull null
|
||||||
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 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(
|
val savedData = PluginData(
|
||||||
url = sitePlugin.url,
|
url = sitePlugin.url,
|
||||||
internalName = sitePlugin.internalName,
|
internalName = sitePlugin.internalName,
|
||||||
|
@ -697,4 +706,4 @@ object PluginManager {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,10 +11,14 @@ import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.lagradost.cloudstream3.AcraApplication
|
||||||
|
import com.lagradost.cloudstream3.AutoDownloadMode
|
||||||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||||
import com.lagradost.cloudstream3.R
|
import com.lagradost.cloudstream3.R
|
||||||
|
import com.lagradost.cloudstream3.app
|
||||||
import com.lagradost.cloudstream3.databinding.LogcatBinding
|
import com.lagradost.cloudstream3.databinding.LogcatBinding
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
|
import com.lagradost.cloudstream3.network.initClient
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.getPref
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setPaddingBottom
|
||||||
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
|
||||||
|
@ -166,5 +170,25 @@ class SettingsUpdates : PreferenceFragmentCompat() {
|
||||||
}
|
}
|
||||||
return@setOnPreferenceClickListener true
|
return@setOnPreferenceClickListener true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPref(R.string.auto_download_plugins_key)?.setOnPreferenceClickListener {
|
||||||
|
val settingsManager = PreferenceManager.getDefaultSharedPreferences(it.context)
|
||||||
|
|
||||||
|
val prefNames = resources.getStringArray(R.array.auto_download_plugin)
|
||||||
|
val prefValues = enumValues<AutoDownloadMode>().sortedBy { x -> x.value }.map { x -> x.value }
|
||||||
|
|
||||||
|
val current = settingsManager.getInt(getString(R.string.auto_download_plugins_pref), 0)
|
||||||
|
|
||||||
|
activity?.showBottomDialog(
|
||||||
|
prefNames.toList(),
|
||||||
|
prefValues.indexOf(current),
|
||||||
|
getString(R.string.automatic_plugin_download_mode_title),
|
||||||
|
true,
|
||||||
|
{}) {
|
||||||
|
settingsManager.edit().putInt(getString(R.string.auto_download_plugins_pref), prefValues[it]).apply()
|
||||||
|
(context ?: AcraApplication.context)?.let { ctx -> app.initClient(ctx) }
|
||||||
|
}
|
||||||
|
return@setOnPreferenceClickListener true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,14 @@
|
||||||
<item>0</item>
|
<item>0</item>
|
||||||
<item>1</item>
|
<item>1</item>
|
||||||
</array>
|
</array>
|
||||||
|
|
||||||
|
<!-- MainAPI enum: AutoDownloadMode -->
|
||||||
|
<array name="auto_download_plugin">
|
||||||
|
<item>@string/disable</item>
|
||||||
|
<item>@string/subtitles_filter_lang</item>
|
||||||
|
<item>@string/all</item>
|
||||||
|
<item>@string/nsfw</item>
|
||||||
|
</array>
|
||||||
|
|
||||||
<array name="player_pref_names">
|
<array name="player_pref_names">
|
||||||
<item>@string/player_settings_play_in_app</item>
|
<item>@string/player_settings_play_in_app</item>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<string name="auto_update_key" translatable="false">auto_update</string>
|
<string name="auto_update_key" translatable="false">auto_update</string>
|
||||||
<string name="auto_update_plugins_key" translatable="false">auto_update_plugins</string>
|
<string name="auto_update_plugins_key" translatable="false">auto_update_plugins</string>
|
||||||
<string name="auto_download_plugins_key" translatable="false">auto_download_plugins_key</string>
|
<string name="auto_download_plugins_key" translatable="false">auto_download_plugins_key</string>
|
||||||
|
<string name="auto_download_plugins_pref" translatable="false">auto_download_plugins_pref</string>
|
||||||
<string name="skip_update_key" translatable="false">skip_update_key</string>
|
<string name="skip_update_key" translatable="false">skip_update_key</string>
|
||||||
<string name="prerelease_update_key" translatable="false">prerelease_update</string>
|
<string name="prerelease_update_key" translatable="false">prerelease_update</string>
|
||||||
<string name="manual_check_update_key" translatable="false">manual_check_update</string>
|
<string name="manual_check_update_key" translatable="false">manual_check_update</string>
|
||||||
|
@ -249,6 +250,7 @@
|
||||||
<string name="pref_filter_search_quality">Hide selected video quality in search results</string>
|
<string name="pref_filter_search_quality">Hide selected video quality in search results</string>
|
||||||
<string name="automatic_plugin_updates">Automatic plugin updates</string>
|
<string name="automatic_plugin_updates">Automatic plugin updates</string>
|
||||||
<string name="automatic_plugin_download">Automatically download plugins</string>
|
<string name="automatic_plugin_download">Automatically download plugins</string>
|
||||||
|
<string name="automatic_plugin_download_mode_title">Select mode to filter plugins download</string>
|
||||||
<string name="automatic_plugin_download_summary">Automatically install all not yet installed plugins from added repositories.</string>
|
<string name="automatic_plugin_download_summary">Automatically install all not yet installed plugins from added repositories.</string>
|
||||||
<string name="updates_settings">Show app updates</string>
|
<string name="updates_settings">Show app updates</string>
|
||||||
<string name="updates_settings_des">Automatically search for new updates after starting the app.</string>
|
<string name="updates_settings_des">Automatically search for new updates after starting the app.</string>
|
||||||
|
@ -482,6 +484,7 @@
|
||||||
<string name="authenticated_user" formatted="true">%s authenticated</string>
|
<string name="authenticated_user" formatted="true">%s authenticated</string>
|
||||||
<string name="authenticated_user_fail" formatted="true">Could not log in at %s</string>
|
<string name="authenticated_user_fail" formatted="true">Could not log in at %s</string>
|
||||||
<!-- ============ -->
|
<!-- ============ -->
|
||||||
|
<string name="disable">Disable</string>
|
||||||
<string name="none">None</string>
|
<string name="none">None</string>
|
||||||
<string name="normal">Normal</string>
|
<string name="normal">Normal</string>
|
||||||
<string name="all">All</string>
|
<string name="all">All</string>
|
||||||
|
|
|
@ -58,8 +58,7 @@
|
||||||
android:key="@string/auto_update_plugins_key"
|
android:key="@string/auto_update_plugins_key"
|
||||||
android:title="@string/automatic_plugin_updates" />
|
android:title="@string/automatic_plugin_updates" />
|
||||||
|
|
||||||
<SwitchPreference
|
<Preference
|
||||||
android:defaultValue="false"
|
|
||||||
android:icon="@drawable/ic_baseline_extension_24"
|
android:icon="@drawable/ic_baseline_extension_24"
|
||||||
android:key="@string/auto_download_plugins_key"
|
android:key="@string/auto_download_plugins_key"
|
||||||
android:title="@string/automatic_plugin_download"
|
android:title="@string/automatic_plugin_download"
|
||||||
|
@ -77,4 +76,4 @@
|
||||||
android:title="@string/redo_setup_process"
|
android:title="@string/redo_setup_process"
|
||||||
app:key="@string/redo_setup_key" />
|
app:key="@string/redo_setup_key" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
Loading…
Reference in a new issue