aboutsummaryrefslogtreecommitdiffstats
path: root/yeetube.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-08-18 10:03:23 +0300
committerThanos Apollo <[email protected]>2023-08-18 10:03:23 +0300
commitbb8cd69540c81094061fe558061f08b6d9877a9d (patch)
tree8540a2de8b54d351822adfeef2316e2620b316c9 /yeetube.el
parentaa8685ba161b0ec19970e8474e71272ffe794a6f (diff)
Add yeetube-send-command-to-socket
No need for socat anymore
Diffstat (limited to 'yeetube.el')
-rw-r--r--yeetube.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/yeetube.el b/yeetube.el
index f8565bb..6639efe 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -226,6 +226,20 @@ It's recommended you keep it as the default value."
(concat mpv no-video socket)))
(message (format "Yeetube Player: %s" yeetube-player))))
+(defun yeetube-send-command-to-socket (socket-file json-data)
+ "Send command with JSON-DATA to SOCKET-FILE."
+ (let* ((proc-name "mpv-socket")
+ (proc-buffer (generate-new-buffer proc-name))
+ (proc (make-network-process :name proc-name
+ :family 'local
+ :buffer proc-buffer
+ :service socket-file)))
+ (let ((json-string (concat json-data "\n")))
+ (process-send-string proc json-string))
+ (accept-process-output proc)
+ (sit-for 0.1) ; wait for the process to finish
+ (with-current-buffer proc-buffer
+ (buffer-string))))
(defun yeetube-toggle-pause-mpv ()
"Toggle play/pause mpv."
(interactive)