Implemented MPRIS metadata "mpris:artUrl"
This commit is contained in:
parent
9416ac6737
commit
a236370d47
3 changed files with 29 additions and 1 deletions
|
@ -62,8 +62,12 @@ class MPRISPlayer(DbusInterfaceCommonAsync, interface_name=MPRIS_PLAYER_INTERFAC
|
||||||
await self.Metadata.set_async(self.to_xesam(metadata))
|
await self.Metadata.set_async(self.to_xesam(metadata))
|
||||||
|
|
||||||
def to_xesam(self, metadata: "TrackMetadata") -> dict:
|
def to_xesam(self, metadata: "TrackMetadata") -> dict:
|
||||||
|
# cache name by filename without extension
|
||||||
|
art_path = self.app.utils.tmp_path + "/cover_cache/" + metadata.path.split("/")[-1][:-4]
|
||||||
|
|
||||||
xesam_metadata = {
|
xesam_metadata = {
|
||||||
"mpris:trackid": ("s", "kjuztuktg"),
|
"mpris:trackid": ("s", "kjuztuktg"), # nonsense, no functionality
|
||||||
|
"mpris:artUrl": ("s", "file://" + art_path),
|
||||||
"xesam:title": ("s", metadata.title),
|
"xesam:title": ("s", metadata.title),
|
||||||
"xesam:artist": ("as", [metadata.artist])
|
"xesam:artist": ("as", [metadata.artist])
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import pygame.mixer
|
import pygame.mixer
|
||||||
|
@ -40,6 +41,8 @@ class Player:
|
||||||
self.paused = False
|
self.paused = False
|
||||||
|
|
||||||
self.app.gui.on_playstate_update()
|
self.app.gui.on_playstate_update()
|
||||||
|
|
||||||
|
self.export_cover_art_tmp()
|
||||||
self.mpris_server.exec_async(self.mpris_server.set_metadata(self.current_playlist.current_track.metadata))
|
self.mpris_server.exec_async(self.mpris_server.set_metadata(self.current_playlist.current_track.metadata))
|
||||||
|
|
||||||
# cache next track so it immediately starts when the current track finishes
|
# cache next track so it immediately starts when the current track finishes
|
||||||
|
@ -217,3 +220,23 @@ class Player:
|
||||||
self.start_playlist(playlist)
|
self.start_playlist(playlist)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def export_cover_art_tmp(self) -> None:
|
||||||
|
"""
|
||||||
|
Export the cover art of the current track to /tmp/wobuzz/current_cover, so MPRIS can access it.
|
||||||
|
"""
|
||||||
|
|
||||||
|
metadata = self.current_playlist.current_track.metadata
|
||||||
|
|
||||||
|
art_tmp_path = self.app.utils.tmp_path + "/cover_cache/"
|
||||||
|
art_path = art_tmp_path + metadata.path.split("/")[-1][:-4]
|
||||||
|
|
||||||
|
if os.path.isfile(art_path): # cover art already exported
|
||||||
|
return
|
||||||
|
|
||||||
|
if not os.path.exists(art_tmp_path):
|
||||||
|
os.makedirs(art_tmp_path)
|
||||||
|
|
||||||
|
file = open(art_path, "wb")
|
||||||
|
file.write(metadata.images.any.data)
|
||||||
|
file.close()
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Utils:
|
||||||
home_path = str(Path.home())
|
home_path = str(Path.home())
|
||||||
wobuzz_location = os.path.dirname(os.path.abspath(__file__))
|
wobuzz_location = os.path.dirname(os.path.abspath(__file__))
|
||||||
settings_location = f"{wobuzz_location}/settings.json"
|
settings_location = f"{wobuzz_location}/settings.json"
|
||||||
|
tmp_path = "/tmp/wobuzz"
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue