Merge pull request #793 from ouuan/playerctl
[modules/playerctl]: use `playerctl -f` and add `playerctl.args`
This commit is contained in:
commit
ec71d7fbbe
2 changed files with 37 additions and 36 deletions
|
@ -6,12 +6,14 @@ Requires the following executable:
|
||||||
* playerctl
|
* playerctl
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* playerctl.format: Format string (defaults to '{artist} - {title}')
|
* playerctl.format: Format string (defaults to '{{artist}} - {{title}} {{duration(position)}}/{{duration(mpris:length)}}').
|
||||||
Available values are: {album}, {title}, {artist}, {trackNumber}
|
The format string is passed to 'playerctl -f' as an argument. Read `the README <https://github.com/altdesktop/playerctl#printing-properties-and-metadata>`_ for more information.
|
||||||
* playerctl.layout: Comma-separated list to change order of widgets (defaults to song, previous, pause, next)
|
* playerctl.layout: Comma-separated list to change order of widgets (defaults to song, previous, pause, next)
|
||||||
Widget names are: playerctl.song, playerctl.prev, playerctl.pause, playerctl.next
|
Widget names are: playerctl.song, playerctl.prev, playerctl.pause, playerctl.next
|
||||||
|
* playerctl.args: The arguments added to playerctl.
|
||||||
|
You can check 'playerctl --help' or `its README <https://github.com/altdesktop/playerctl#using-the-cli>`_. For example, it could be '-p vlc,%any'.
|
||||||
|
|
||||||
Parameters are inherited from `spotify` module, many thanks to its developers!
|
Parameters are inspired by the `spotify` module, many thanks to its developers!
|
||||||
|
|
||||||
contributed by `smitajit <https://github.com/smitajit>`_ - many thanks!
|
contributed by `smitajit <https://github.com/smitajit>`_ - many thanks!
|
||||||
"""
|
"""
|
||||||
|
@ -36,9 +38,8 @@ class Module(core.module.Module):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self.__song = ""
|
self.__cmd = "playerctl " + self.parameter("args", "") + " "
|
||||||
self.__cmd = "playerctl "
|
self.__format = self.parameter("format", "{{artist}} - {{title}} {{duration(position)}}/{{duration(mpris:length)}}")
|
||||||
self.__format = self.parameter("format", "{artist} - {title}")
|
|
||||||
|
|
||||||
widget_map = {}
|
widget_map = {}
|
||||||
for widget_name in self.__layout:
|
for widget_name in self.__layout:
|
||||||
|
@ -48,7 +49,6 @@ class Module(core.module.Module):
|
||||||
"button": core.input.LEFT_MOUSE,
|
"button": core.input.LEFT_MOUSE,
|
||||||
"cmd": self.__cmd + "previous",
|
"cmd": self.__cmd + "previous",
|
||||||
}
|
}
|
||||||
widget.set("state", "prev")
|
|
||||||
elif widget_name == "playerctl.pause":
|
elif widget_name == "playerctl.pause":
|
||||||
widget_map[widget] = {
|
widget_map[widget] = {
|
||||||
"button": core.input.LEFT_MOUSE,
|
"button": core.input.LEFT_MOUSE,
|
||||||
|
@ -59,7 +59,6 @@ class Module(core.module.Module):
|
||||||
"button": core.input.LEFT_MOUSE,
|
"button": core.input.LEFT_MOUSE,
|
||||||
"cmd": self.__cmd + "next",
|
"cmd": self.__cmd + "next",
|
||||||
}
|
}
|
||||||
widget.set("state", "next")
|
|
||||||
elif widget_name == "playerctl.song":
|
elif widget_name == "playerctl.song":
|
||||||
widget_map[widget] = [
|
widget_map[widget] = [
|
||||||
{
|
{
|
||||||
|
@ -86,32 +85,32 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
try:
|
try:
|
||||||
self.__get_song()
|
|
||||||
|
|
||||||
for widget in self.widgets():
|
|
||||||
if widget.name == "playerctl.pause":
|
|
||||||
playback_status = str(util.cli.execute(self.__cmd + "status")).strip()
|
playback_status = str(util.cli.execute(self.__cmd + "status")).strip()
|
||||||
if playback_status != "":
|
|
||||||
if playback_status == "Playing":
|
|
||||||
widget.set("state", "playing")
|
|
||||||
else:
|
|
||||||
widget.set("state", "paused")
|
|
||||||
elif widget.name == "playerctl.song":
|
|
||||||
widget.set("state", "song")
|
|
||||||
widget.full_text(self.__song)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
self.__song = ""
|
playback_status = None
|
||||||
|
for widget in self.widgets():
|
||||||
|
if playback_status:
|
||||||
|
if widget.name == "playerctl.pause":
|
||||||
|
if playback_status == "Playing":
|
||||||
|
widget.set("state", "playing")
|
||||||
|
elif playback_status == "Paused":
|
||||||
|
widget.set("state", "paused")
|
||||||
|
else:
|
||||||
|
widget.set("state", "")
|
||||||
|
elif widget.name == "playerctl.next":
|
||||||
|
widget.set("state", "next")
|
||||||
|
elif widget.name == "playerctl.prev":
|
||||||
|
widget.set("state", "prev")
|
||||||
|
elif widget.name == "playerctl.song":
|
||||||
|
widget.full_text(self.__get_song())
|
||||||
|
else:
|
||||||
|
widget.set("state", "")
|
||||||
|
widget.full_text(" ")
|
||||||
|
|
||||||
def __get_song(self):
|
def __get_song(self):
|
||||||
album = str(util.cli.execute(self.__cmd + "metadata xesam:album")).strip()
|
try:
|
||||||
title = str(util.cli.execute(self.__cmd + "metadata xesam:title")).strip()
|
return str(util.cli.execute(self.__cmd + "metadata -f '" + self.__format + "'")).strip()
|
||||||
artist = str(util.cli.execute(self.__cmd + "metadata xesam:albumArtist")).strip()
|
except Exception as e:
|
||||||
track_number = str(util.cli.execute(self.__cmd + "metadata xesam:trackNumber")).strip()
|
logging.exception(e)
|
||||||
|
return " "
|
||||||
self.__song = self.__format.format(
|
|
||||||
album = album,
|
|
||||||
title = title,
|
|
||||||
artist = artist,
|
|
||||||
trackNumber = track_number
|
|
||||||
)
|
|
||||||
|
|
|
@ -1060,12 +1060,14 @@ Requires the following executable:
|
||||||
* playerctl
|
* playerctl
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* playerctl.format: Format string (defaults to '{artist} - {title}')
|
* playerctl.format: Format string (defaults to '{{artist}} - {{title}} {{duration(position)}}/{{duration(mpris:length)}}').
|
||||||
Available values are: {album}, {title}, {artist}, {trackNumber}
|
The format string is passed to 'playerctl -f' as an argument. Read `the README <https://github.com/altdesktop/playerctl#printing-properties-and-metadata>`_ for more information.
|
||||||
* playerctl.layout: Comma-separated list to change order of widgets (defaults to song, previous, pause, next)
|
* playerctl.layout: Comma-separated list to change order of widgets (defaults to song, previous, pause, next)
|
||||||
Widget names are: playerctl.song, playerctl.prev, playerctl.pause, playerctl.next
|
Widget names are: playerctl.song, playerctl.prev, playerctl.pause, playerctl.next
|
||||||
|
* playerctl.args: The arguments added to playerctl.
|
||||||
|
You can check 'playerctl --help' or `its readme <https://github.com/altdesktop/playerctl#using-the-cli>`_. For example, it could be '-p vlc,%any'.
|
||||||
|
|
||||||
Parameters are inherited from `spotify` module, many thanks to its developers!
|
Parameters are inspired by the `spotify` module, many thanks to its developers!
|
||||||
|
|
||||||
contributed by `smitajit <https://github.com/smitajit>`_ - many thanks!
|
contributed by `smitajit <https://github.com/smitajit>`_ - many thanks!
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue