youpipe: shrink codec lists
- Commit
e4abe38df65504a39281a142ddc2de2c5f438d6f- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-23 17:22 UTC (4 months ago)
- Parents
6ef879d
Diff
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 38c0a93eed..a6b9375050 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPage.kt@@ -292,7 +292,7 @@ fun VideoDetails( onExpandedChange = { videoExpanded = it } ) { OutlinedTextField(- value = "${selectedVideoStream.quality} (${getVideoCodecName(selectedVideoStream.codec)}) - ${Formatter.formatShortFileSize(context, selectedVideoStream.size)}",+ value = "${selectedVideoStream.quality} - ${Formatter.formatShortFileSize(context, selectedVideoStream.size)}", onValueChange = {}, readOnly = true, trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = videoExpanded) },@@ -358,7 +358,7 @@ fun VideoDetails( onExpandedChange = { audioExpanded = it } ) { OutlinedTextField(- value = selectedAudioStream?.let { "${it.bitrate / 1000} kbps (${getAudioCodecName(it.codec)}) - ${Formatter.formatShortFileSize(context, it.size)}" } ?: "None",+ value = selectedAudioStream?.let { "${it.bitrate / 1000} kbps - ${Formatter.formatShortFileSize(context, it.size)}" } ?: "None", onValueChange = {}, readOnly = true, trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = audioExpanded) },@@ -371,7 +371,7 @@ fun VideoDetails( ) { filteredAudioStreams.forEach { stream -> DropdownMenuItem(- text = { Text("${stream.bitrate / 1000} kbps (${getAudioCodecName(stream.codec)}) - ${Formatter.formatShortFileSize(context, stream.size)}") },+ text = { Text("${stream.bitrate / 1000} kbps - ${Formatter.formatShortFileSize(context, stream.size)}") }, onClick = { selectedAudioStream = stream audioExpanded = false
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 0afd5bf52e..a21a7f8965 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/ui/VideoPlayer.kt@@ -414,7 +414,8 @@ fun VideoPlayer( shape = RoundedCornerShape(4.dp) ) { Row(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {- Text(text = stringResource(R.string.video_quality_codec, currentVideoStream.quality, getVideoCodecName(currentVideoStream.codec)), color = Color.White, style = MaterialTheme.typography.labelMedium)+ // Per user request: button shows only quality, codec only in dropdown+ Text(text = currentVideoStream.quality, color = Color.White, style = MaterialTheme.typography.labelMedium) IconArrowDropDown(tint = Color.White) } }@@ -453,6 +454,7 @@ fun VideoPlayer( } } + // Audio is opus-only now, so no need to surface codec to user. Only bitrate matters. Box { Surface( onClick = { isAudioMenuExpanded = true },@@ -460,14 +462,14 @@ fun VideoPlayer( shape = RoundedCornerShape(4.dp) ) { Row(modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {- Text(text = stringResource(R.string.audio_bitrate_codec, (currentAudioStream?.bitrate ?: 0) / 1000, getAudioCodecName(currentAudioStream?.codec ?: "")), color = Color.White, style = MaterialTheme.typography.labelMedium)+ Text(text = stringResource(R.string.audio_bitrate, (currentAudioStream?.bitrate ?: 0) / 1000), color = Color.White, style = MaterialTheme.typography.labelMedium) IconArrowDropDown(tint = Color.White) } } DropdownMenu(expanded = isAudioMenuExpanded, onDismissRequest = { isAudioMenuExpanded = false }) { audioStreamOptions.forEach { stream -> DropdownMenuItem(- text = { Text(stringResource(R.string.audio_bitrate_codec, stream.bitrate / 1000, getAudioCodecName(stream.codec))) },+ text = { Text(stringResource(R.string.audio_bitrate, stream.bitrate / 1000)) }, onClick = { currentAudioStream = stream; isAudioMenuExpanded = 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 5873a995e2..5c026b6ac1 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt@@ -713,29 +713,45 @@ class YouPipeViewModel( } if (progVideoOnly.isNotEmpty() || sabrVideoOnly.isNotEmpty()) {- // Combine progressive + SABR video-only options, but de-duplicate by- // (codec, resolution): progressive is listed first and kept for any- // combo it already offers, so SABR only contributes what's genuinely- // new — notably AV1 (SABR-only) and any resolutions progressive lacks.- // Without this, h264/vp9 would appear twice (once per source).- videoStreams = (+ // Combine progressive + SABR video-only. Deduplicate by height and prefer+ // vp9 over avc for same resolution (per user request). AV1 is kept when+ // present as distinct quality. Opus-only audio.+ val combinedVideo = ( progVideoOnly.map { it.toDomain() } + sabrVideoOnly.map { it.toSabrDomain(videoId) } )+ .groupBy { it.height }+ .flatMap { (_, streamsAtHeight) ->+ val vp9 = streamsAtHeight.filter { it.codec == "vp9" }+ val avc = streamsAtHeight.filter { it.codec == "avc" }+ // If both vp9 and avc exist at same height, keep only vp9+ if (vp9.isNotEmpty() && avc.isNotEmpty()) {+ streamsAtHeight.filter { it.codec != "avc" }+ } else {+ streamsAtHeight+ }+ } .distinctBy { it.codec to it.height } .sortedWith( compareByDescending<VideoStream> { it.height } .thenByDescending { codecPriority(it.codec) } )- audioStreams = (- if (progAudio.isNotEmpty()) {- progAudio.map { it.toDomain() }- } else {- sabrAudio.map { it.toSabrDomain(videoId) }+ videoStreams = combinedVideo++ // Audio: opus only (F-Droid friendly, higher quality). Filter before sort.+ val rawAudioCandidates = if (progAudio.isNotEmpty()) {+ progAudio.map { it.toDomain() }+ } else {+ sabrAudio.map { it.toSabrDomain(videoId) }+ }+ audioStreams = rawAudioCandidates+ .filter { it.codec == "opus" }+ .let { opusList ->+ // Fallback to all if no opus (rare, but avoid empty track list)+ if (opusList.isEmpty()) rawAudioCandidates else opusList }- ).sortedWith(+ .sortedWith( compareByDescending<AudioStream> { it.bitrate }- .thenByDescending { audioCodecPriority(it.codec) } ) } else { videoStreams = ex.videoStreams.map { it.toDomain() }@@ -840,7 +856,8 @@ class YouPipeViewModel( private fun downloadedStreams(dv: DownloadedVideo): Pair<List<VideoStream>, List<AudioStream>> { val video = listOf(VideoStream(dv.filePath, 1920, 1080, 0, 30, "Downloaded", "avc", 0L))- val audio = if (dv.audioPath != null) listOf(AudioStream(dv.audioPath, 0, "Default", "aac", 0L)) else emptyList()+ // Keep as opus for consistency with opus-only filter in UI+ val audio = if (dv.audioPath != null) listOf(AudioStream(dv.audioPath, 0, "Default", "opus", 0L)) else emptyList() return video to audio } @@ -1267,10 +1284,6 @@ private fun codecPriority(codec: String): Int = when (codec) { "av1" -> 3; "vp9" -> 2; "avc" -> 1; else -> 0 } -private fun audioCodecPriority(codec: String): Int = when (codec) {- "opus" -> 2; "aac" -> 1; else -> 0-}- /** Factory for constructing [YouPipeViewModel] with the DAOs. */ class YouPipeViewModelFactory( private val application: Application,
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 032b58d0a2..557a9ba82c 100644--- a/youpipe/src/main/res/values/strings.xml+++ b/youpipe/src/main/res/values/strings.xml@@ -48,8 +48,10 @@ <string name="label_import_youtube">Import from YouTube (Takeout)</string> <string name="label_export_youpipe">Export Subscriptions</string> <string name="video_quality_codec">%1$s (%2$s)</string>+ <string name="video_quality">%1$s</string> <string name="video_quality_fps_codec">%1$s (%2$dfps) %3$s</string> <string name="audio_bitrate_codec">%1$dkbps (%2$s)</string>+ <string name="audio_bitrate">%1$dkbps</string> <string name="empty_recommendations">Watch some videos to get personalized recommendations</string> <string name="recommendation_reason">Why: %1$s</string> <string name="action_more_options">More options</string>