From 36684f63deb02d412f3f423d3f672e86e866af6f Mon Sep 17 00:00:00 2001 From: forbiders <339140124+forbiders@users.noreply.github.com> Date: Thu, 22 Oct 2026 03:44:08 +0000 Subject: [PATCH] Add auto-play source regex setting --- .../cloudstream3/ui/player/GeneratorPlayer.kt | 7 ++++++- .../ui/settings/SettingsPlayerScreen.kt | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt index e4616c93bcf..8b5597476a4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/GeneratorPlayer.kt @@ -1616,7 +1616,12 @@ class GeneratorPlayer : FullScreenPlayer() { val links = viewModel.state.sortLinks(currentQualityProfile) - val firstAvailableLink = links.firstOrNull { it.shouldUseLink }?.link + // Auto-play regex: read user pattern (comma-separated → OR). If it matches a source name, play that; otherwise fall back to first available. + val autoPlayRegex = CloudStreamApp.getKey("player_auto_play_regex") + val pattern = autoPlayRegex?.trim()?.takeIf { it.isNotEmpty() } + ?.split(",")?.map { it.trim() }?.filter { it.isNotEmpty() }?.joinToString("|") + val regex = pattern?.let { runCatching { Regex(it, RegexOption.IGNORE_CASE) }.getOrNull() } + val firstAvailableLink = (regex?.let { r -> links.firstOrNull { it.shouldUseLink && r.containsMatchIn(it.link?.first?.name ?: "") } } ?: links.firstOrNull { it.shouldUseLink })?.link if (firstAvailableLink == null) { noLinksFound() return diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt index 8f6f5bf4f12..21eccea4024 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsPlayerScreen.kt @@ -1,5 +1,6 @@ package com.lagradost.cloudstream3.ui.settings +import androidx.appcompat.app.AlertDialog import android.text.format.Formatter.formatShortFileSize import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -14,6 +15,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringArrayResource import androidx.compose.ui.res.stringResource import com.lagradost.cloudstream3.CommonActivity.activity +import com.lagradost.cloudstream3.CloudStreamApp import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.actions.VideoClickActionHolder import com.lagradost.cloudstream3.ui.player.source_priority.QualityProfileDialog @@ -108,6 +110,25 @@ object SettingsPlayerScreen : SearchableSettings { } }), + Preference.PreferenceItem.TextPreference( + title = "Auto-play source regex", + subtitle = "Auto-pick first source matching (e.g. hindi,hin,tamil,webdl,4k). Empty = normal.", + icon = painterResource(R.drawable.play_arrow_24px), + onClick = { + val ctx = context + val input = android.widget.EditText(ctx).apply { + setText(CloudStreamApp.getKey("player_auto_play_regex") ?: "") + isSingleLine = true + } + AlertDialog.Builder(ctx, R.style.AlertDialogCustom).setTitle("Auto-play source regex") + .setView(input) + .setPositiveButton("Save") { _, _ -> + CloudStreamApp.setKey("player_auto_play_regex", input.text.toString().trim()) + } + .setNegativeButton("Cancel", null) + .show() + }), + Preference.PreferenceItem.SwitchPreference( preference = settings.player.pipEnabled, title = stringResource(R.string.picture_in_picture),