youpipe: distinguish paid videos and add hide-paid filter #481
- Commit
02dc0ef668478e60aef4fd160602a5be67d9c3c4- Author
- Vayun Mathur <[email protected]>
- When
- 2026-08-10 17:03 UTC (3 months ago)
- Parents
129142f
Diff
youpipe/src/main/java/com/vayunmathur/youpipe/data/RecommendationPreferences.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/data/RecommendationPreferences.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/data/RecommendationPreferences.ktindex 6f4f7dfcfc..a5d49cca68 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/data/RecommendationPreferences.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/data/RecommendationPreferences.kt@@ -31,6 +31,7 @@ data class RecommendationPreferences( val sourceSearch: Boolean = true, val hideShorts: Boolean = false, val hideLive: Boolean = false,+ val hidePaid: Boolean = false, val minDurationSec: Long = 0, val maxDurationSec: Long = 0, )
youpipe/src/main/java/com/vayunmathur/youpipe/data/SubscriptionDatabase.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/data/SubscriptionDatabase.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/data/SubscriptionDatabase.ktindex 785f8ff082..0f107e9533 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/data/SubscriptionDatabase.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/data/SubscriptionDatabase.kt@@ -124,6 +124,10 @@ val MIGRATION_4_5 = Migration(4, 5) { it.execSQL("CREATE INDEX IF NOT EXISTS `index_PlaylistItem_playlistId` ON `PlaylistItem` (`playlistId`)") } +val MIGRATION_5_6 = Migration(5, 6) {+ it.execSQL("ALTER TABLE `RecommendationPreferences` ADD COLUMN `hidePaid` INTEGER NOT NULL DEFAULT 0")+}+ @Dao interface HistoryVideoDao { @Query("SELECT * FROM HistoryVideo")@@ -191,7 +195,7 @@ interface SubscriptionVideoDao { } @TypeConverters(DefaultConverters::class)-@Database(entities = [Subscription::class, SubscriptionVideo::class, HistoryVideo::class, SubscriptionCategory::class, DownloadedVideo::class, CachedRelatedVideo::class, RecommendationImpression::class, RecommendationPreferences::class, ChannelPreference::class, KeywordPreference::class, Playlist::class, PlaylistItem::class], version = 5, exportSchema = false)+@Database(entities = [Subscription::class, SubscriptionVideo::class, HistoryVideo::class, SubscriptionCategory::class, DownloadedVideo::class, CachedRelatedVideo::class, RecommendationImpression::class, RecommendationPreferences::class, ChannelPreference::class, KeywordPreference::class, Playlist::class, PlaylistItem::class], version = 6, exportSchema = false) abstract class SubscriptionDatabase : RoomDatabase() { abstract fun subscriptionDao(): SubscriptionDao abstract fun subscriptionVideoDao(): SubscriptionVideoDao@@ -207,6 +211,6 @@ abstract class SubscriptionDatabase : RoomDatabase() { abstract fun playlistItemDao(): PlaylistItemDao companion object : com.vayunmathur.library.util.DatabaseMigrations {- override val migrations: List<Migration> = listOf(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5)+ override val migrations: List<Migration> = listOf(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6) } }
youpipe/src/main/java/com/vayunmathur/youpipe/ui/ChannelPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/ChannelPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/ChannelPage.ktindex 7e19ff7e8e..39b36aa42b 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/ChannelPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/ChannelPage.kt@@ -64,7 +64,7 @@ data class ChannelInfo(val name: String, val channelID: String, val subscribers: } @Serializable-data class VideoInfo(val name: String, val videoID: Long, val duration: Long, val views: Long, val uploadDate: Instant, val thumbnailURL: String, val author: String): ItemInfo+data class VideoInfo(val name: String, val videoID: Long, val duration: Long, val views: Long, val uploadDate: Instant, val thumbnailURL: String, val author: String, val isPaid: Boolean = false): ItemInfo @Composable fun ChannelPage(@@ -132,11 +132,18 @@ fun videoRowState( title = (deArrowTitle ?: videoInfo.name).decodeHtml(), thumbnailURL = deArrowThumbnailURL ?: videoInfo.thumbnailURL, author = videoInfo.author.decodeHtml().takeIf { showAuthor },- stats = context.getString(- R.string.video_stat_format,- countString(context, videoInfo.views),- uploadTimeAgo(context, videoInfo.uploadDate),- ),+ stats = if (videoInfo.isPaid || videoInfo.views < 0) {+ context.getString(+ R.string.video_stat_paid_format,+ uploadTimeAgo(context, videoInfo.uploadDate),+ )+ } else {+ context.getString(+ R.string.video_stat_format,+ countString(context, videoInfo.views),+ uploadTimeAgo(context, videoInfo.uploadDate),+ )+ }, reason = reason, channelKey = videoInfo.author.lowercase(), percentWatched = percentWatched,
youpipe/src/main/java/com/vayunmathur/youpipe/ui/RecommendationsSettingsPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/RecommendationsSettingsPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/RecommendationsSettingsPage.ktindex 5dbaa0ac3f..faf2bc3d64 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/RecommendationsSettingsPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/RecommendationsSettingsPage.kt@@ -116,6 +116,11 @@ fun RecommendationsSettingsPage( checked = recPrefs.hideLive, onCheckedChange = { ypvm.setHideLive(it) }, )+ SettingsSwitchRow(+ title = stringResource(R.string.label_hide_paid),+ checked = recPrefs.hidePaid,+ onCheckedChange = { ypvm.setHidePaid(it) },+ ) DurationField( label = stringResource(R.string.label_min_duration), seconds = recPrefs.minDurationSec,
youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.ktindex 423cee8303..322bef998f 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt@@ -220,12 +220,20 @@ fun VideoPage( loaded = videoData != null, title = videoData?.title.orEmpty(), byline = videoData?.let {- resources.getString(- R.string.video_info_format,- it.author,- countString(context, it.views),- uploadTimeAgo(context, it.uploadDate),- )+ if (it.views < 0) {+ resources.getString(+ R.string.video_info_paid_format,+ it.author,+ uploadTimeAgo(context, it.uploadDate),+ )+ } else {+ resources.getString(+ R.string.video_info_format,+ it.author,+ countString(context, it.views),+ uploadTimeAgo(context, it.uploadDate),+ )+ } }.orEmpty(), authorThumbnailURL = videoData?.authorThumbnail.orEmpty(), authorURL = videoData?.authorURL.orEmpty(),
youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.ktindex 464a0844c9..1249430821 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/Extractor.kt@@ -7,6 +7,7 @@ import com.vayunmathur.youpipe.ui.VideoInfo import kotlinx.coroutines.coroutineScope import kotlinx.serialization.Serializable import org.schabi.newpipe.extractor.ServiceList+import org.schabi.newpipe.extractor.stream.ContentAvailability import org.schabi.newpipe.extractor.stream.StreamInfoItem import java.nio.ByteBuffer import kotlin.io.encoding.Base64@@ -36,7 +37,8 @@ fun StreamInfoItem.toVideoInfo(): VideoInfo? { getViewCount(), date.instant.toKotlinInstant(), thumbnails.firstOrNull()?.url ?: "",- getUploaderName().orEmpty().decodeHtml()+ getUploaderName().orEmpty().decodeHtml(),+ getContentAvailability() == ContentAvailability.PAID, ) }
youpipe/src/main/java/com/vayunmathur/youpipe/util/Recommender.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/Recommender.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/Recommender.ktindex 20c6632f74..f119d65248 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/Recommender.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/Recommender.kt@@ -44,6 +44,8 @@ data class ContentFilters( val hideShorts: Boolean = false, /** Drop videos with unknown/zero duration (treated as live). */ val hideLive: Boolean = false,+ /** Drop paid/paywalled videos. */+ val hidePaid: Boolean = false, val minDurationSec: Long = 0, val maxDurationSec: Long = 0, )@@ -438,6 +440,7 @@ private fun passesHardFilters( ): Boolean { if (channelPrefs[v.author.lowercase()]?.blocked == true) return false if (mutedKeywords.isNotEmpty() && tokenize(v.name).any { it in mutedKeywords }) return false+ if (filters.hidePaid && v.isPaid) return false val d = v.duration if (filters.hideLive && d <= 0) return false if (filters.hideShorts && d in 1 until 60) return false
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 87533be664..4d67d3bbd9 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt@@ -347,6 +347,7 @@ class YouPipeViewModel( val filters = ContentFilters( hideShorts = prefs.hideShorts, hideLive = prefs.hideLive,+ hidePaid = prefs.hidePaid, minDurationSec = prefs.minDurationSec, maxDurationSec = prefs.maxDurationSec, )@@ -569,6 +570,7 @@ class YouPipeViewModel( fun setHideShorts(value: Boolean) = updatePrefs { it.copy(hideShorts = value) } fun setHideLive(value: Boolean) = updatePrefs { it.copy(hideLive = value) }+ fun setHidePaid(value: Boolean) = updatePrefs { it.copy(hidePaid = value) } fun setMinDuration(seconds: Long) = updatePrefs { it.copy(minDurationSec = seconds.coerceAtLeast(0)) } fun setMaxDuration(seconds: Long) = updatePrefs { it.copy(maxDurationSec = seconds.coerceAtLeast(0)) } @@ -706,8 +708,10 @@ class YouPipeViewModel( try { val info = getChannelInfo(channelID) _channelState.update { it.copy(info = info) }+ val hidePaid = (recommendationPreferencesDao.get() ?: RecommendationPreferences()).hidePaid val channelVideos = mutableListOf<VideoInfo>() getChannelVideos(info.channelID).forEach { video ->+ if (hidePaid && video.isPaid) return@forEach channelVideos.add(video) _channelState.update { it.copy(videos = it.videos + video) } }
youpipe/src/main/res/values/strings.xml
diff --git a/youpipe/src/main/res/values/strings.xml b/youpipe/src/main/res/values/strings.xmlindex ebc9f70b1d..329686e63b 100644--- a/youpipe/src/main/res/values/strings.xml+++ b/youpipe/src/main/res/values/strings.xml@@ -61,6 +61,10 @@ <string name="cc">CC</string> <!-- Video stats format: views | time ago for channel list items. %1$s = views e.g. 1M, %2$s = time ago e.g. 3 days ago --> <string name="video_stat_format"><xliff:g id="views" example="1M">%1$s</xliff:g> views | <xliff:g id="time" example="3 days ago">%2$s</xliff:g></string>+ <!-- Video stats format for paid videos, which have no public view count. %1$s = time ago e.g. 3 days ago -->+ <string name="video_stat_paid_format">Paid | <xliff:g id="time" example="3 days ago">%1$s</xliff:g></string>+ <!-- Video byline for paid videos, which have no public view count. %1$s = channel name, %2$s = time ago -->+ <string name="video_info_paid_format"><xliff:g id="channel" example="Linus Tech Tips">%1$s</xliff:g> | Paid | <xliff:g id="time" example="2 days ago">%2$s</xliff:g></string> <!-- Quality with fps and codec. %1$s = quality, %2$d = fps e.g. 60, %3$s = codec --> <string name="video_quality_fps_codec"><xliff:g id="quality" example="1080p">%1$s</xliff:g> (<xliff:g id="fps" example="60">%2$d</xliff:g>fps) <xliff:g id="codec" example="avc">%3$s</xliff:g></string> @@ -171,6 +175,8 @@ <string name="label_hide_shorts">Hide Shorts</string> <!-- Filter toggle: hide live or unknown duration videos. Verb phrase --> <string name="label_hide_live">Hide live/unknown length</string>+ <!-- Filter toggle: hide paid/paywalled videos from feeds. Verb phrase -->+ <string name="label_hide_paid">Hide paid videos</string> <!-- Field label: minimum video length in seconds filter input. Noun phrase with unit --> <string name="label_min_duration">Min length (seconds)</string> <!-- Field label: maximum video length filter input -->