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:
parent
93379449ee
commit
c64119a22b
4 changed files with 18 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue