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>
This commit is contained in:
İlyas 2026-03-28 13:58:16 +03:00 committed by GitHub
parent 93379449ee
commit c64119a22b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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) {