-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #446 from GrislyMe/master
spotifyd_dbus: add spotifyd_dbus, show spotifyd status
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 GrislyMe | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Spotifyd dbus status | ||
Show song currently played on Spotifyd | ||
|
||
And provide simple control(Click to pause/start). | ||
![](./example.png) | ||
|
||
## requirement | ||
require dbus-python package. | ||
|
||
require spotifyd with dbus support. (For Arch user is "spotifyd-full-git" in AUR) | ||
|
||
## example config | ||
``` | ||
[spotify] | ||
min_width=Buttom=? | ||
command=$SCRIPT_DIR/spotifyd_dbus $buttom | ||
color=#00FFB3 | ||
interval=10 | ||
``` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import dbus | ||
import sys | ||
|
||
def progressBar(perc : float): | ||
char = ["░", "▒", "█"] | ||
bar = char[2] * int(perc / 0.2) | ||
if perc >= 0.99: | ||
return bar + char[2] | ||
bar += char[1] | ||
while len(bar) != 5: | ||
bar += char[0] | ||
return bar | ||
|
||
def main(): | ||
bus = dbus.SessionBus() | ||
proxy = bus.get_object('org.mpris.MediaPlayer2.spotifyd','/org/mpris/MediaPlayer2') | ||
|
||
properties_manager = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties') | ||
|
||
if properties_manager: | ||
|
||
if len(sys.argv) > 1: | ||
if sys.argv[1] == "1": | ||
dbus.Interface(proxy, 'org.mpris.MediaPlayer2.Player').PlayPause() | ||
|
||
status = properties_manager.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus') | ||
if status == "Playing" : status = " " | ||
else : status = " " | ||
|
||
current = properties_manager.Get('org.mpris.MediaPlayer2.Player', 'Position') | ||
|
||
data = properties_manager.Get('org.mpris.MediaPlayer2.Player', 'Metadata') | ||
length = data["mpris:length"] | ||
title = data["xesam:title"] | ||
|
||
perc = current / length | ||
progress = progressBar(perc) | ||
bar = f" [ {title} ] {status} {progress}" | ||
print(bar) | ||
|
||
if __name__ == "__main__": | ||
main() |