add a download quality preference

Downloads always fetched the original file. The setting takes the same choices
as the stream quality, and when it transcodes the download uses the stream
endpoint with those parameters instead, so the stored file is already the
wanted encoding rather than the original that would be transcoded on each play.

A preference change applied before the source is ready falls back to original,
and the URI is built from the same cached source the stream URL uses.
This commit is contained in:
austinried
2026-10-04 00:30:03 +00:00
parent 26b8963205
commit adb9367f18
7 changed files with 98 additions and 11 deletions
@@ -9,6 +9,7 @@ import com.subtracks.data.db.SubtracksDatabase
import com.subtracks.data.download.ArtworkStore
import com.subtracks.data.model.CoverArtRef
import com.subtracks.data.model.coverArtKey
import com.subtracks.data.prefs.StreamQuality
import com.subtracks.data.prefs.UserPreferences
import com.subtracks.data.prefs.fakeUserPreferences
import kotlinx.coroutines.Dispatchers
@@ -63,6 +64,29 @@ class SourceRepositoryTest {
db.close()
}
@Test
fun aTranscodedDownloadQualityDownloadsTheStreamInstead() =
runBlocking {
repository.addSource("nav", "http://a.example/", "u", "p", false)
val sourceId = repository.activeSourceId().first()!!
withTimeout(5_000) { while (repository.downloadUri(sourceId, "s1") == null) delay(10) }
assertTrue(repository.downloadUri(sourceId, "s1")!!.contains("/rest/download"))
prefs.setDownloadQuality(StreamQuality(maxBitrate = 128, format = "opus"))
var transcoded: String? = null
withTimeout(5_000) {
while (transcoded == null) {
delay(10)
transcoded = repository.downloadUri(sourceId, "s1")?.takeIf { it.contains("/rest/stream") }
}
}
assertTrue(transcoded!!.contains("maxBitRate=128"))
assertTrue(transcoded!!.contains("format=opus"))
}
@Test
fun addingASourceMakesItTheSingleActiveOne() =
runTest {
@@ -343,11 +343,13 @@ class AppScreenshotTest {
wifiQuality = StreamQuality(),
mobileQuality = StreamQuality(192, "mp3"),
syncConcurrency = 4,
downloadQuality = StreamQuality(128, "opus"),
onSelectSource = {},
onEditServer = {},
onWifiQualityChange = {},
onMobileQualityChange = {},
onSyncConcurrencyChange = {},
onDownloadQualityChange = {},
onAddServer = {},
onOpenDownloads = {},
onBack = {},