Update mprix and colors
This commit is contained in:
parent
b725dccade
commit
e1aa18dbed
20 changed files with 389 additions and 85 deletions
30
bin/dominant-color.py
Executable file
30
bin/dominant-color.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
from __future__ import print_function
|
||||
import binascii
|
||||
from PIL import Image
|
||||
import numpy as np
|
||||
import scipy
|
||||
import scipy.misc
|
||||
import scipy.cluster
|
||||
import sys
|
||||
|
||||
NUM_CLUSTERS = 5
|
||||
|
||||
# print('reading image')
|
||||
im = Image.open(sys.argv[1])
|
||||
im = im.resize((150, 150)) # optional, to reduce time
|
||||
ar = np.asarray(im)
|
||||
shape = ar.shape
|
||||
ar = ar.reshape(np.product(shape[:2]), shape[2]).astype(float)
|
||||
|
||||
# print('finding clusters')
|
||||
codes, dist = scipy.cluster.vq.kmeans(ar, NUM_CLUSTERS)
|
||||
# print('cluster centres:\n', codes)
|
||||
|
||||
vecs, dist = scipy.cluster.vq.vq(ar, codes) # assign codes
|
||||
counts, bins = np.histogram(vecs, len(codes)) # count occurrences
|
||||
|
||||
index_max = np.argmax(counts) # find most frequent
|
||||
peak = codes[index_max]
|
||||
colour = binascii.hexlify(bytearray(int(c) for c in peak)).decode('ascii')
|
||||
# print('most frequent is %s (#%s)' % (peak, colour))
|
||||
print(colour)
|
|
@ -1,3 +1,18 @@
|
|||
get_artUrl() {
|
||||
artUrl=$(playerctl -p $1 metadata | grep artUrl | awk '{$1=$2=""; print $0}')
|
||||
regex='(https?|ftp)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]'
|
||||
if [[ $artUrl =~ $regex ]]
|
||||
then
|
||||
filename=/tmp/spotify-mpris/$(basename $artUrl)
|
||||
if [ ! -f $filename ]
|
||||
then
|
||||
curl -sSL $artUrl --create-dirs -o $filename
|
||||
fi
|
||||
echo $filename
|
||||
else
|
||||
echo $artUrl
|
||||
fi
|
||||
}
|
||||
|
||||
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
|
||||
declare -a PAUSED
|
||||
|
@ -8,7 +23,7 @@ for player in "${PLAYERS[@]}"; do
|
|||
|
||||
# if we have one playing, we'll use it and EXIT
|
||||
if [ "$p_status" = "Playing" ]; then
|
||||
echo $(playerctl -p $player metadata | grep artUrl | awk '{$1=$2=""; print $0}')
|
||||
get_artUrl $player
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
|
@ -17,6 +32,7 @@ done
|
|||
|
||||
# if we have a paused, show it otherwise assume there are no players or have all stopped
|
||||
if [ -n "${PAUSED[0]}" ]; then
|
||||
echo $(playerctl -p ${PAUSED[0]} metadata | grep artUrl | awk '{$1=$2=""; print $0}')
|
||||
get_artUrl ${PAUSED[0]}
|
||||
echo $(playerctl -p metadata | grep artUrl | awk '{$1=$2=""; print $0}')
|
||||
fi
|
||||
|
||||
|
|
98
bin/get_mpris_status_desc_only.sh
Executable file
98
bin/get_mpris_status_desc_only.sh
Executable file
|
@ -0,0 +1,98 @@
|
|||
#!/bin/bash
|
||||
|
||||
# The name of polybar bar which houses the main spotify module and the control modules.
|
||||
PARENT_BAR="${1:-music}"
|
||||
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
|
||||
|
||||
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
||||
|
||||
send_hook() {
|
||||
[ -z "$1" ] && echo "send_hook: missing arg" && exit 1
|
||||
polybar-msg hook mpris-play-pause "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
extract_meta() {
|
||||
grep "$1\W" <<< "$meta" | awk '{$1=$2=""; print $0}' | sed 's/^ *//; s/; */;/g' | paste -s -d/ -
|
||||
}
|
||||
|
||||
# if "icon" given, determine icon. otherwise, print metadata
|
||||
get_info() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: get_info PLAYER [icon]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
meta=$(playerctl -p "$1" metadata)
|
||||
|
||||
# get title
|
||||
title=$(extract_meta title)
|
||||
# if no title, try url e.g. vlc
|
||||
if [ -z "$title" ]; then
|
||||
title=$(extract_meta url)
|
||||
title=$(urldecode "${title##*/}")
|
||||
fi
|
||||
|
||||
# if not "icon", display information and return
|
||||
if [ "$2" != "icon" ]; then
|
||||
artist=$(extract_meta artist)
|
||||
[ -z "$artist" ] && artist=$(extract_meta albumArtist)
|
||||
|
||||
if [ -n "$artist" ]; then
|
||||
album=$(extract_meta album)
|
||||
[ -n "$album" ] && printf "from $album\n"
|
||||
|
||||
printf "by $artist"
|
||||
fi
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
# determine icon:
|
||||
# if player name is recognised, use it
|
||||
case "$1" in
|
||||
spotify* | vlc | mpv) echo "$1";;
|
||||
kdeconnect*) echo "kdeconnect";;
|
||||
chromium*)
|
||||
# if a browser, search window titles:
|
||||
|
||||
# this tries to avoid title messing up the regex
|
||||
regex_title=$(echo "$title" | tr "[:punct:]" ".")
|
||||
windowname=$(xdotool search --name --class --classname "$regex_title" getwindowname 2>/dev/null)
|
||||
case $windowname in
|
||||
"") ;; # ignore if empty
|
||||
*Netflix*) echo "netflix";;
|
||||
*YouTube*) echo "youtube";;
|
||||
*"Prime Video"*) echo "prime";;
|
||||
*"Corridor Digital"*) echo "corridor";;
|
||||
*) echo "browser";;
|
||||
esac;;
|
||||
*) echo "none";;
|
||||
esac
|
||||
}
|
||||
|
||||
# manually go through players
|
||||
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
|
||||
declare -a PAUSED
|
||||
for player in "${PLAYERS[@]}"; do
|
||||
[ "$player" = "playerctld" ] && continue;
|
||||
|
||||
p_status=$(playerctl -p "$player" status 2>/dev/null)
|
||||
|
||||
# if we have one playing, we'll use it and EXIT
|
||||
if [ "$p_status" = "Playing" ]; then
|
||||
send_hook 1
|
||||
get_info "$player" "$2"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
[ "$p_status" = "Paused" ] && PAUSED+=("$player")
|
||||
done
|
||||
|
||||
# if we have a paused, show it otherwise assume there are no players or have all stopped
|
||||
if [ -n "${PAUSED[0]}" ]; then
|
||||
send_hook 2
|
||||
get_info "${PAUSED[0]}" "$2"
|
||||
else
|
||||
[ "$2" = icon ] && echo "none" || echo " 鈴 no players "
|
||||
fi
|
89
bin/get_mpris_status_title_only.sh
Executable file
89
bin/get_mpris_status_title_only.sh
Executable file
|
@ -0,0 +1,89 @@
|
|||
#!/bin/bash
|
||||
|
||||
# The name of polybar bar which houses the main spotify module and the control modules.
|
||||
PARENT_BAR="${1:-music}"
|
||||
PARENT_BAR_PID=$(pgrep -a "polybar" | grep "$PARENT_BAR" | cut -d" " -f1)
|
||||
|
||||
urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
|
||||
|
||||
send_hook() {
|
||||
[ -z "$1" ] && echo "send_hook: missing arg" && exit 1
|
||||
polybar-msg hook mpris-play-pause "$1" 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
|
||||
extract_meta() {
|
||||
grep "$1\W" <<< "$meta" | awk '{$1=$2=""; print $0}' | sed 's/^ *//; s/; */;/g' | paste -s -d/ -
|
||||
}
|
||||
|
||||
# if "icon" given, determine icon. otherwise, print metadata
|
||||
get_info() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: get_info PLAYER [icon]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
meta=$(playerctl -p "$1" metadata)
|
||||
|
||||
# get title
|
||||
title=$(extract_meta title)
|
||||
# if no title, try url e.g. vlc
|
||||
if [ -z "$title" ]; then
|
||||
title=$(extract_meta url)
|
||||
title=$(urldecode "${title##*/}")
|
||||
fi
|
||||
|
||||
# if not "icon", display information and return
|
||||
if [ "$2" != "icon" ]; then
|
||||
printf "$title"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# determine icon:
|
||||
# if player name is recognised, use it
|
||||
case "$1" in
|
||||
spotify* | vlc | mpv) echo "$1";;
|
||||
kdeconnect*) echo "kdeconnect";;
|
||||
chromium*)
|
||||
# if a browser, search window titles:
|
||||
|
||||
# this tries to avoid title messing up the regex
|
||||
regex_title=$(echo "$title" | tr "[:punct:]" ".")
|
||||
windowname=$(xdotool search --name --class --classname "$regex_title" getwindowname 2>/dev/null)
|
||||
case $windowname in
|
||||
"") ;; # ignore if empty
|
||||
*Netflix*) echo "netflix";;
|
||||
*YouTube*) echo "youtube";;
|
||||
*"Prime Video"*) echo "prime";;
|
||||
*"Corridor Digital"*) echo "corridor";;
|
||||
*) echo "browser";;
|
||||
esac;;
|
||||
*) echo "none";;
|
||||
esac
|
||||
}
|
||||
|
||||
# manually go through players
|
||||
read -d'\n' -ra PLAYERS <<<"$(playerctl -l 2>/dev/null)"
|
||||
declare -a PAUSED
|
||||
for player in "${PLAYERS[@]}"; do
|
||||
[ "$player" = "playerctld" ] && continue;
|
||||
|
||||
p_status=$(playerctl -p "$player" status 2>/dev/null)
|
||||
|
||||
# if we have one playing, we'll use it and EXIT
|
||||
if [ "$p_status" = "Playing" ]; then
|
||||
send_hook 1
|
||||
get_info "$player" "$2"
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
[ "$p_status" = "Paused" ] && PAUSED+=("$player")
|
||||
done
|
||||
|
||||
# if we have a paused, show it otherwise assume there are no players or have all stopped
|
||||
if [ -n "${PAUSED[0]}" ]; then
|
||||
send_hook 2
|
||||
get_info "${PAUSED[0]}" "$2"
|
||||
else
|
||||
[ "$2" = icon ] && echo "none" || echo " 鈴 no players "
|
||||
fi
|
22
bin/scroll_mpris_status_title_only.sh
Executable file
22
bin/scroll_mpris_status_title_only.sh
Executable file
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
cmd="${0%/*}/get_mpris_status_title_only.sh $1"
|
||||
|
||||
zscroll -l 50 \
|
||||
--scroll-padding "$(printf ' %.0s' {1..8})" \
|
||||
-d 0.5 \
|
||||
-M "$cmd icon" \
|
||||
-m "none" "-b ''" \
|
||||
-m "browser" "-b ' '" \
|
||||
-m "netflix" "-b 'ﱄ '" \
|
||||
-m "youtube" "-b ' '" \
|
||||
-m "prime" "-b ' '" \
|
||||
-m "spotify" "-b ' '" \
|
||||
-m "spotifyd" "-b ' '" \
|
||||
-m "vlc" "-b '嗢 '" \
|
||||
-m "mpv" "-b ' '" \
|
||||
-m "kdeconnect" "-b ' '" \
|
||||
-m "corridor" "-b ' '" \
|
||||
-U 1 -u t "$cmd" &
|
||||
|
||||
wait
|
Loading…
Add table
Add a link
Reference in a new issue