forked from Shinonome/dots-hyprland
media controls: make cover art download more reliable
This commit is contained in:
@@ -88,6 +88,7 @@ Scope {
|
|||||||
}
|
}
|
||||||
delegate: PlayerControl {
|
delegate: PlayerControl {
|
||||||
required property MprisPlayer modelData
|
required property MprisPlayer modelData
|
||||||
|
artDownloadLocation: root.baseCoverArtDir
|
||||||
player: modelData
|
player: modelData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ Item { // Player instance
|
|||||||
id: playerController
|
id: playerController
|
||||||
required property MprisPlayer player
|
required property MprisPlayer player
|
||||||
property var artUrl: player?.trackArtUrl
|
property var artUrl: player?.trackArtUrl
|
||||||
|
property string artDownloadLocation: FileUtils.trimFileProtocol(`${XdgDirectories.cache}/media/coverart`)
|
||||||
|
property string artFileName: Qt.md5(artUrl) + ".jpg"
|
||||||
|
property string artFilePath: `${artDownloadLocation}/${artFileName}`
|
||||||
property color artDominantColor: Appearance.m3colors.m3secondaryContainer
|
property color artDominantColor: Appearance.m3colors.m3secondaryContainer
|
||||||
|
property bool downloaded: false
|
||||||
|
|
||||||
implicitWidth: widgetWidth
|
implicitWidth: widgetWidth
|
||||||
implicitHeight: widgetHeight
|
implicitHeight: widgetHeight
|
||||||
@@ -60,8 +64,27 @@ Item { // Player instance
|
|||||||
playerController.artDominantColor = Appearance.m3colors.m3secondaryContainer
|
playerController.artDominantColor = Appearance.m3colors.m3secondaryContainer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
colorQuantizer.targetFile = playerController.artUrl // Yes this binding break is intentional
|
// console.log("PlayerControl: Art URL changed to", playerController.artUrl)
|
||||||
colorQuantizer.running = true
|
// console.log("Download cmd:", coverArtDownloader.command.join(" "))
|
||||||
|
playerController.downloaded = false
|
||||||
|
coverArtDownloader.running = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Process { // Cover art downloader
|
||||||
|
id: coverArtDownloader
|
||||||
|
property string targetFile: playerController.artUrl
|
||||||
|
command: [ "bash", "-c", `[ -f ${artFilePath} ] || curl -sSL '${targetFile}' -o '${artFilePath}'` ]
|
||||||
|
stdout: SplitParser {
|
||||||
|
onRead: data => {
|
||||||
|
// console.log("Color quantizer output:", data)
|
||||||
|
playerController.artDominantColor = "#" + data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onExited: (exitCode, exitStatus) => {
|
||||||
|
colorQuantizer.targetFile = playerController.artUrl // Yes this binding break is intentional
|
||||||
|
colorQuantizer.running = true
|
||||||
|
playerController.downloaded = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Process { // Average Color Runner
|
Process { // Average Color Runner
|
||||||
@@ -113,7 +136,7 @@ Item { // Player instance
|
|||||||
id: blurredArt
|
id: blurredArt
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
visible: true
|
visible: true
|
||||||
source: playerController.artUrl
|
source: playerController.downloaded ? Qt.resolvedUrl(artFilePath) : ""
|
||||||
sourceSize.width: background.width
|
sourceSize.width: background.width
|
||||||
sourceSize.height: background.height
|
sourceSize.height: background.height
|
||||||
fillMode: Image.PreserveAspectCrop
|
fillMode: Image.PreserveAspectCrop
|
||||||
|
|||||||
Reference in New Issue
Block a user