youpipe: added SponsorBlock segment type selection in settings
- Commit
e4b622d0a2582bdf5042acf2884f42f05bda91bc- Author
- Vayun Mathur <[email protected]>
- When
- 2026-06-02 00:23 UTC (6 months ago)
- Parents
99a17d5
Diff
youpipe/src/main/java/com/vayunmathur/youpipe/ui/SettingsPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SettingsPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SettingsPage.ktindex e0fb18b14c..b392c6e314 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SettingsPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/SettingsPage.kt@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.material3.Checkbox import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ListItem@@ -27,6 +28,8 @@ import com.vayunmathur.youpipe.MAIN_BOTTOM_BAR_ITEMS import com.vayunmathur.youpipe.R import com.vayunmathur.youpipe.Route import com.vayunmathur.youpipe.util.YouPipeViewModel+import com.vayunmathur.youpipe.util.YouPipeViewModel.Companion.ALL_SPONSOR_CATEGORIES+import com.vayunmathur.youpipe.util.YouPipeViewModel.Companion.SPONSOR_CATEGORY_LABELS @OptIn(ExperimentalMaterial3Api::class) @Composable@@ -35,6 +38,7 @@ fun SettingsPage( ypvm: YouPipeViewModel, ) { val sponsorBlockEnabled by ypvm.sponsorBlockEnabled.collectAsState()+ val sponsorBlockCategories by ypvm.sponsorBlockCategories.collectAsState() val isLoading by ypvm.isImporting.collectAsState() val progress by ypvm.importProgress.collectAsState() @@ -72,6 +76,24 @@ fun SettingsPage( } ) }+ if (sponsorBlockEnabled) {+ ALL_SPONSOR_CATEGORIES.forEach { category ->+ item(key = "sb_$category") {+ val label = SPONSOR_CATEGORY_LABELS[category] ?: category+ val checked = category in sponsorBlockCategories+ ListItem(+ headlineContent = { Text(label) },+ trailingContent = {+ Checkbox(+ checked = checked,+ onCheckedChange = { ypvm.toggleSponsorBlockCategory(category) }+ )+ },+ modifier = Modifier.padding(start = 16.dp)+ )+ }+ }+ } item { ListItem( headlineContent = { Text(stringResource(R.string.label_backup_restore)) }
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.ktindex b75e632894..6c0323336b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt@@ -100,8 +100,9 @@ fun VideoPlayer( ) { val context = LocalContext.current val sponsorBlockEnabled by ypvm.sponsorBlockEnabled.collectAsState()+ val sponsorBlockCategories by ypvm.sponsorBlockCategories.collectAsState() val videoState by ypvm.videoState.collectAsState()- val sponsorSegments = videoState.sponsorSegments+ val sponsorSegments = videoState.sponsorSegments.filter { it.category in sponsorBlockCategories } var languages by remember { mutableStateOf(audioStreams.map { it.language }.distinct().sorted()) } var language by remember { mutableStateOf(if("en" in languages) "en" else languages.first()) }
youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.ktindex fcd13dba4e..1cd3a3ac0a 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt@@ -461,6 +461,12 @@ class YouPipeViewModel( .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false) val sponsorBlockEnabled: StateFlow<Boolean> = _sponsorBlockEnabled + private val _sponsorBlockCategories: StateFlow<Set<String>> = DataStoreUtils+ .getInstance(application)+ .stringSetFlow("sponsorblock_categories")+ .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), DEFAULT_SPONSOR_CATEGORIES)+ val sponsorBlockCategories: StateFlow<Set<String>> = _sponsorBlockCategories+ fun setSponsorBlockEnabled(enabled: Boolean) { viewModelScope.launch { DataStoreUtils.getInstance(getApplication())@@ -468,6 +474,25 @@ class YouPipeViewModel( } } + fun setSponsorBlockCategories(categories: Set<String>) {+ viewModelScope.launch(Dispatchers.IO) {+ val ds = DataStoreUtils.getInstance(getApplication())+ // Clear and re-add all categories+ for (cat in ALL_SPONSOR_CATEGORIES) {+ ds.removeStringFromSet("sponsorblock_categories", cat)+ }+ for (cat in categories) {+ ds.addStringToSet("sponsorblock_categories", cat)+ }+ }+ }++ fun toggleSponsorBlockCategory(category: String) {+ val current = _sponsorBlockCategories.value+ val updated = if (category in current) current - category else current + category+ setSponsorBlockCategories(updated)+ }+ fun importYouTubeTakeout(uri: Uri) { val ctx = getApplication<Application>() viewModelScope.launch(Dispatchers.IO) {@@ -658,6 +683,26 @@ class YouPipeViewModel( companion object { private const val TAG = "YouPipeViewModel"++ val ALL_SPONSOR_CATEGORIES = setOf(+ "sponsor", "selfpromo", "interaction", "intro", "outro",+ "preview", "music_offtopic", "filler"+ )+ val DEFAULT_SPONSOR_CATEGORIES = setOf(+ "sponsor", "selfpromo", "interaction", "intro", "outro",+ "preview", "music_offtopic", "filler"+ )++ val SPONSOR_CATEGORY_LABELS = mapOf(+ "sponsor" to "Sponsor",+ "selfpromo" to "Self Promotion",+ "interaction" to "Interaction Reminder",+ "intro" to "Intro",+ "outro" to "Outro/Endcards",+ "preview" to "Preview/Recap",+ "music_offtopic" to "Non-Music in Music Videos",+ "filler" to "Filler",+ ) } }