From c64119a22b9af16dc696522b8342ce168c878256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0lyas?= <67807483+Mestane@users.noreply.github.com> Date: Sat, 28 Mar 2026 13:58:16 +0300 Subject: [PATCH] fix: YouTube thumbnail fallback for missing mpris:artUrl (#1347) * fix: YouTube thumbnail fallback for missing mpris:artUrl * fix --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> --- modules/dashboard/Media.qml | 2 +- modules/dashboard/dash/Media.qml | 2 +- modules/lock/Media.qml | 2 +- services/Players.qml | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/dashboard/Media.qml b/modules/dashboard/Media.qml index 49046185..4c838a5f 100644 --- a/modules/dashboard/Media.qml +++ b/modules/dashboard/Media.qml @@ -181,7 +181,7 @@ Item { anchors.fill: parent - source: Players.active?.trackArtUrl ?? "" // qmllint disable incompatible-type + source: Players.getArtUrl(Players.active) asynchronous: true fillMode: Image.PreserveAspectCrop sourceSize.width: width diff --git a/modules/dashboard/dash/Media.qml b/modules/dashboard/dash/Media.qml index 1a4f0c93..4f50531c 100644 --- a/modules/dashboard/dash/Media.qml +++ b/modules/dashboard/dash/Media.qml @@ -106,7 +106,7 @@ Item { anchors.fill: parent - source: Players.active?.trackArtUrl ?? "" // qmllint disable incompatible-type + source: Players.getArtUrl(Players.active) asynchronous: true fillMode: Image.PreserveAspectCrop sourceSize.width: width diff --git a/modules/lock/Media.qml b/modules/lock/Media.qml index cabe60b9..9d2a0367 100644 --- a/modules/lock/Media.qml +++ b/modules/lock/Media.qml @@ -18,7 +18,7 @@ Item { Image { anchors.fill: parent - source: Players.active?.trackArtUrl ?? "" // qmllint disable incompatible-type + source: Players.getArtUrl(Players.active) asynchronous: true fillMode: Image.PreserveAspectCrop diff --git a/services/Players.qml b/services/Players.qml index d51b5df3..526b0044 100644 --- a/services/Players.qml +++ b/services/Players.qml @@ -20,6 +20,21 @@ Singleton { return alias?.to ?? player.identity; } + function getArtUrl(player: MprisPlayer): string { + if (!player) + return ""; + if (player.trackArtUrl) + return player.trackArtUrl; + + const url = player.metadata["xesam:url"] ?? ""; + if (url.startsWith("https://www.youtube.com/watch")) { + // Fallback for youtube + const id = url.match(/[?&]v=([\w-]{11})/)?.[1]; + return id ? `https://img.youtube.com/vi/${id}/hqdefault.jpg` : ""; + } + return ""; + } + Connections { function onPostTrackChanged() { if (!Config.utilities.toasts.nowPlaying) {