summaryrefslogtreecommitdiff
path: root/polybar
diff options
context:
space:
mode:
Diffstat (limited to 'polybar')
-rwxr-xr-xpolybar/.config/polybar/config18
-rwxr-xr-xpolybar/.config/polybar/spotify.py123
2 files changed, 5 insertions, 136 deletions
diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config
index bb61b5a..82573d1 100755
--- a/polybar/.config/polybar/config
+++ b/polybar/.config/polybar/config
@@ -1,5 +1,6 @@
1[settings] 1[settings]
2screenchange-reload = true 2screenchange-reload = true
3# wm-restack = bspwm
3 4
4[colors] 5[colors]
5#background = ${xrdb:color0:#222} 6#background = ${xrdb:color0:#222}
@@ -31,10 +32,10 @@ padding-left = 2
31padding-right = 2 32padding-right = 2
32module-margin-left = 1.5 33module-margin-left = 1.5
33module-margin-right = 1.5 34module-margin-right = 1.5
34font-0 = Hermit:style=medium:size=9;1 35font-0 = JetBrains Mono Nerd Font Mono:style=medium:pixelsize=10:antialias=true:autohint=true:lcdfilter=lcddefault:rgba=rgb
35modules-left = pulseaudio battery date time bspwm 36modules-left = pulseaudio battery date time cmus
36modules-center = 37modules-center =
37modules-right = cmus 38modules-right = bspwm
38tray-position = right 39tray-position = right
39cursor-click = pointer 40cursor-click = pointer
40cursor-scroll = ns-resize 41cursor-scroll = ns-resize
@@ -43,7 +44,6 @@ cursor-scroll = ns-resize
43type = internal/xwindow 44type = internal/xwindow
44label = %title:0:20:...% 45label = %title:0:20:...%
45 46
46
47[module/bspwm] 47[module/bspwm]
48type = internal/bspwm 48type = internal/bspwm
49format = <label-state> <label-mode> 49format = <label-state> <label-mode>
@@ -122,7 +122,7 @@ battery = BAT0
122adapter = ADP1 122adapter = ADP1
123poll-interval = 1 123poll-interval = 1
124;full-at = 98 124;full-at = 98
125label-discharging = -bat %percentage%% 125label-discharging = bat %percentage%%
126label-charging = +bat %percentage%% 126label-charging = +bat %percentage%%
127label-full = ^bat %percentage%% 127label-full = ^bat %percentage%%
128format-discharging = <label-discharging> 128format-discharging = <label-discharging>
@@ -135,14 +135,6 @@ format-volume = vol <label-volume>
135label-volume = %percentage%% 135label-volume = %percentage%%
136label-muted = muted 136label-muted = muted
137 137
138[module/spotify]
139type = custom/script
140interval = 1
141format-prefix = " "
142format = <label>
143format-foreground = #7b8c58
144exec = python ~/.config/polybar/spotify.py -f '{artist}: {song}'
145
146[module/cmus] 138[module/cmus]
147type = custom/script 139type = custom/script
148exec = ~/.config/polybar/cmus.sh 140exec = ~/.config/polybar/cmus.sh
diff --git a/polybar/.config/polybar/spotify.py b/polybar/.config/polybar/spotify.py
deleted file mode 100755
index aae6d81..0000000
--- a/polybar/.config/polybar/spotify.py
+++ /dev/null
@@ -1,123 +0,0 @@
1#!/bin/python
2
3import sys
4import dbus
5import argparse
6
7
8parser = argparse.ArgumentParser()
9parser.add_argument(
10 '-t',
11 '--trunclen',
12 type=int,
13 metavar='trunclen'
14)
15parser.add_argument(
16 '-f',
17 '--format',
18 type=str,
19 metavar='custom format',
20 dest='custom_format'
21)
22parser.add_argument(
23 '-p',
24 '--playpause',
25 type=str,
26 metavar='play-pause indicator',
27 dest='play_pause'
28)
29parser.add_argument(
30 '--font',
31 type=str,
32 metavar='the index of the font to use for the main label',
33 dest='font'
34)
35parser.add_argument(
36 '--playpause-font',
37 type=str,
38 metavar='the index of the font to use to display the playpause indicator',
39 dest='play_pause_font'
40)
41
42
43args = parser.parse_args()
44
45def fix_string(string):
46 # corrects encoding for the python version used
47 if sys.version_info.major == 3:
48 return string
49 else:
50 return string.encode('utf-8')
51
52# Default parameters
53output = fix_string(u'{play_pause} {artist}: {song}')
54trunclen = 25
55play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused
56
57label_with_font = '%{{T{font}}}{label}%{{T-}}'
58font = args.font
59play_pause_font = args.play_pause_font
60
61# parameters can be overwritten by args
62if args.trunclen is not None:
63 trunclen = args.trunclen
64if args.custom_format is not None:
65 output = args.custom_format
66if args.play_pause is not None:
67 play_pause = args.play_pause
68
69try:
70 session_bus = dbus.SessionBus()
71 spotify_bus = session_bus.get_object(
72 'org.mpris.MediaPlayer2.spotify',
73 '/org/mpris/MediaPlayer2'
74 )
75
76 spotify_properties = dbus.Interface(
77 spotify_bus,
78 'org.freedesktop.DBus.Properties'
79 )
80
81 metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
82 status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
83
84 # Handle play/pause label
85
86 play_pause = play_pause.split(',')
87
88 if status == 'Playing':
89 play_pause = play_pause[0]
90 elif status == 'Paused':
91 play_pause = play_pause[1]
92 else:
93 play_pause = str()
94
95 if play_pause_font:
96 play_pause = label_with_font.format(font=play_pause_font, label=play_pause)
97
98 # Handle main label
99
100 artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else ''
101 song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else ''
102
103 if not artist and not song:
104 print('')
105 else:
106 if len(song) > trunclen:
107 song = song[0:trunclen]
108 song += '...'
109 if ('(' in song) and (')' not in song):
110 song += ')'
111
112 if font:
113 artist = label_with_font.format(font=font, label=artist)
114 song = label_with_font.format(font=font, label=song)
115
116 print(output.format(artist=artist, song=song, play_pause=play_pause))
117
118except Exception as e:
119 if isinstance(e, dbus.exceptions.DBusException):
120 print('')
121 else:
122 print(e)
123