Skip to content

Commit

Permalink
use vlc:nowplaying in mpris widget
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Feb 18, 2022
1 parent ea5015f commit 6e4dc60
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions source/dwinbar/widgets/mediaplayer.d
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,32 @@ class MprisMediaPlayerWidget : Widget, IMouseWatch
{
auto artist = "xesam:artist" in metadata;
auto title = "xesam:title" in metadata;
auto nowplaying = "vlc:nowplaying" in metadata;

string song;

if (artist)
if (nowplaying && nowplaying.data.type == 's')
{
if (artist.data.type == 'a' && artist.data.signature == "s")
song = artist.data.to!(string[]).join(", ") ~ " - ";
else if (artist.data.type == 's')
song = artist.data.to!string ~ " - ";
song = nowplaying.data.to!string;
}
else
{
if (artist)
{
if (artist.data.type == 'a' && artist.data.signature == "s")
song = artist.data.to!(string[]).join(", ") ~ " - ";
else if (artist.data.type == 's')
song = artist.data.to!string ~ " - ";
}

if (title)
song ~= title.data.get!string;
else if (song.length)
song.length -= 3;
if (title)
song ~= title.data.get!string;
else if (song.length)
song.length -= 3;

if (!song.length)
song = "Unknown";
if (!song.length)
song = "Unknown";
}

if (song == label)
return false;
Expand Down Expand Up @@ -361,6 +369,8 @@ class MprisMediaPlayerWidget : Widget, IMouseWatch
if (!owner.isMprisName)
return;

stderr.writeln("Name change: ", owner, ": ", old, " -> ", new_);

if (!old.length && new_.length)
addName(owner);
else if (old.length && !new_.length)
Expand Down Expand Up @@ -395,7 +405,7 @@ class MprisMediaPlayerWidget : Widget, IMouseWatch
registerMethods(router, ObjectPath("/org/webfreak/DWinBar"),
interfaceName("org.webfreak.DWinBar.ActiveMprisController"), activeController);
registerRouter(sessionBus.conn, router);
enforce(requestName(sessionBus.conn, busName("org.webfreak.DWinBar")));
enforce(requestName(sessionBus.conn, busName("org.webfreak.DWinBar")), "Failed owning name org.webfreak.DWinBar");

sessionBus.onNameChange(&changeName);
names = sessionBus.listNames().filter!isMprisName.array;
Expand Down

0 comments on commit 6e4dc60

Please sign in to comment.