ref: adjusting formatters

This commit is contained in:
tapframe 2026-05-16 03:43:10 +05:30
parent b35010fd4b
commit b217d9c4a6
6 changed files with 34 additions and 21 deletions

View file

@ -1068,7 +1068,7 @@
<string name="streams_resume_from_percent">Pokračovat od %1$d%%</string>
<string name="streams_resume_from_time">Pokračovat od %1$s</string>
<string name="streams_size">VELIKOST %1$s</string>
<string name="streams_torrent_not_supported">Torrent streamy nejsou podporovány</string>
<string name="streams_torrent_not_supported">Tento typ streamu není podporován</string>
<string name="trailer_close">Zavřít trailer</string>
<string name="trailer_unable_to_play">Trailer nelze přehrát</string>
<string name="trakt_lists_load_failed">Nepodařilo se načíst seznamy Trakt</string>

View file

@ -1100,7 +1100,7 @@
<string name="streams_resume_from_percent">Lanjutkan dari %1$d%</string>
<string name="streams_resume_from_time">Lanjutkan dari %1$s</string>
<string name="streams_size">UKURAN %1$s</string>
<string name="streams_torrent_not_supported">Stream torrent tidak didukung</string>
<string name="streams_torrent_not_supported">Jenis stream ini tidak didukung</string>
<string name="trailer_close">Tutup trailer</string>
<string name="trailer_unable_to_play">Tidak dapat memutar trailer</string>
<string name="trakt_lists_load_failed">Gagal memuat daftar Trakt</string>

View file

@ -575,24 +575,24 @@
<string name="settings_integrations_section_title">Integrations</string>
<string name="settings_integrations_tmdb_description">Metadata enrichment controls</string>
<string name="settings_integrations_mdblist_description">External ratings providers</string>
<string name="settings_integrations_debrid_description">Instant cached Debrid streams</string>
<string name="settings_debrid_section_title">Direct Debrid</string>
<string name="settings_debrid_enable">Enable Debrid streams</string>
<string name="settings_debrid_enable_description">Show instant cached Debrid streams.</string>
<string name="settings_debrid_add_key_first">Add an API key before enabling Debrid streams.</string>
<string name="settings_integrations_debrid_description">Cloud account sources</string>
<string name="settings_debrid_section_title">Debrid</string>
<string name="settings_debrid_enable">Enable sources</string>
<string name="settings_debrid_enable_description">Show playable results from connected accounts.</string>
<string name="settings_debrid_add_key_first">Add an API key first.</string>
<string name="settings_debrid_section_providers">Account</string>
<string name="settings_debrid_provider_torbox_description">Use Torbox for instant cached streams.</string>
<string name="settings_debrid_provider_torbox_description">Connect your Torbox account.</string>
<string name="settings_debrid_section_instant_playback">Instant Playback</string>
<string name="settings_debrid_prepare_instant_playback">Prepare instant playback</string>
<string name="settings_debrid_prepare_instant_playback_description">Get Torbox streams ready before you press play.</string>
<string name="settings_debrid_prepare_stream_count">Streams to prepare</string>
<string name="settings_debrid_prepare_count_one">1 stream</string>
<string name="settings_debrid_prepare_count_many">%d streams</string>
<string name="settings_debrid_section_formatting">Stream Formatting</string>
<string name="settings_debrid_prepare_instant_playback">Prepare links</string>
<string name="settings_debrid_prepare_instant_playback_description">Resolve the first sources before playback starts.</string>
<string name="settings_debrid_prepare_stream_count">Sources to prepare</string>
<string name="settings_debrid_prepare_count_one">1 source</string>
<string name="settings_debrid_prepare_count_many">%1$d sources</string>
<string name="settings_debrid_section_formatting">Formatting</string>
<string name="settings_debrid_name_template">Name template</string>
<string name="settings_debrid_name_template_description">Controls how Debrid stream names appear in source lists.</string>
<string name="settings_debrid_name_template_description">Controls how source names appear.</string>
<string name="settings_debrid_description_template">Description template</string>
<string name="settings_debrid_description_template_description">Controls the metadata lines shown under each Debrid stream.</string>
<string name="settings_debrid_description_template_description">Controls the metadata shown under each source.</string>
<string name="settings_debrid_key_valid">API key validated.</string>
<string name="settings_debrid_key_invalid">Could not validate this API key.</string>
<string name="settings_mdb_add_api_key_first">Add your MDBList API key below before turning ratings on.</string>
@ -1129,7 +1129,7 @@
<string name="streams_resume_from_percent">Resume from %1$d%</string>
<string name="streams_resume_from_time">Resume from %1$s</string>
<string name="streams_size">SIZE %1$s</string>
<string name="streams_torrent_not_supported">Torrent streams are not supported</string>
<string name="streams_torrent_not_supported">This stream type is not supported</string>
<string name="debrid_missing_api_key">Add a Debrid API key in Settings.</string>
<string name="debrid_stream_stale">This Debrid result expired. Refreshing streams.</string>
<string name="debrid_resolve_failed">Could not resolve this Debrid stream.</string>

View file

@ -60,8 +60,8 @@ class DebridStreamFormatter(
"stream.audioChannels" to parsed?.channels.orEmpty(),
"stream.languages" to parsed?.languages.orEmpty(),
"stream.languageEmojis" to parsed?.languages.orEmpty().map { languageEmoji(it) },
"stream.size" to (raw?.size ?: stream.behaviorHints.videoSize),
"stream.folderSize" to raw?.folderSize,
"stream.size" to (raw?.size ?: stream.behaviorHints.videoSize)?.let(::DebridTemplateBytes),
"stream.folderSize" to raw?.folderSize?.let(::DebridTemplateBytes),
"stream.encode" to parsed?.codec?.uppercase(),
"stream.indexer" to (raw?.indexer ?: raw?.tracker),
"stream.network" to (parsed?.network ?: raw?.network),

View file

@ -3,6 +3,8 @@ package com.nuvio.app.features.debrid
import kotlin.math.abs
import kotlin.math.roundToLong
internal data class DebridTemplateBytes(val value: Long)
class DebridStreamTemplateEngine {
fun render(template: String, values: Map<String, Any?>): String {
if (template.isEmpty()) return ""
@ -299,6 +301,7 @@ class DebridStreamTemplateEngine {
private fun isTruthy(value: Any?): Boolean =
when (value) {
is Boolean -> value
is DebridTemplateBytes -> value.value != 0L
is Number -> value.toDouble() != 0.0
else -> exists(value)
}
@ -313,6 +316,7 @@ class DebridStreamTemplateEngine {
private fun asNumber(value: Any?): Double? =
when (value) {
is Number -> value.toDouble()
is DebridTemplateBytes -> value.value.toDouble()
is String -> value.toDoubleOrNull()
else -> null
}
@ -339,6 +343,7 @@ class DebridStreamTemplateEngine {
when (value) {
null -> ""
is Iterable<*> -> value.mapNotNull { valueToText(it).takeIf { text -> text.isNotBlank() } }.joinToString(", ")
is DebridTemplateBytes -> formatBytes(value.value.toDouble())
is Double -> if (value % 1.0 == 0.0) value.toLong().toString() else value.toString()
is Float -> if (value % 1f == 0f) value.toLong().toString() else value.toString()
else -> value.toString()
@ -387,4 +392,3 @@ class DebridStreamTemplateEngine {
}
}
}

View file

@ -32,5 +32,14 @@ class DebridStreamTemplateEngineTest {
assertEquals("1.5 GB DTS | Atmos", rendered)
}
}
@Test
fun `renders Debrid size values as readable text while keeping numeric comparisons`() {
val rendered = engine.render(
"{stream.size::>0[\"{stream.size}\"||\"\"]}",
mapOf("stream.size" to DebridTemplateBytes(7_361_184_308L)),
)
assertEquals("6.9 GB", rendered)
}
}