-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathytmp.gum
More file actions
102 lines (99 loc) · 7.9 KB
/
ytmp.gum
File metadata and controls
102 lines (99 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
# ARGS: -s: a wrapper for ytmpsuite and ytmp daemon; multiple things can be chosen at once
# (have a look at the fzf binds below)
# -c: don't exit wrapper after selections
# -a: display art with status line
# -o: show status and queue and quit
# -O: show just status and quit
# No arg - show a non-interactive mpv/ytmp status line and entries around queue
# gray val means its inactive
# status line: [-d] [-vl] [-p] [name] [-dur] [ytmpsuite t1] [ytmpsuite t2] [-r]
mpvsocket='/tmp/mpvsocketytmp'
conf="/home/$USER/Music/ytmp/conf"
. $conf
# one can display ascii/ansi art to the left of the interface
# a good collection can be found in 'https://github.com/poetaman/arttime/tree/main/share/arttime/textart'
# note: sometimes wrapping is messed up if using art or song names are lengthy
# in which case pipe add `| head -#` to $name and $acp
# artfile="$( fd . <ASCII/ANSI-ART-PATH> | shuf -n1 )"
if [ "$1" = '-s' ]; then
while true; do
pgrep -f 'ytmp -d' >/dev/null 2>&1 && daemon="Daemon" || daemon=$( gum style --faint "Daemon" )
pgrep -f 'ytmp -r' >/dev/null 2>&1 && rand="Random" || rand=$( gum style --faint "Random" )
[ "$( echo '{ "command": ["get_property_string", "loop" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 )" = 'inf' ] && loop='Loop' || loop=$( gum style --faint "Loop" )
echo '{ "command": ["get_property_string", "pid" ] }' | socat - "$mpvsocket" >/dev/null 2>&1 && vol="PVOL $( echo '{ "command": ["get_property_string", "volume" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 | cut -d '.' -f1 )" || vol="$( gum style --faint PVOL )"
[ $( echo '{ "command": ["get_property_string", "pause" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 ) = 'no' ] && toggle_play='Playing' || toggle_play=$( gum style --faint "Playing" )
echo '{ "command": ["get_property_string", "pid" ] }' | socat - "$mpvsocket" >/dev/null 2>&1 && quit='Quit' || quit=$( gum style --faint "Quit" )
start_vol="VOL $( sed -E -n 's/^vol=(.*)/\1/p' "$run_on_next" )"
[ "$( ytmpsuite gt2 | head -1 )" = 'ON' ] && gt2='Loop On Start' || gt2=$( gum style --faint "Loop On Start" )
[ "$( ytmpsuite gt1 | head -1 )" = 'ON' ] && gt1="$start_vol On Start" || gt1=$( gum style --faint "$start_vol On Start" )
queue="QUEUE $( sed -E -n 's/^queue="(.*)"/\1/p' "$conf" )"
# printf '%s\n' 'Reload' "$toggle_play" "$vol" "$loop" "$quit" "$daemon" "$rand" "$gt1" "$gt2" "$start_vol" "$queue" | gum filter --no-limit --prompt='' --placeholder='' | cat -v | while read s; do
printf '%s\n' "$toggle_play" "$vol" "$loop" "$quit" "$daemon" "$rand" "$gt1" "$gt2" "$start_vol" "$queue" 'Reload' | \
fzf --disabled -m --no-bold --ansi --prompt='' --info=hidden --pointer='•' --marker='◉ ' --color=gutter:black,hl+:bold:bright-red,hl:bright-red,label:italic:white,marker:cyan,pointer:cyan,bg+:black,label:white,info:white:dim,label:white:dim,spinner:white:dim --separator='' --layout=reverse --height 60% --cycle \
--bind='1:pos(1)+toggle,2:pos(2)+toggle,3:pos(3)+toggle,4:pos(4)+toggle,5:pos(5)+toggle,6:pos(6)+toggle,7:pos(7)+toggle,8:pos(8)+toggle,9:pos(9)+toggle,0:pos(10)+toggle,!:pos(1)+accept,@:pos(2)+accept,#:pos(3)+accept,$:pos(4)+accept,%:pos(5)+accept,^:pos(6)+accept,&:pos(7)+accept,*:pos(8)+accept,(:pos(9)+accept,):pos(10)+accept,home:first,end:last,ctrl-j:jump,tab:toggle+down,btab:deselect-all,alt-r:pos(-1)+accept,ctrl-x:print-query' \
| cat -v | while read s; do
echo "$s" | grep -q 'VOL.*On Start' && ytmpsuite t1 >/dev/null 2>&1 && continue
case "$s" in
Reload) break ;;
'^[[2mDaemon^[[0m') setsid -f ytmp -d >/dev/null 2>&1 ;;
'^[[2mRandom^[[0m') setsid -f ytmp -r >/dev/null 2>&1 ;;
'^[[2mPlaying^[[0m') ytmp -p >/dev/null 2>&1 ;;
'^[[2mQuit^[[0m') ytmp -qa >/dev/null 2>&1 ;;
'Quit') ytmp -qa >/dev/null 2>&1 ;;
'Playing') ytmp -p >/dev/null 2>&1 ;;
Daemon) pgrep -f 'ytmp -d' >/dev/null 2>&1 && ytmp -kd >/dev/null 2>&1 || setsid -f ytmp -d >/dev/null 2>&1; sleep .2 ;;
Random) pgrep -f 'ytmp -r' >/dev/null 2>&1 && ytmp -kr >/dev/null 2>&1 || setsid -f ytmp -r >/dev/null 2>&1; sleep .2 ;;
'Loop On Start') ytmpsuite t2 >/dev/null 2>&1 ;;
'^[[2mLoop On Start^[[0m') ytmpsuite t2 >/dev/null 2>&1 ;;
'^[[2mLoop^[[0m') ytmp -l >/dev/null 2>&1 ;;
Loop) ytmp -l >/dev/null 2>&1 ;;
# PVOL*) printf '\r'; ytmp -vl "$( gum input --placeholder='Set playback volume to what?' )" >/dev/null 2>&1 ;;
PVOL*) printf '\r'; ytmp -vl "$( fzf --bind='enter:print-query' --prompt='Set playback volume to what? ' --info=hidden )" >/dev/null 2>&1 ;;
# QUEUE*) printf '\r'; ytmpsuite sq "$( gum input --placeholder='Set starting volume to what?' )" ;;
QUEUE*) printf '\r'; ytmpsuite sq "$( fd -t f . "$prefix" | fzf )" ;;
# VOL*) printf '\r'; ytmpsuite sv "$( fd -t f . "$prefix" | gum filter )" >/dev/null 2>&1 ;;
VOL*) printf '\r'; ytmpsuite sv "$( fzf --bind='enter:print-query' --prompt='Set playback volume to what? ' --info=hidden )" >/dev/null 2>&1 ;;
*) printf '\r'; cmd="$s"; if ( printf "$cmd" | grep -Eq '^( |x.*|s.*|z|l s|v|vv|E|sp.*)+$' ); then setsid -f $TERMINAL -e ytmp $cmd >/dev/null 2>&1; else ytmp $cmd; fi ;;
esac
done
[ "$2" != '-c' ] && break
done
else
while true; do
! echo '{ "command": ["get_property_string", "pid" ] }' | socat - "$mpvsocket" >/dev/null 2>&1 && sleep 1 && continue
[ "$1" != '-O' ] && clear
pgrep -f 'ytmp -d' >/dev/null 2>&1 && daemon="D" || daemon=$( gum style --faint "D" )
pgrep -f 'ytmp -r' >/dev/null 2>&1 && rand="R" || rand=$( gum style --faint "R" )
[ "$( echo '{ "command": ["get_property_string", "loop" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 )" = 'inf' ] && loop='L' || loop=$( gum style --faint "L" )
vol="V$( echo '{ "command": ["get_property_string", "volume" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 | cut -d '.' -f1 )"
name="$( echo '{ "command": ["get_property_string", "media-title" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 | sed -E 's/(^.{11} )(.*)(\.webm)/\2/' )"
[ "$( ytmpsuite gt2 | head -1 )" = 'ON' ] && gt2='L' || gt2=$( gum style --faint "L" )
queue=$( sed -E -n 's/^queue="(.*)"/\1/p' "$conf" )
start_vol=$( sed -E -n 's/^vol=(.*)/\1/p' "$run_on_next" )
[ "$( ytmpsuite gt1 | head -1 )" = 'ON' ] && gt1="V$start_vol" || gt1=$( gum style --faint "V$start_vol" )
duration="$( echo '{ "command": ["get_property_string", "duration" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 | cut -d'.' -f1 )"
position="$( echo '{ "command": ["get_property_string", "time-pos" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 | cut -d'.' -f1 )"
[ "$duration" -lt 3600 ] && dur=$( printf "%02d:%02d / %02d:%02d\n" $((position%3600/60)) $((position%60)) $((duration%3600/60)) $((duration%60)) ) || dur=$( printf "%d:%02d:%02d / %d:%02d:%02d\n" $((position/3600)) $((position%3600/60)) $((position%60)) $((duration/3600)) $((duration%3600/60)) $((duration%60)) )
dur=$( gum style --foreground 249 "$dur" )
vol=$( gum style --foreground 249 "$vol" )
[ $( echo '{ "command": ["get_property_string", "pause" ] }' | socat - "$mpvsocket" | cut -d'"' -f4 ) = 'no' ] && play=$( gum style --foreground 249 ">" ) || play=$( gum style --foreground 249 "P" )
all=$( gum join --horizontal --align=center "$daemon $loop $vol $play $name $dur $gt1 $gt2 $rand" )
acp="$( grep -C 1 -F '***' $queue | cut -d' ' -f2- )"
if [ "$1" = '-a' ]; then
joined="$( gum style --padding '5 5' "$( gum join --align center --vertical "$( gum style --border double "$queue" )" "$acp" "$( gum style --border rounded "$all" )" )" )"
# delete the first line which contains a placeholder sentence if
# using art from 'https://github.com/poetaman/arttime/tree/main/share/arttime/textart'
gum join --horizontal "$( sed 1d $artfile )" "$joined"
# or don't
# gum join --horizontal "$( cat $artfile )" "$joined"
elif [ "$1" = '-O' ]; then
gum style --border rounded "$all"
break
else
gum style --padding '5 5' "$( gum join --align center --vertical "$( gum style --border double "$queue" )" "$acp" "$( gum style --border rounded "$all" )" )"
[ "$1" = '-o' ] && break
fi
sleep 1
done
fi