Skip to content

Instantly share code, notes, and snippets.

@FrancisMurillo
Created January 10, 2017 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrancisMurillo/dadaca70121cb71aaa85762b0d03723d to your computer and use it in GitHub Desktop.
Save FrancisMurillo/dadaca70121cb71aaa85762b0d03723d to your computer and use it in GitHub Desktop.
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