Added new mediaplayer script for waybar
This commit is contained in:
parent
aa84653a5c
commit
5983c567de
10 changed files with 142 additions and 234 deletions
|
@ -2,7 +2,7 @@
|
||||||
{
|
{
|
||||||
"layer": "bottom", // Waybar at top layer
|
"layer": "bottom", // Waybar at top layer
|
||||||
"height": 22, // Waybar height
|
"height": 22, // Waybar height
|
||||||
"modules-left": ["sway/workspaces", "sway/mode", "custom/playerctl"],
|
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
|
||||||
"modules-center": ["sway/window"],
|
"modules-center": ["sway/window"],
|
||||||
"modules-right": [
|
"modules-right": [
|
||||||
"idle_inhibitor",
|
"idle_inhibitor",
|
||||||
|
@ -107,12 +107,12 @@
|
||||||
"on-scroll-up": "pamixer -ui 1 && pamixer --get-volume > $SWAYSOCK.wob",
|
"on-scroll-up": "pamixer -ui 1 && pamixer --get-volume > $SWAYSOCK.wob",
|
||||||
"on-scroll-down": "pamixer -ud 1 && pamixer --get-volume > $SWAYSOCK.wob"
|
"on-scroll-down": "pamixer -ud 1 && pamixer --get-volume > $SWAYSOCK.wob"
|
||||||
},
|
},
|
||||||
"custom/playerctl": {
|
"custom/media": {
|
||||||
"tooltip": false,
|
"tooltip": false,
|
||||||
"format": "{}",
|
"format": "{}",
|
||||||
"exec": "$HOME/Scripts/metadata.sh",
|
"return-type": "json",
|
||||||
"interval": 2,
|
"exec": "$HOME/Scripts/mediaplayer.py 2>/dev/null",
|
||||||
"max-length": 40,
|
"max-length": 50,
|
||||||
"on-click": "playerctl play-pause",
|
"on-click": "playerctl play-pause",
|
||||||
"on-click-right": "playerctl next",
|
"on-click-right": "playerctl next",
|
||||||
"on-scroll-up": "playerctl volume 0.05+",
|
"on-scroll-up": "playerctl volume 0.05+",
|
||||||
|
@ -123,7 +123,7 @@
|
||||||
"format": "{} ",
|
"format": "{} ",
|
||||||
"exec": "yay -Qu | wc -l",
|
"exec": "yay -Qu | wc -l",
|
||||||
"interval": 300,
|
"interval": 300,
|
||||||
"on-click": "alacritty -e yay"
|
"on-click": "gnome-software --mode=updates"
|
||||||
},
|
},
|
||||||
"temperature": {
|
"temperature": {
|
||||||
"format": "{temperatureC}°C "
|
"format": "{temperatureC}°C "
|
||||||
|
|
|
@ -26,7 +26,7 @@ window#waybar {
|
||||||
background: #64727D;
|
background: #64727D;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clock, #battery, #cpu, #temperature, #memory, #backlight, #network, #pulseaudio, #custom-playerctl, #custom-yay, #tray, #mode, #idle_inhibitor {
|
#clock, #battery, #cpu, #temperature, #memory, #backlight, #network, #pulseaudio, #custom-media, #custom-yay, #tray, #mode, #idle_inhibitor {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
margin: 0 5px;
|
margin: 0 5px;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ window#waybar {
|
||||||
color: #2a5c45;
|
color: #2a5c45;
|
||||||
}
|
}
|
||||||
|
|
||||||
#custom-playerctl {
|
#custom-media {
|
||||||
background: #97B084;
|
background: #97B084;
|
||||||
color: black;
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Moved to https://git.reekynet.com/ReekyMarko/fzf-pass
|
|
126
home/Scripts/mediaplayer.py
Executable file
126
home/Scripts/mediaplayer.py
Executable file
|
@ -0,0 +1,126 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
import signal
|
||||||
|
import gi
|
||||||
|
import json
|
||||||
|
gi.require_version('Playerctl', '2.0')
|
||||||
|
from gi.repository import Playerctl, GLib
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def write_output(text, player):
|
||||||
|
logger.info('Writing output')
|
||||||
|
|
||||||
|
output = {'text': text,
|
||||||
|
'class': 'custom-' + player.props.player_name,
|
||||||
|
'alt': player.props.player_name}
|
||||||
|
|
||||||
|
sys.stdout.write(json.dumps(output) + '\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def on_play(player, status, manager):
|
||||||
|
logger.info('Received new playback status')
|
||||||
|
on_metadata(player, player.props.metadata, manager)
|
||||||
|
|
||||||
|
|
||||||
|
def on_metadata(player, metadata, manager):
|
||||||
|
logger.info('Received new metadata')
|
||||||
|
track_info = ''
|
||||||
|
|
||||||
|
if player.get_artist() != '' and player.get_title() != '':
|
||||||
|
track_info = '{artist} - {title}'.format(artist=player.get_artist(),
|
||||||
|
title=player.get_title())
|
||||||
|
else:
|
||||||
|
track_info = player.get_title()
|
||||||
|
|
||||||
|
if player.props.status == 'Playing' and track_info:
|
||||||
|
track_info = ' ' + track_info
|
||||||
|
else:
|
||||||
|
track_info = ' ' + track_info
|
||||||
|
|
||||||
|
write_output(track_info, player)
|
||||||
|
|
||||||
|
|
||||||
|
def on_player_appeared(manager, player, selected_player=None):
|
||||||
|
if player is not None and (selected_player is None or player.name == selected_player):
|
||||||
|
init_player(manager, player)
|
||||||
|
else:
|
||||||
|
logger.debug("New player appeared, but it's not the selected player, skipping")
|
||||||
|
|
||||||
|
|
||||||
|
def on_player_vanished(manager, player):
|
||||||
|
logger.info('Player has vanished')
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def init_player(manager, name):
|
||||||
|
logger.debug('Initialize player: {player}'.format(player=name.name))
|
||||||
|
player = Playerctl.Player.new_from_name(name)
|
||||||
|
player.connect('playback-status', on_play, manager)
|
||||||
|
player.connect('metadata', on_metadata, manager)
|
||||||
|
manager.manage_player(player)
|
||||||
|
on_metadata(player, player.props.metadata, manager)
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(sig, frame):
|
||||||
|
logger.debug('Received signal to stop, exiting')
|
||||||
|
sys.stdout.write('\n')
|
||||||
|
sys.stdout.flush()
|
||||||
|
# loop.quit()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_arguments():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
# Increase verbosity with every occurence of -v
|
||||||
|
parser.add_argument('-v', '--verbose', action='count', default=0)
|
||||||
|
|
||||||
|
# Define for which player we're listening
|
||||||
|
parser.add_argument('--player')
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
arguments = parse_arguments()
|
||||||
|
|
||||||
|
# Initialize logging
|
||||||
|
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG,
|
||||||
|
format='%(name)s %(levelname)s %(message)s')
|
||||||
|
|
||||||
|
# Logging is set by default to WARN and higher.
|
||||||
|
# With every occurrence of -v it's lowered by one
|
||||||
|
logger.setLevel(max((3 - arguments.verbose) * 10, 0))
|
||||||
|
|
||||||
|
# Log the sent command line arguments
|
||||||
|
logger.debug('Arguments received {}'.format(vars(arguments)))
|
||||||
|
|
||||||
|
manager = Playerctl.PlayerManager()
|
||||||
|
loop = GLib.MainLoop()
|
||||||
|
|
||||||
|
manager.connect('name-appeared', lambda *args: on_player_appeared(*args, arguments.player))
|
||||||
|
manager.connect('player-vanished', on_player_vanished)
|
||||||
|
|
||||||
|
signal.signal(signal.SIGINT, signal_handler)
|
||||||
|
signal.signal(signal.SIGTERM, signal_handler)
|
||||||
|
|
||||||
|
for player in manager.props.player_names:
|
||||||
|
if arguments.player is not None and arguments.player != player.name:
|
||||||
|
logger.debug('{player} is not the filtered player, skipping it'
|
||||||
|
.format(player=player.name)
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
init_player(manager, player)
|
||||||
|
|
||||||
|
loop.run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
ARTIST=$(playerctl metadata | grep 'xesam:artist' | cut -d' ' -f5- | sed 's/^[ \t]*//')
|
|
||||||
TITLE=$(playerctl metadata title)
|
|
||||||
|
|
||||||
if [ -n "$ARTIST" ]; then
|
|
||||||
echo "$ARTIST - $TITLE"
|
|
||||||
else
|
|
||||||
echo "$TITLE"
|
|
||||||
fi
|
|
|
@ -3,13 +3,7 @@
|
||||||
MPVPIPE=/tmp/mpvqueue.playlist
|
MPVPIPE=/tmp/mpvqueue.playlist
|
||||||
|
|
||||||
notify="notify-send -i mpv -a mpv"
|
notify="notify-send -i mpv -a mpv"
|
||||||
|
url="$1"
|
||||||
# if link is a youtube playlist, clean up url
|
|
||||||
if [[ ${1} =~ /^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$ ]]; then
|
|
||||||
url="https://youtube.com/playlist?list=${1#*list=}"
|
|
||||||
else
|
|
||||||
url="$1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# See if MPV is already running
|
# See if MPV is already running
|
||||||
if [ -z "$(pidof mpv)" ]; then
|
if [ -z "$(pidof mpv)" ]; then
|
||||||
|
@ -17,6 +11,9 @@ if [ -z "$(pidof mpv)" ]; then
|
||||||
# remove fifo
|
# remove fifo
|
||||||
rm -f $MPVPIPE && mkfifo $MPVPIPE
|
rm -f $MPVPIPE && mkfifo $MPVPIPE
|
||||||
|
|
||||||
|
# pause other players
|
||||||
|
playerctl pause
|
||||||
|
|
||||||
# start mpv
|
# start mpv
|
||||||
/usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "$url" & disown
|
/usr/bin/mpv --no-terminal --input-file="${MPVPIPE}" "$url" & disown
|
||||||
|
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Get the pid of the window that is to be moved to the next sink
|
|
||||||
pid_to_move=$(swaymsg -t get_tree | jq -r '.nodes[]?.nodes[]?.nodes[]?.nodes[]?.nodes[] | select(.focused==true).pid')
|
|
||||||
|
|
||||||
# Assign all the sink indices into an array
|
|
||||||
sink_array=($(pacmd list-sinks | grep index | sed 's/index://' | sed 's/*//' | xargs))
|
|
||||||
|
|
||||||
# Get the sink inputs to prepare to be inserted into array of arrays
|
|
||||||
# The following raw string format is index sink pid\nindex sink pid
|
|
||||||
sink_inputs_raw=$(pacmd list-sink-inputs | grep -e index -e sink: -e process.id | sed 's/<[^"]*>//' | sed 's/[^0-9]*//g' | tr '\n' ' ' | xargs | sed 's/\([[:digit:]]*\) \([[:digit:]]*\) \([[:digit:]]*\) /\1 \2 \3\n/g')
|
|
||||||
|
|
||||||
# Find the corresponding pid
|
|
||||||
sink_input_selected_pid=$(echo "$sink_inputs_raw" | grep $pid_to_move)
|
|
||||||
|
|
||||||
# Parse the individual values from the info retrieved above
|
|
||||||
selected_input_index=$(echo $sink_input_selected_pid | awk '{print $1;}')
|
|
||||||
selected_input_sink=$(echo $sink_input_selected_pid | awk '{print $2;}')
|
|
||||||
selected_input_pid=$(echo $sink_input_selected_pid | awk '{print $3;}')
|
|
||||||
|
|
||||||
len=${#sink_array[@]}
|
|
||||||
|
|
||||||
for (( i=0; i<$len; i++ )); do
|
|
||||||
if [[ $selected_input_sink == "${sink_array[$i]}" ]]; then
|
|
||||||
len_idx=$((len-1))
|
|
||||||
if (( $i == $len_idx )); then
|
|
||||||
pacmd move-sink-input $selected_input_index ${sink_array[0]}
|
|
||||||
else
|
|
||||||
pacmd move-sink-input $selected_input_index ${sink_array[$((i+1))]}
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
|
@ -1,165 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
# terminal application launcher for sway, using fzf
|
|
||||||
# Based on: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher
|
|
||||||
|
|
||||||
shopt -s nullglob
|
|
||||||
if [[ "$1" == 'describe' ]]; then
|
|
||||||
shift
|
|
||||||
if [[ $2 == 'command' ]]; then
|
|
||||||
title=$1
|
|
||||||
readarray arr < <(whatis -l "$1" 2>/dev/null)
|
|
||||||
description="${arr[0]}"
|
|
||||||
description="${description%*-}"
|
|
||||||
else
|
|
||||||
title=$(sed -ne '/^Name=/{s/^Name=//;p;q}' "$1")
|
|
||||||
description=$(sed -ne '/^Comment=/{s/^Comment=//;p;q}' "$1")
|
|
||||||
fi
|
|
||||||
echo -e "\033[33m$title\033[0m"
|
|
||||||
echo "${description:-No description}"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt"
|
|
||||||
|
|
||||||
DIRS=(
|
|
||||||
/usr/share/applications
|
|
||||||
"$HOME/.local/share/applications"
|
|
||||||
/usr/local/share/applications
|
|
||||||
)
|
|
||||||
|
|
||||||
GLYPH_COMMAND=" "
|
|
||||||
GLYPH_DESKTOP=" "
|
|
||||||
|
|
||||||
touch "$HIST_FILE"
|
|
||||||
readarray HIST_LINES <"$HIST_FILE"
|
|
||||||
FZFPIPE=$(mktemp)
|
|
||||||
PIDFILE=$(mktemp)
|
|
||||||
trap 'rm "$FZFPIPE" "$PIDFILE"' EXIT INT
|
|
||||||
|
|
||||||
# Append Launcher History, removing usage count
|
|
||||||
(printf '%s' "${HIST_LINES[@]#* }" >>"$FZFPIPE") &
|
|
||||||
|
|
||||||
# Load and append Desktop entries
|
|
||||||
(
|
|
||||||
for dir in "${DIRS[@]}"; do
|
|
||||||
[[ -d "$dir" ]] || continue
|
|
||||||
awk -v pre="$GLYPH_DESKTOP" -F= '
|
|
||||||
BEGINFILE{application=0;block="";a=0}
|
|
||||||
/^\[Desktop Entry\]/{block="entry"}
|
|
||||||
/^Type=Application/{application=1}
|
|
||||||
/^\[Desktop Action/{
|
|
||||||
sub("^\\[Desktop Action ", "");
|
|
||||||
sub("\\]$", "");
|
|
||||||
block="action";
|
|
||||||
a++;
|
|
||||||
actions[a,"key"]=$0
|
|
||||||
}
|
|
||||||
/^Name=/{
|
|
||||||
if(block=="action") {
|
|
||||||
actions[a,"name"]=$2;
|
|
||||||
} else {
|
|
||||||
name=$2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ENDFILE{
|
|
||||||
if (application){
|
|
||||||
print FILENAME "\034desktop\034\033[33m" pre name "\033[0m";
|
|
||||||
if (a>0)
|
|
||||||
for (i=1; i<=a; i++)
|
|
||||||
print FILENAME "\034desktop\034\033[33m" pre name "\033[0m (" actions[i, "name"] ")\034" actions[i, "key"]
|
|
||||||
}
|
|
||||||
}' \
|
|
||||||
"$dir/"*.desktop </dev/null >>"$FZFPIPE"
|
|
||||||
# the empty stdin is needed in case no *.desktop files
|
|
||||||
done
|
|
||||||
) &
|
|
||||||
|
|
||||||
# Load and append command list
|
|
||||||
(
|
|
||||||
IFS=:
|
|
||||||
read -ra path <<<"$PATH"
|
|
||||||
for dir in "${path[@]}"; do
|
|
||||||
printf '%s\n' "$dir/"* |
|
|
||||||
awk -F / -v pre="$GLYPH_COMMAND" '{print $NF "\034command\034\033[31m" pre "\033[0m" $NF;}'
|
|
||||||
done | sort -u >>"$FZFPIPE"
|
|
||||||
) &
|
|
||||||
|
|
||||||
COMMAND_STR=$(
|
|
||||||
(
|
|
||||||
tail -n +0 -f "$FZFPIPE" &
|
|
||||||
echo $! >"$PIDFILE"
|
|
||||||
) |
|
|
||||||
fzf +s -x -d '\034' --nth ..3 --with-nth 3 \
|
|
||||||
--preview "$0 describe {1} {2}" \
|
|
||||||
--preview-window=up:3:wrap --ansi
|
|
||||||
kill -9 "$(<"$PIDFILE")" | tail -n1
|
|
||||||
) || exit 1
|
|
||||||
|
|
||||||
[ -z "$COMMAND_STR" ] && exit 1
|
|
||||||
|
|
||||||
# update history
|
|
||||||
for i in "${!HIST_LINES[@]}"; do
|
|
||||||
if [[ "${HIST_LINES[i]}" == *" $COMMAND_STR"$'\n' ]]; then
|
|
||||||
HIST_COUNT=${HIST_LINES[i]%% *}
|
|
||||||
HIST_LINES[$i]="$((HIST_COUNT + 1)) $COMMAND_STR"$'\n'
|
|
||||||
match=1
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if ! ((match)); then
|
|
||||||
HIST_LINES+=("1 $COMMAND_STR"$'\n')
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s' "${HIST_LINES[@]}" | sort -nr >"$HIST_FILE"
|
|
||||||
|
|
||||||
command='echo "nope"'
|
|
||||||
# shellcheck disable=SC2086
|
|
||||||
readarray -d $'\034' -t PARAMS <<<${COMMAND_STR}
|
|
||||||
# COMMAND_STR is "<string>\034<type>"
|
|
||||||
case ${PARAMS[1]} in
|
|
||||||
desktop)
|
|
||||||
# Define the search pattern that specifies the block to search for within the .desktop file
|
|
||||||
PATTERN="^\\\\[Desktop Entry\\\\]"
|
|
||||||
if [[ -n ${PARAMS[3]} ]]; then
|
|
||||||
PATTERN="^\\\\[Desktop Action ${PARAMS[3]%?}\\\\]"
|
|
||||||
fi
|
|
||||||
# 1. We see a line starting [Desktop, but we're already searching: deactivate search again
|
|
||||||
# 2. We see the specified pattern: start search
|
|
||||||
# 3. We see an Exec= line during search: remove field codes and set variable
|
|
||||||
# 3. We see a Path= line during search: set variable
|
|
||||||
# 4. Finally, build command line
|
|
||||||
command=$(awk -v pattern="${PATTERN}" -F= '
|
|
||||||
BEGIN{a=0;exec=0; path=0}
|
|
||||||
/^\[Desktop/{
|
|
||||||
if(a){
|
|
||||||
a=0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$0 ~ pattern{
|
|
||||||
a=1
|
|
||||||
}
|
|
||||||
/^Exec=/{
|
|
||||||
if(a && !exec){
|
|
||||||
sub("^Exec=", "");
|
|
||||||
gsub(" ?%[cDdFfikmNnUuv]", "");
|
|
||||||
exec=$0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/^Path=/{
|
|
||||||
if(a && !path){
|
|
||||||
path=$2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
END{
|
|
||||||
if(path){
|
|
||||||
print "cd " path " &&"
|
|
||||||
}
|
|
||||||
print exec
|
|
||||||
}' "${PARAMS[0]}")
|
|
||||||
;;
|
|
||||||
command)
|
|
||||||
command="${PARAMS[0]}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
swaymsg -t command exec "$command"
|
|
|
@ -1,13 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
swaylock="$HOME/Scripts/swaylock.sh"
|
swaylock="$HOME/Scripts/swaylock.sh"
|
||||||
dimscreen="$HOME/Scripts/dim-screen.sh"
|
|
||||||
screenon="swaymsg 'output * dpms on'"
|
screenon="swaymsg 'output * dpms on'"
|
||||||
screenoff="swaymsg 'output * dpms off'"
|
screenoff="swaymsg 'output * dpms off'"
|
||||||
swayidle \
|
swayidle \
|
||||||
lock "$swaylock" \
|
lock "$swaylock" \
|
||||||
|
unlock "pkill -9 swaylock" \
|
||||||
timeout 300 "lqsd -d" \
|
timeout 300 "lqsd -d" \
|
||||||
resume "lqsd -r" \
|
resume "lqsd -r" \
|
||||||
timeout 600 "loginctl lock-session $(loginctl show-user $USER -p Sessions | cut -d'=' -f2); sleep 0.5; $screenoff" \
|
timeout 600 "loginctl lock-session" \
|
||||||
|
timeout 610 "$screenoff" \
|
||||||
resume "$screenon; lqsd -r" \
|
resume "$screenon; lqsd -r" \
|
||||||
before-sleep "playerctl pause; loginctl lock-session $(loginctl show-user $USER -p Sessions | cut -d'=' -f2)" \
|
before-sleep "playerctl pause; loginctl lock-session)"
|
||||||
unlock "pkill -9 swaylock"
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
curLayout=$(setxkbmap -query | grep layout | sed 's/layout: //g')
|
|
||||||
|
|
||||||
if [ $curLayout == "eu" ]; then
|
|
||||||
setxkbmap dvorak
|
|
||||||
else
|
|
||||||
setxkbmap eu
|
|
||||||
fi
|
|
Loading…
Reference in a new issue