commit 2164139
hovercats
·
2026-08-31 10:03:36 +0000 UTC
parent 8016c66
create a function that covers the printfs to the socket
1 files changed,
+9,
-10
M
ampv
M
ampv
+9,
-10
1@@ -7,8 +7,8 @@ tmpfile=`{mktemp}
2
3 fn player {mpv '--input-ipc-server='$socket $*}
4 fn njetcat {nc -UN $socket}
5-fn getfilepath {
6- printf '{ "command": ["get_property", "path"] }\n' | \
7+fn tosocket {printf '{ "command": '$*' }\n'}
8+fn getfilepath {tosocket '[ "get_property", "path" ]' | \
9 njetcat | awk -F '"' '{print $4}'
10 }
11
12@@ -24,23 +24,22 @@ switch($1) {
13 songfile=`{getfilepath}
14 rm -rf $"songfile
15 case -i
16- printf '{ "command": ["get_property", "filtered-metadata"] }\n' | \
17- njetcat | \
18+ tosocket '[ "get_property", "filtered-metadata" ]' | njetcat | \
19 sed -e 's/{"data":{//' \
20 -e 's/"},"request_id":0,"error":"success"}//' \
21 -e 's/_/ /g' -e 's/":/: /g' -e 's/,"/\n/g' -e 's/"//g'
22 case -n
23- printf 'playlist-next\n' | njetcat
24+ tosocket '[ "playlist-next" ]' | njetcat
25 case -p
26- printf 'cycle pause\n' | njetcat
27+ tosocket '[ "cycle pause" ]' | njetcat
28 case -P
29- printf 'playlist-prev\n' | njetcat
30+ tosocket '[ "playlist-prev" ]' | njetcat
31 case -s
32- printf 'playlist-shuffle\n' | njetcat
33+ tosocket '[ "playlist-shuffle" ]' | njetcat
34 case -S
35 player --idle &
36 case -g
37- printf 'quit\n' | njetcat
38+ tosocket '[ "quit" ]' | njetcat
39 shift
40 if (~ $#* 0) {
41 find $musicdir -type f -name *.opus > /tmp/.music
42@@ -49,7 +48,7 @@ switch($1) {
43 if not music=$*
44 player --no-audio-display $music
45 case -u
46- printf 'playlist-unshuffle\n' | njetcat
47+ tosocket '[ "playlist-unshuffle" ]' | njetcat
48 case *
49 printf 'Usage: ampv -a|-d|-D|-i|-n|-p|-P|-s|-S|-g|-u\n'
50 exit 1