This commit is contained in:
Marco Thomas
2021-03-26 00:59:52 +01:00
parent 8b4c286623
commit f22dd2fd1f
4 changed files with 187 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
opacity-rule = [
];
shadow = true;
shadow = false;
shadow-radius = 12;
shadow-opacity = 0.4;
shadow-offset-x = 4;

View File

@@ -39,4 +39,11 @@ nm-applet &
feh --bg-scale $HOME/data/nextcloud/wallpaper/wallpaper.png
#asetroot $HOME/data/nextcloud/wallpaper/animated/current/ -t 50 &
exec i3
if [ `hostname` = "aincrad" ];then
dwmblocks &
exec dwm
fi
if [ `hostname` = "nazarick" ];then
exec i3
fi

37
files/scripts/dwm_bar/song.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/sh
function scroll () {
prefix="$1"
scrolling="$2"
temp="$(echo "$scrolling"| sed "s/^\(.\{20\}\)\(.*\)$/\1[\2]/"| sed "s/\[ *\]$//"| sed "s/\[.*\]$//")"
suffix="$3"
if [ "$(echo -n $scrolling |wc -c)" -gt 20 ]; then
echo "$prefix%{T7}$temp%{T-}$suffix"
sleep 0.5
zscroll -l 20 \
--delay 0.2 \
--before-text "$prefix" \
--after-text "$suffix" \
--scroll-padding " " \
--update-check true "echo '$(get_title)'" &
wait
else
echo "$prefix $temp $suffix"
fi
} #
function get_artist () {
echo "$(playerctl -p spotify metadata --format "{{ artist }}"| sed -e "s/[[(]....*[])]*//g" | sed "s/ *$//"| sed "s/^\(.\{20\}[^ ]*\)\(.*\)$/\1[\2]/"| sed "s/\[ *\]$//"| sed "s/\[.*\]$/.../")"
} #
function get_title () {
echo "$(playerctl -p spotify metadata --format "{{title}}" | sed 's/'\''/\\'\''/g')"
} #
[ ! -z "$(playerctl -p spotify status 2>/dev/null)" ] \
&& artist=$(get_artist) \
&& title=$(get_title) \
&& ([ -z "$artist$title" ] && scroll "" "Spotify is not connected on this pc" "" || scroll "$artist - $title" ) \
|| exit 1

View File

@@ -0,0 +1,141 @@
#!/usr/bin/env 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'
)
parser.add_argument(
'-q',
'--quiet',
action='store_true',
help="if set, don't show any output when the current song is paused",
dest='quiet',
)
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')
def truncate(name, trunclen):
if len(name) > trunclen:
name = name[:trunclen]
name += '...'
if ('(' in name) and (')' not in name):
name += ')'
return name
# Default parameters
output = fix_string(u'{play_pause} {artist}: {song}')
trunclen = 60
play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused
label_with_font = '{label}'
font = args.font
play_pause_font = args.play_pause_font
quiet = args.quiet
# 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 (quiet and status == 'Paused') or (not artist and not song and not album):
print('')
else:
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)
# Add 4 to trunclen to account for status symbol, spaces, and other padding characters
print(truncate(output.format(artist=artist,
song=song,
play_pause=play_pause,
album=album), trunclen + 4))
except Exception as e:
if isinstance(e, dbus.exceptions.DBusException):
print('')
else:
print(e)