diff options
author | Yigit Sever | 2019-10-30 00:36:19 +0300 |
---|---|---|
committer | Yigit Sever | 2019-10-30 00:36:19 +0300 |
commit | d1c0127a9c3292239ef7ac357566d0575cd026f7 (patch) | |
tree | 8ec7f9c98f21283c263f11be737bbe00d5858bfe /.config | |
parent | cd5002de11e6fc5ebd7c354f23342d4be04470e0 (diff) | |
download | dotfiles-d1c0127a9c3292239ef7ac357566d0575cd026f7.tar.gz dotfiles-d1c0127a9c3292239ef7ac357566d0575cd026f7.tar.bz2 dotfiles-d1c0127a9c3292239ef7ac357566d0575cd026f7.zip |
Polybar spotify update
Diffstat (limited to '.config')
-rw-r--r-- | .config/polybar/config##desktop.Linux.Lowe | 36 | ||||
-rw-r--r-- | .config/polybar/config##desktop.Linux.Maus | 2 | ||||
-rwxr-xr-x | .config/polybar/pulseaudio-control.sh | 2 | ||||
-rw-r--r-- | .config/polybar/spotify_status.py | 123 |
4 files changed, 151 insertions, 12 deletions
diff --git a/.config/polybar/config##desktop.Linux.Lowe b/.config/polybar/config##desktop.Linux.Lowe index f0670d5..488edc4 100644 --- a/.config/polybar/config##desktop.Linux.Lowe +++ b/.config/polybar/config##desktop.Linux.Lowe | |||
@@ -52,7 +52,7 @@ font-1 = Lato:size=10;1 | |||
52 | font-2 = Raleway:size=10;1 | 52 | font-2 = Raleway:size=10;1 |
53 | font-3 = FuraCode Nerd Font:size=11;2 | 53 | font-3 = FuraCode Nerd Font:size=11;2 |
54 | 54 | ||
55 | modules-left = i3 pulseaudio spotify | 55 | modules-left = i3 pulseaudio-control spotify |
56 | modules-center = xwindow | 56 | modules-center = xwindow |
57 | modules-right = focus date time xkeyboard | 57 | modules-right = focus date time xkeyboard |
58 | 58 | ||
@@ -96,8 +96,8 @@ y-offset = 10 | |||
96 | label-padding = 1 | 96 | label-padding = 1 |
97 | label-font = 1 | 97 | label-font = 1 |
98 | 98 | ||
99 | label-empty = ﳓ | 99 | label-empty = |
100 | label-empty-font = 4 | 100 | label-empty-font = 3 |
101 | label-empty-padding = 5 | 101 | label-empty-padding = 5 |
102 | 102 | ||
103 | [module/xkeyboard] | 103 | [module/xkeyboard] |
@@ -108,11 +108,11 @@ blacklist-1 = scroll lock | |||
108 | format = <label-layout> <label-indicator> | 108 | format = <label-layout> <label-indicator> |
109 | format-spacing = 0 | 109 | format-spacing = 0 |
110 | 110 | ||
111 | format-prefix = | 111 | format-prefix = |
112 | format-prefix-padding = 1 | 112 | format-prefix-padding = 1 |
113 | format-prefix-background = ${colors.blue} | 113 | format-prefix-background = ${colors.blue} |
114 | format-prefix-foreground = ${colors.foreground} | 114 | format-prefix-foreground = ${colors.foreground} |
115 | format-prefix-font = 4 | 115 | format-prefix-font = 3 |
116 | 116 | ||
117 | label-layout = %layout% | 117 | label-layout = %layout% |
118 | label-layout-padding = 1 | 118 | label-layout-padding = 1 |
@@ -202,7 +202,7 @@ format = <label> | |||
202 | format-prefix = | 202 | format-prefix = |
203 | format-prefix-background = ${colors.orange} | 203 | format-prefix-background = ${colors.orange} |
204 | format-prefix-foreground = ${colors.foreground} | 204 | format-prefix-foreground = ${colors.foreground} |
205 | format-prefix-font = 4 | 205 | format-prefix-font = 3 |
206 | format-prefix-padding = 1 | 206 | format-prefix-padding = 1 |
207 | 207 | ||
208 | label-background = ${colors.background_modules} | 208 | label-background = ${colors.background_modules} |
@@ -217,10 +217,10 @@ time = %H:%M | |||
217 | label = %time% | 217 | label = %time% |
218 | format = <label> | 218 | format = <label> |
219 | 219 | ||
220 | format-prefix = | 220 | format-prefix = |
221 | format-prefix-background = ${colors.secondary} | 221 | format-prefix-background = ${colors.secondary} |
222 | format-prefix-foreground = ${colors.foreground} | 222 | format-prefix-foreground = ${colors.foreground} |
223 | format-prefix-font = 4 | 223 | format-prefix-font = 3 |
224 | format-prefix-padding = 1 | 224 | format-prefix-padding = 1 |
225 | 225 | ||
226 | label-background = ${colors.background_modules} | 226 | label-background = ${colors.background_modules} |
@@ -233,10 +233,10 @@ interval = 5 | |||
233 | 233 | ||
234 | format-volume = <label-volume> | 234 | format-volume = <label-volume> |
235 | 235 | ||
236 | format-volume-prefix = ♫ | 236 | format-volume-prefix = |
237 | format-volume-prefix-background = ${colors.purple} | 237 | format-volume-prefix-background = ${colors.purple} |
238 | format-volume-prefix-foreground = ${colors.background_modules} | 238 | format-volume-prefix-foreground = ${colors.background_modules} |
239 | format-volume-prefix-font = 4 | 239 | format-volume-prefix-font = 3 |
240 | format-volume-prefix-padding = 1 | 240 | format-volume-prefix-padding = 1 |
241 | 241 | ||
242 | label-volume = %percentage% | 242 | label-volume = %percentage% |
@@ -249,6 +249,22 @@ label-muted-background = ${colors.purple} | |||
249 | label-muted-foreground = ${colors.foreground} | 249 | label-muted-foreground = ${colors.foreground} |
250 | label-muted-padding = 2 | 250 | label-muted-padding = 2 |
251 | 251 | ||
252 | [module/pulseaudio-control] | ||
253 | type = custom/script | ||
254 | tail = true | ||
255 | label = %output% | ||
256 | interval = 5 | ||
257 | |||
258 | exec = ~/.config/polybar/pulseaudio-control.sh --listen | ||
259 | click-right = exec pavucontrol & | ||
260 | click-left = ~/.config/polybar/pulseaudio-control.sh --togmute | ||
261 | click-middle = ~/.config/polybar/pulseaudio-control.sh --change | ||
262 | scroll-up = ~/.config/polybar/pulseaudio-control.sh --up | ||
263 | scroll-down = ~/.config/polybar/pulseaudio-control.sh --down | ||
264 | label-padding = 2 | ||
265 | label-foreground = ${colors.foreground_modules} | ||
266 | label-background = ${colors.background_modules} | ||
267 | |||
252 | [settings] | 268 | [settings] |
253 | screenchange-reload = true | 269 | screenchange-reload = true |
254 | compositing-background = source | 270 | compositing-background = source |
diff --git a/.config/polybar/config##desktop.Linux.Maus b/.config/polybar/config##desktop.Linux.Maus index f9686ae..0c8ce3d 100644 --- a/.config/polybar/config##desktop.Linux.Maus +++ b/.config/polybar/config##desktop.Linux.Maus | |||
@@ -52,7 +52,7 @@ font-1 = Lato:size=10;1 | |||
52 | font-2 = Raleway:size=10;1 | 52 | font-2 = Raleway:size=10;1 |
53 | font-3 = FuraCode Nerd Font:size=12;2 | 53 | font-3 = FuraCode Nerd Font:size=12;2 |
54 | 54 | ||
55 | modules-left = i3 mpd pulseaudio-control | 55 | modules-left = i3 pulseaudio-control mpd |
56 | modules-center = xwindow | 56 | modules-center = xwindow |
57 | modules-right = focus date time xkeyboard | 57 | modules-right = focus date time xkeyboard |
58 | 58 | ||
diff --git a/.config/polybar/pulseaudio-control.sh b/.config/polybar/pulseaudio-control.sh index e88ce39..bdabf2f 100755 --- a/.config/polybar/pulseaudio-control.sh +++ b/.config/polybar/pulseaudio-control.sh | |||
@@ -14,7 +14,7 @@ VOLUME_ICONS=( " " " " " " ) # Volume icons array, from lower volume t | |||
14 | MUTED_ICON=" " # Muted volume icon | 14 | MUTED_ICON=" " # Muted volume icon |
15 | MUTED_COLOR="%{F#A9AA83}" # Color when the audio is muted | 15 | MUTED_COLOR="%{F#A9AA83}" # Color when the audio is muted |
16 | DEFAULT_SINK_ICON="♫ " # The default sink icon if a custom one isn't found | 16 | DEFAULT_SINK_ICON="♫ " # The default sink icon if a custom one isn't found |
17 | CUSTOM_SINK_ICONS=("" "" "") # Custom sink icons in index of sink order | 17 | CUSTOM_SINK_ICONS=("" "") # Custom sink icons in index of sink order |
18 | NOTIFICATIONS="yes" # Notifications when switching sinks if enabled | 18 | NOTIFICATIONS="yes" # Notifications when switching sinks if enabled |
19 | SINK_BLACKLIST=( ) # Index blacklist for sinks when switching between them | 19 | SINK_BLACKLIST=( ) # Index blacklist for sinks when switching between them |
20 | 20 | ||
diff --git a/.config/polybar/spotify_status.py b/.config/polybar/spotify_status.py new file mode 100644 index 0000000..3a56096 --- /dev/null +++ b/.config/polybar/spotify_status.py | |||
@@ -0,0 +1,123 @@ | |||
1 | #!/bin/python | ||
2 | |||
3 | import sys | ||
4 | import dbus | ||
5 | import argparse | ||
6 | |||
7 | parser = argparse.ArgumentParser() | ||
8 | parser.add_argument( | ||
9 | '-t', | ||
10 | '--trunclen', | ||
11 | type=int, | ||
12 | metavar='trunclen' | ||
13 | ) | ||
14 | parser.add_argument( | ||
15 | '-f', | ||
16 | '--format', | ||
17 | type=str, | ||
18 | metavar='custom format', | ||
19 | dest='custom_format' | ||
20 | ) | ||
21 | parser.add_argument( | ||
22 | '-p', | ||
23 | '--playpause', | ||
24 | type=str, | ||
25 | metavar='play-pause indicator', | ||
26 | dest='play_pause' | ||
27 | ) | ||
28 | parser.add_argument( | ||
29 | '--font', | ||
30 | type=str, | ||
31 | metavar='the index of the font to use for the main label', | ||
32 | dest='font' | ||
33 | ) | ||
34 | parser.add_argument( | ||
35 | '--playpause-font', | ||
36 | type=str, | ||
37 | metavar='the index of the font to use to display the playpause indicator', | ||
38 | dest='play_pause_font' | ||
39 | ) | ||
40 | |||
41 | |||
42 | args = parser.parse_args() | ||
43 | |||
44 | def fix_string(string): | ||
45 | # corrects encoding for the python version used | ||
46 | if sys.version_info.major == 3: | ||
47 | return string | ||
48 | else: | ||
49 | return string.encode('utf-8') | ||
50 | |||
51 | # Default parameters | ||
52 | output = fix_string(u'{play_pause} {artist}: {song}') | ||
53 | trunclen = 25 | ||
54 | play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused | ||
55 | |||
56 | label_with_font = '%{{T{font}}}{label}%{{T-}}' | ||
57 | font = args.font | ||
58 | play_pause_font = args.play_pause_font | ||
59 | |||
60 | # parameters can be overwritten by args | ||
61 | if args.trunclen is not None: | ||
62 | trunclen = args.trunclen | ||
63 | if args.custom_format is not None: | ||
64 | output = args.custom_format | ||
65 | if args.play_pause is not None: | ||
66 | play_pause = args.play_pause | ||
67 | |||
68 | try: | ||
69 | session_bus = dbus.SessionBus() | ||
70 | spotify_bus = session_bus.get_object( | ||
71 | 'org.mpris.MediaPlayer2.spotify', | ||
72 | '/org/mpris/MediaPlayer2' | ||
73 | ) | ||
74 | |||
75 | spotify_properties = dbus.Interface( | ||
76 | spotify_bus, | ||
77 | 'org.freedesktop.DBus.Properties' | ||
78 | ) | ||
79 | |||
80 | metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata') | ||
81 | status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus') | ||
82 | |||
83 | # Handle play/pause label | ||
84 | |||
85 | play_pause = play_pause.split(',') | ||
86 | |||
87 | if status == 'Playing': | ||
88 | play_pause = play_pause[0] | ||
89 | elif status == 'Paused': | ||
90 | play_pause = play_pause[1] | ||
91 | else: | ||
92 | play_pause = str() | ||
93 | |||
94 | if play_pause_font: | ||
95 | play_pause = label_with_font.format(font=play_pause_font, label=play_pause) | ||
96 | |||
97 | # Handle main label | ||
98 | |||
99 | artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else '' | ||
100 | song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else '' | ||
101 | album = fix_string(metadata['xesam:album']) if metadata['xesam:album'] else '' | ||
102 | |||
103 | if not artist and not song and not album: | ||
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 | album = label_with_font.format(font=font, label=album) | ||
116 | |||
117 | print(output.format(artist=artist, song=song, play_pause=play_pause, album=album)) | ||
118 | |||
119 | except Exception as e: | ||
120 | if isinstance(e, dbus.exceptions.DBusException): | ||
121 | print('') | ||
122 | else: | ||
123 | print(e) | ||