mirror of
https://github.com/elkowar/dots-of-war.git
synced 2024-11-05 19:02:24 +00:00
add spotify to toolbar
This commit is contained in:
parent
164dca7bd1
commit
8308801130
6 changed files with 160 additions and 15 deletions
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"optOut": false,
|
||||
"lastUpdateCheck": 1584909489032
|
||||
"lastUpdateCheck": 1585038828775
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
;==========================================================
|
||||
;
|
||||
;
|
||||
|
@ -8,14 +9,15 @@
|
|||
; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║
|
||||
; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
|
||||
;
|
||||
;
|
||||
; To learn more about how to configure Polybar
|
||||
; ; To learn more about how to configure Polybar
|
||||
; go to https://github.com/polybar/polybar
|
||||
;
|
||||
; The README contains a lot of information
|
||||
;
|
||||
;==========================================================
|
||||
|
||||
;; Colors ------------------------------------------- {{{
|
||||
|
||||
[colors]
|
||||
;background = ${xrdb:color0:#222}
|
||||
background = #bb282828
|
||||
|
@ -28,13 +30,18 @@ primary = #ffb52a
|
|||
secondary = #e60053
|
||||
alert = #bd2c40
|
||||
|
||||
;; }}}
|
||||
|
||||
;; Bar config ----------------------------------------- {{{
|
||||
|
||||
[bar/main]
|
||||
width = 100%
|
||||
height = 27
|
||||
height = 24
|
||||
radius = 0.0
|
||||
fixed-center = false
|
||||
enable-ipc = true
|
||||
padding = 0
|
||||
;; center centered modules on screen, not between other modules
|
||||
fixed-center = true
|
||||
|
||||
background = ${colors.background}
|
||||
foreground = ${colors.foreground}
|
||||
|
@ -52,13 +59,18 @@ module-margin-left = 1
|
|||
module-margin-right = 2
|
||||
|
||||
font-0 = fixed:pixelsize=10;1
|
||||
font-1 = unifont:fontformat=truetype:size=8:antialias=false;0
|
||||
font-2 = siji:pixelsize=10;1
|
||||
font-7 = NotoEmoji:size=7;
|
||||
;font-1 = unifont:fontformat=truetype:size=8:antialias=false;0
|
||||
;font-2 = siji:pixelsize=10;1
|
||||
;font-7 = NotoEmoji:size=7;
|
||||
;font-7 = "JetBrainsMono Nerd Font:size=7"
|
||||
;font-0 = "JetBrainsMono Nerd Font:fontformat=truetype:size=10;2"
|
||||
;font-0 = "Iosevka Nerd Font:size=10;1"
|
||||
;font-1 = "NotoEmoji:scale=12;1"
|
||||
font-1 = "Symbola:size=12;1"
|
||||
|
||||
|
||||
modules-left = xmonad test
|
||||
modules-center = timerDisplay mpd gitlab-pipeline player-mpv-tail
|
||||
modules-center = timerDisplay spotify mpd gitlab-pipeline player-mpv-tail
|
||||
modules-right = network-traffic info-pingrtt pulseaudio filesystem memory cpu date
|
||||
|
||||
tray-position = right
|
||||
|
@ -70,6 +82,10 @@ tray-background = ${colors.background}
|
|||
cursor-click = pointer
|
||||
cursor-scroll = ns-resize
|
||||
|
||||
;; }}}
|
||||
|
||||
;; MODULES ----------------------------------------------- {{{
|
||||
|
||||
; show's currently focussed window, already contained in xmonad module
|
||||
[module/xwindow]
|
||||
type = internal/xwindow
|
||||
|
@ -158,8 +174,6 @@ pseudo-transparency = true
|
|||
margin-top = 5
|
||||
margin-bottom = 0
|
||||
|
||||
; vim:ft=dosini
|
||||
|
||||
[module/xmonad]
|
||||
type = custom/script
|
||||
exec = xmonad-log
|
||||
|
@ -199,3 +213,15 @@ scroll-down = ~/.config/polybar/polybar-scripts/player-mpv-tail.py -p time-pos
|
|||
type = custom/script
|
||||
exec = ~/.config/polybar/polybar-scripts/network-traffic.sh
|
||||
tail = true
|
||||
|
||||
|
||||
[module/spotify]
|
||||
type = custom/script
|
||||
interval = 1
|
||||
label-font = 7
|
||||
format-font = 7
|
||||
format = <label>
|
||||
exec = python ~/.config/polybar/polybar-scripts/spotify_status.py -f '{play_pause} : {artist} - {song} [ {album} ]'
|
||||
format-underline = #1db954
|
||||
|
||||
;; }}}
|
||||
|
|
123
files/.config/polybar/polybar-scripts/spotify_status.py
Normal file
123
files/.config/polybar/polybar-scripts/spotify_status.py
Normal file
|
@ -0,0 +1,123 @@
|
|||
#!/bin/python
|
||||
|
||||
import sys
|
||||
import dbus
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-t',
|
||||
'--trunclen',
|
||||
type=int,
|
||||
metavar='trunclen'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-f',
|
||||
'--format',
|
||||
type=str,
|
||||
metavar='custom format',
|
||||
dest='custom_format'
|
||||
)
|
||||
parser.add_argument(
|
||||
'-p',
|
||||
'--playpause',
|
||||
type=str,
|
||||
metavar='play-pause indicator',
|
||||
dest='play_pause'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--font',
|
||||
type=str,
|
||||
metavar='the index of the font to use for the main label',
|
||||
dest='font'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--playpause-font',
|
||||
type=str,
|
||||
metavar='the index of the font to use to display the playpause indicator',
|
||||
dest='play_pause_font'
|
||||
)
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
def fix_string(string):
|
||||
# corrects encoding for the python version used
|
||||
if sys.version_info.major == 3:
|
||||
return string
|
||||
else:
|
||||
return string.encode('utf-8')
|
||||
|
||||
# Default parameters
|
||||
output = fix_string(u'{play_pause} {artist}: {song}')
|
||||
trunclen = 25
|
||||
play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused
|
||||
|
||||
label_with_font = '%{{T{font}}}{label}%{{T-}}'
|
||||
font = args.font
|
||||
play_pause_font = args.play_pause_font
|
||||
|
||||
# parameters can be overwritten by args
|
||||
if args.trunclen is not None:
|
||||
trunclen = args.trunclen
|
||||
if args.custom_format is not None:
|
||||
output = args.custom_format
|
||||
if args.play_pause is not None:
|
||||
play_pause = args.play_pause
|
||||
|
||||
try:
|
||||
session_bus = dbus.SessionBus()
|
||||
spotify_bus = session_bus.get_object(
|
||||
'org.mpris.MediaPlayer2.spotify',
|
||||
'/org/mpris/MediaPlayer2'
|
||||
)
|
||||
|
||||
spotify_properties = dbus.Interface(
|
||||
spotify_bus,
|
||||
'org.freedesktop.DBus.Properties'
|
||||
)
|
||||
|
||||
metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
|
||||
status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
|
||||
|
||||
# Handle play/pause label
|
||||
|
||||
play_pause = play_pause.split(',')
|
||||
|
||||
if status == 'Playing':
|
||||
play_pause = play_pause[0]
|
||||
elif status == 'Paused':
|
||||
play_pause = play_pause[1]
|
||||
else:
|
||||
play_pause = str()
|
||||
|
||||
if play_pause_font:
|
||||
play_pause = label_with_font.format(font=play_pause_font, label=play_pause)
|
||||
|
||||
# Handle main label
|
||||
|
||||
artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else ''
|
||||
song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else ''
|
||||
album = fix_string(metadata['xesam:album']) if metadata['xesam:album'] else ''
|
||||
|
||||
if not artist and not song and not album:
|
||||
print('')
|
||||
else:
|
||||
if len(song) > trunclen:
|
||||
song = song[0:trunclen]
|
||||
song += '...'
|
||||
if ('(' in song) and (')' not in song):
|
||||
song += ')'
|
||||
|
||||
if font:
|
||||
artist = label_with_font.format(font=font, label=artist)
|
||||
song = label_with_font.format(font=font, label=song)
|
||||
album = label_with_font.format(font=font, label=album)
|
||||
|
||||
print(output.format(artist=artist, song=song, play_pause=play_pause, album=album))
|
||||
|
||||
except Exception as e:
|
||||
if isinstance(e, dbus.exceptions.DBusException):
|
||||
print('')
|
||||
else:
|
||||
print(e)
|
Binary file not shown.
Binary file not shown.
|
@ -1,4 +0,0 @@
|
|||
|
||||
-- While building package my-xmonad-0.1.0.0 using:
|
||||
/home/leon/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0 build exe:my-xmonad --ghc-options ""
|
||||
Process exited with code: ExitFailure 1
|
Loading…
Reference in a new issue