Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
2017-01-11 - w3m with vlc
(defcustom fn/w3m-video-executable "vlc"
"The executable that can run a network video stream.")
(defcustom fn/w3m-video-args
(list
;; This skews how the process is managed for vlc
;; "--one-instance"
;; "--play-and-exit"
)
"Extra arguments to run `fn/w3m-video-executable'")
(defun fn/w3m-video (&optional url)
"Get image video url."
(or url (w3m-anchor) w3m-current-url))
(defun fn/w3m-view-video ()
"View the video url with `fn/w3m-video-executable'"
(interactive)
(let ((url (w3m-url-valid (fn/w3m-video))))
(if (null url)
(prog1
(w3m-message "No video at point")
nil)
(lexical-let ((video-process
(apply #'start-process
(append
(list
(format "%s-%s" "w3m" fn/w3m-video-executable)
nil
fn/w3m-video-executable)
fn/w3m-video-args
(list url)))))
(with-current-buffer (current-buffer)
(fn/w3m-kill-page-process)
(setq-local fn/w3m-page-process video-process))))))
(defun fn/w3m-kill-page-process ()
"Kill the `fn/w3m-page-process' of the current buffer."
(interactive)
(with-current-buffer (current-buffer)
(when (and (boundp 'fn/w3m-page-process)
(process-live-p fn/w3m-page-process))
(kill-process fn/w3m-page-process))
(setq-local fn/w3m-page-process nil)))
(defun fn/w3m-auto-kill-page-process (url)
"If the page has a process, quit it."
(fn/w3m-kill-page-process))
(add-hook 'w3m-display-hook #'fn/w3m-auto-kill-page-process t)
(add-hook 'kill-buffer-hook #'fn/w3m-kill-page-process t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment