Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import com.lagradost.cloudstream3.newSearchResponseList
import com.lagradost.cloudstream3.utils.Coroutines.threadSafeListOf
import com.lagradost.cloudstream3.utils.ExtractorLink
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.withTimeout

class LinkLoadingLimitReached : Error(null, null, false, false)

class APIRepository(val api: MainAPI) {
companion object {
// 2 minute timeout to prevent bad extensions/extractors from hogging the resources
Expand Down Expand Up @@ -210,9 +213,13 @@ class APIRepository(val api: MainAPI) {
withTimeout(getTimeout(api.loadLinksTimeoutMs)) {
api.loadLinks(data, isCasting, subtitleCallback, callback)
}
} catch (_: LinkLoadingLimitReached) {
true
} catch (throwable: CancellationException) {
throw throwable
} catch (throwable: Throwable) {
logError(throwable)
return false
}
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ import com.lagradost.cloudstream3.ui.player.RepoLinkGenerator
import com.lagradost.cloudstream3.ui.player.SubtitleData
import com.lagradost.cloudstream3.ui.result.EpisodeAdapter.Companion.getPlayerAction
import com.lagradost.cloudstream3.utils.AppContextUtils.getNameFull
import com.lagradost.cloudstream3.utils.AppContextUtils.getSearchAllProviderSourceNames
import com.lagradost.cloudstream3.utils.AppContextUtils.isConnectedToChromecast
import com.lagradost.cloudstream3.utils.AppContextUtils.setDefaultFocus
import com.lagradost.cloudstream3.utils.AppContextUtils.shouldSearchAllProviderSources
import com.lagradost.cloudstream3.utils.AppContextUtils.sortSubs
import com.lagradost.cloudstream3.utils.CastHelper.startCast
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
Expand Down Expand Up @@ -1268,7 +1270,12 @@ class ResultViewModel2 : ViewModel() {
clearCache: Boolean = false,
isCasting: Boolean = false
): LinkLoadingResult {
val tempGenerator = RepoLinkGenerator(listOf(result))
val tempGenerator = RepoLinkGenerator(
listOf(result),
page = currentResponse,
includeAllProviderSources = context?.shouldSearchAllProviderSources() == true,
allProviderSourceNames = context?.getSearchAllProviderSourceNames().orEmpty()
)

val links: MutableSet<ExtractorLink> = mutableSetOf()
val subs: MutableSet<SubtitleData> = mutableSetOf()
Expand Down Expand Up @@ -2074,14 +2081,26 @@ class ResultViewModel2 : ViewModel() {
preferDubStatus = indexer.dubStatus

generator = if (isMovie) {
getMovie()?.let { RepoLinkGenerator(listOf(it), page = currentResponse) }
getMovie()?.let {
RepoLinkGenerator(
listOf(it),
page = currentResponse,
includeAllProviderSources = context?.shouldSearchAllProviderSources() == true,
allProviderSourceNames = context?.getSearchAllProviderSourceNames().orEmpty()
)
}
} else {
val episodes = currentEpisodes.filter { it.key.dubStatus == indexer.dubStatus }
.toList()
.sortedBy { it.first.season }
.flatMap { it.second }

RepoLinkGenerator(episodes, page = currentResponse)
RepoLinkGenerator(
episodes,
page = currentResponse,
includeAllProviderSources = context?.shouldSearchAllProviderSources() == true,
allProviderSourceNames = context?.getSearchAllProviderSourceNames().orEmpty()
)
}

if (isMovie) {
Expand Down Expand Up @@ -2706,4 +2725,4 @@ class ResultViewModel2 : ViewModel() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setTool
import com.lagradost.cloudstream3.ui.settings.SettingsFragment.Companion.setUpToolbar
import com.lagradost.cloudstream3.utils.AppContextUtils.getApiDubstatusSettings
import com.lagradost.cloudstream3.utils.AppContextUtils.getApiProviderLangSettings
import com.lagradost.cloudstream3.utils.AppContextUtils.getSearchAllProviderSourceNames
import com.lagradost.cloudstream3.utils.DataStoreHelper
import com.lagradost.cloudstream3.utils.SingleSelectionHelper.showMultiDialog
import com.lagradost.cloudstream3.utils.SubtitleHelper.getNameNextToFlagEmoji
Expand Down Expand Up @@ -109,6 +110,38 @@ class SettingsProviders : BasePreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}

getPref(R.string.search_all_provider_sources_list_key)?.setOnPreferenceClickListener {
val providers = synchronized(APIHolder.apis) {
APIHolder.apis.filter { api -> api.providerType != ProviderType.MetaProvider }
.sortedBy { api -> api.name.lowercase() }
}
val selectedProviderNames = requireContext().getSearchAllProviderSourceNames()
val currentList = providers.mapIndexedNotNull { index, api ->
if (selectedProviderNames.contains(api.name)) index else null
}

activity?.showMultiDialog(
providers.map { api -> "${api.name} (${api.lang})" },
currentList,
getString(R.string.search_all_provider_sources_list),
{}
) { selectedList ->
val limitedSelection = selectedList.take(5)
if (selectedList.size > limitedSelection.size) {
CommonActivity.showToast(R.string.search_all_provider_sources_limit)
}

settingsManager.edit {
putStringSet(
getString(R.string.search_all_provider_sources_list_key),
limitedSelection.map { providers[it].name }.toSet()
)
}
}

return@setOnPreferenceClickListener true
}

getPref(R.string.provider_lang_key)?.setOnPreferenceClickListener {
activity?.getApiProviderLangSettings()?.let { currentLangTags ->
val languagesTagName = synchronized(APIHolder.apis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,19 @@ object AppContextUtils {
return list.toHashSet()
}

fun Context.shouldSearchAllProviderSources(): Boolean {
return PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.search_all_provider_sources_key), false)
}

fun Context.getSearchAllProviderSourceNames(): Set<String> {
return PreferenceManager.getDefaultSharedPreferences(this)
.getStringSet(getString(R.string.search_all_provider_sources_list_key), emptySet())
?.take(5)
?.toSet()
?: emptySet()
}

fun Context.getApiTypeSettings(): HashSet<TvType> {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
val hashSet = HashSet<TvType>()
Expand Down Expand Up @@ -916,4 +929,4 @@ object AppContextUtils {
} else null
return currentAudioFocusRequest
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values-b+tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@
<string name="app_layout">Uygulama düzeni</string>
<string name="preferred_media_settings">Tercih edilen medya</string>
<string name="enable_nsfw_on_providers">Desteklenen uzantılarda NSFW etkinleştir</string>
<string name="search_all_provider_sources">Tüm uzantılarda kaynak ara</string>
<string name="search_all_provider_sources_summary">Film veya bölüm kaynakları yüklenirken seçili uzantılardaki eşleşen kaynakları da listele.</string>
<string name="search_all_provider_sources_list">Kaynağı birleştirilecek uzantılar</string>
<string name="search_all_provider_sources_list_summary">En fazla 5 uzantı seç. Her seçili uzantıdan en fazla 5 kaynak eklenir.</string>
<string name="search_all_provider_sources_limit">En fazla 5 uzantı seçebilirsin.</string>
<string name="subtitles_encoding">Altyazı kodlaması</string>
<string name="category_providers">Sağlayıcılar</string>
<string name="category_ui">Düzen</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/donottranslate-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<string name="filter_sub_lang_key">filter_sub_lang_key</string>
<string name="pref_filter_search_quality_key">pref_filter_search_quality_key</string>
<string name="enable_nsfw_on_providers_key">enable_nsfw_on_providers_key</string>
<string name="search_all_provider_sources_key">search_all_provider_sources_key</string>
<string name="search_all_provider_sources_list_key">search_all_provider_sources_list_key</string>
<string name="skip_startup_account_select_key">skip_startup_account_select_key</string>
<string name="enable_skip_op_from_database">enable_skip_op_from_database</string>
<string name="rotate_video_key">rotate_video_key</string>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@
<string name="app_layout">App Layout</string>
<string name="preferred_media_settings">Preferred media</string>
<string name="enable_nsfw_on_providers">Enable NSFW on supported Extensions</string>
<string name="search_all_provider_sources">Search sources in all extensions</string>
<string name="search_all_provider_sources_summary">When loading a movie or episode, also list matching sources from selected extensions.</string>
<string name="search_all_provider_sources_list">Extensions to merge sources from</string>
<string name="search_all_provider_sources_list_summary">Select up to 5 extensions. Up to 5 sources are added from each selected extension.</string>
<string name="search_all_provider_sources_limit">You can select up to 5 extensions.</string>
<string name="subtitles_encoding">Subtitle encoding</string>
<string name="category_providers">Providers</string>
<string name="category_provider_test">Provider test</string>
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/res/xml/settings_providers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,24 @@
android:title="@string/enable_nsfw_on_providers"
app:defaultValue="false" />

<SwitchPreference
android:defaultValue="false"
android:icon="@drawable/search_icon"
android:key="@string/search_all_provider_sources_key"
android:summary="@string/search_all_provider_sources_summary"
android:title="@string/search_all_provider_sources" />

<Preference
android:dependency="@string/search_all_provider_sources_key"
android:icon="@drawable/ic_baseline_extension_24"
android:key="@string/search_all_provider_sources_list_key"
android:summary="@string/search_all_provider_sources_list_summary"
android:title="@string/search_all_provider_sources_list" />

<Preference
android:icon="@drawable/baseline_network_ping_24"
android:key="@string/test_providers_key"
android:title="@string/test_extensions"
android:summary="@string/test_extensions_summary"/>

</PreferenceScreen>
</PreferenceScreen>
Loading