Closed ibrokemypie closed 6 years ago
Can you paste the needed parts of your config?
[module/player-mpris-tail]
type = custom/script
exec = ~/.config/polybar/player-mpris-tail.py
tail = true
click-left = ~/.config/polybar/player-ctrl.sh previous
click-right = ~/.config/polybar/player-ctrl.sh next
click-middle = ~/.config/polybar/player-ctrl.sh play-pause
And you added player-mpris-tail
to your bar?
Like modules-right = player-mpris-tail
Yes, I did
You are right. I have the same problem here on Fedora. The script run but there is no output.
$ python3 -V
Python 3.6.4
Unfortunately I do not use a player script. So I have not much experience with it. Maybe @Cybolic can help. He was the last one who worked on this script. Let's give him some time to answer.
Maybe it's a case of missing packages; I added a call to dbus-send
. Could you check if that command is available on your system?
dbus-send
is available.
I checked that on my Arch device. It works if I install playerctl
and playerctl-git
.
It's a little bit weird. It works on my Fedora now too. But I haven't changed anything.
@ibrokemypie could you find out something?
@Cybolic should we add python-gobject
as dependency? Otherwise I got an error:
python3 polybar-scripts/polybar-scripts/player-mpris-tail/player-mpris-tail.py
Traceback (most recent call last):
File "polybar-scripts/polybar-scripts/player-mpris-tail/player-mpris-tail.py", line 8, in <module>
gi.require_version('Playerctl', '1.0')
AttributeError: module 'gi' has no attribute 'require_version'
Yes, I think that would be a good idea.
Outside of this issue, I'd like to revisit the script at some point and do a rewrite as it's still not great at handling multiple players and can be redone to not actually need playerctl
(or dbus-send
for that matter). Unfortunately, I'm swamped with work these days, but I do expect to get on it within a month or so.
As for solving this, with your player open, what do you get when running the following?
dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep org.mpris.MediaPlayer2
string "org.mpris.MediaPlayer2.rhythmbox"
That is my output.
No hurry. As long as everything works, here is not much to fix. I don't think the dbus is the problem. I guess it is the existing script. It looks a bit unstable. Multiple players use different keys.
I have both playerctl and dbus-send
dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep org.mpris.MediaPlayer2
string "org.mpris.MediaPlayer2.cmus"
The update does seem to work for me though
I've finally gotten a bit of time to look at the rewrite and I have the status part up and running well enough to use it for my own daily use. If anyone wants to try it out, use the following script instead of the one in exec = ~/.config/polybar/player-mpris-tail.py
https://gist.github.com/Cybolic/3ad51365f0d329b0ac2bc177ea721af5
This one doesn't have any dependencies other than the python dbus module.
Can we build a script which merges the running script and the player-ctrl.sh
?
Meaning a script that will provide the functionality of player-ctrl.sh
when given the appropriate arguments? That's on my roadmap :)
So that you have to install just one script.
You are the man and this is your script. :beer:
I've updated the script in the link so it now supports the basic playback controls that playertrl does (minus seek, volume and getting metadata/status). I'd be grateful if people could try this out and see how it works for them so I can get an idea of how far we are from this replacing the current script.
@nealot I'm running it as follows:
[module/player-mpris-tail]
type = custom/script
exec = ~/INSERT_DOWNLOAD_PATH_HERE/player-mpris-tail2.py
tail = true
label = %output:0:60%...
click-left = ~/INSERT_DOWNLOAD_PATH_HERE/player-mpris-tail2.py previous
click-right = ~/INSERT_DOWNLOAD_PATH_HERE/player-mpris-tail2.py next
click-middle = ~/INSERT_DOWNLOAD_PATH_HERE/player-mpris-tail2.py play-pause
@Cybolic Thanks! But I can't seem to get it working. I'm using https://github.com/mps-youtube/mps-youtube and it only displays the closed icon.
For mpris2 support, install the python bindings for dbus and gobject:
$ pip3 install --user dbus-python pygobject
I have the module already installed but some songs aren't being recognized. Does the script only work if an artist is specified? Because mpsyt sometimes only lists the title.
if len(self.metadata['artist']) and (self.metadata['title']):
This seems to be the suspect line.
Should it be modified to print whichever metadata exists? So, if the title isn't provided it would just print the artist and vice versa.
Yes. I was getting overlapping results from running VLC, plasma-browser-integration and cantata at the same time, which is why I added that condition. The plan is to remove it and replace it with a format and a blacklist argument instead.
I've updated the script again to remove the restriction on the artist and added the blacklisting as well as formatting (with conditional text), so you can run it as this:
player-mpris-tail2.p --blacklist plasma-browser-integration -b vlc -f '{title}{:album: on {album}:}{:year: ({year}):}{:artist: by {artist}:}'
which will leave plasma-browser-integration and vlc alone and print the status with the on {album}
, (year)
and by {artist}
parts only if the album, year or artist tags aren't empty respectively.
EDIT: Oh, also added a raise
command to focus the current player (for mouse bindings).
Updated the script:
list
, current
and metadata
I think it's pretty close to being able to replace the old script; has anyone had any issues?
Is the script supposed to know if the application has been closed? When I open mpsyt and then exit it just keeps the last output it had.
@nealot It is supposed to detect that, yes, but it'll keep showing the last status (useful for when paused). I'll see about properly detecting when nothing is active and clear the output when that happens.
@nealot Your issue should be fixed with the latest update. I've also added options to set the icons used, improved performance a bit by not updating text when only the seek position has changed and fixed a few silly copy-paste errors that kept stop/previous/next from working.
Everything works well for me now :+1:. Also, I prefer the icon layout below so if anyone else shares this preference they could use:
exec = player-mpris-tail2.py -f '{:artist:{artist} - :}{title}'
label = %output:0:30: . . .% %{A1:playerctl previous:}%{A} %{A1:playerctl play-pause:}%{A} %{A1:playerctl next:}%{A}
The downside is that it doesn't change the pause button. Any ways I could work around this?
Okay, I may have gone overboard with handling your case @nealot :stuck_out_tongue:
I extended the formatting handling to not touch Polybar's syntax so you can pass it directly, and also added basic width handling for the fields as the second "part" of the format block (or the first if we don't want it conditional).
i.e.:
{:w10:text:}
to crop the text
to 10 chars
{:t10:text:}
to truncate the text
to 10 chars, appending ...
to it if it's longer than that
This also works with conditional tags: {:artist:w10:{artist} - :}
or {:album:t10: - {album}:}
.
I also added a tag for a reversed icon that shows the pause icon when playing and the play icon at all other times.
For your case, that means you can do the following:
exec = player-mpris-tail2.py -f '{:artist:t12:{artist}:}{:artist: - :}{:t15:{title}:} %{A1:playerctl previous:}%{A} %{A1:playerctl play-pause:}{icon-reversed}%{A} %{A1:playerctl next:}%{A}'
label = %output%
That's actually awesome -- thank you!
You're welcome! I've adopted a version of your label now myself, so I definitely got something out of it as well :wink:
I'll keep running with this for a few days and if no new issues pop up here or on my machine, I'll document the formatting and send a pull request.
Hey, when trying to use player-mpris-tail I simply get no output in my bar. Playerctl itself correctly shows my players and the current status, but even running the script manually does nothing. I am on arch linux with python up to date.