fix: PC steuern zeigt Cover scharf statt 60x60 Pixel (v1.2.1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-05 21:21:15 +01:00
co-authored by Claude Opus 5.5
parent 7a01655e43
commit 968920e7f3
4 changed files with 40 additions and 13 deletions
@@ -67,7 +67,7 @@ object PcRemote {
visibleTab = state.optString("visibleTab", activeTab),
title = tab.text("title"),
subtitle = tab.text("subtitle"),
thumbnail = tab.text("thumbnail").takeIf { it.startsWith("https://") }.orEmpty(),
thumbnail = largeCover(tab.text("thumbnail").takeIf { it.startsWith("https://") }.orEmpty()),
playing = tab?.optBoolean("playing") ?: false,
position = tab?.optDouble("currentTime")?.takeIf { it.isFinite() } ?: 0.0,
duration = tab?.optDouble("duration")?.takeIf { it.isFinite() } ?: 0.0,
@@ -76,6 +76,20 @@ object PcRemote {
)
}
private val GOOGLE_IMAGE_SIZE = Regex("=(w\\d+-h\\d+|s\\d+)[^/=]*$")
private val YTIMG_SMALL = Regex("/(default|mqdefault)\\.jpg$")
/**
* Das Cover aus der YouTube-Music-Player-Leiste ist nur 60x60 Pixel gross ("=w60-h60-l90-rj") -
* fuer die Fernbedienung in 544x544 anfordern; kleine YouTube-Vorschaubilder durch hqdefault ersetzen.
*/
fun largeCover(url: String): String = when {
url.contains("googleusercontent.com") || url.contains("ggpht.com") ->
url.replace(GOOGLE_IMAGE_SIZE, "=w544-h544-l90-rj")
url.contains("ytimg.com") -> url.replace(YTIMG_SMALL, "/hqdefault.jpg")
else -> url
}
/** Textfeld ohne JSON-null ("null" als Text waere sonst sichtbar). */
private fun JSONObject?.text(key: String): String =
if (this == null || isNull(key)) "" else optString(key)
@@ -71,6 +71,21 @@ class PcRemoteTest {
assertNull(PcRemote.parseState(JSONObject("""{"ok": true}""")))
}
@Test
fun requestsLargeCovers() {
assertEquals(
"https://lh3.googleusercontent.com/abc=w544-h544-l90-rj",
PcRemote.largeCover("https://lh3.googleusercontent.com/abc=w60-h60-l90-rj"),
)
assertEquals(
"https://yt3.ggpht.com/xyz=w544-h544-l90-rj",
PcRemote.largeCover("https://yt3.ggpht.com/xyz=s88-c-k-c0x00ffffff-no-rj"),
)
assertEquals("https://i.ytimg.com/vi/id/hqdefault.jpg", PcRemote.largeCover("https://i.ytimg.com/vi/id/default.jpg"))
assertEquals("https://i.ytimg.com/vi/id/hqdefault.jpg", PcRemote.largeCover("https://i.ytimg.com/vi/id/hqdefault.jpg"))
assertEquals("https://example.com/a.png", PcRemote.largeCover("https://example.com/a.png"))
}
@Test
fun formatsTimes() {
assertEquals("0:00", PcRemote.formatTime(-5.0))