From 999485e6099b2c42a8fdb45aba146ad1f35e4f4c Mon Sep 17 00:00:00 2001 From: Lucien Cartier-Tilet Date: Fri, 4 Feb 2022 17:00:36 +0100 Subject: [PATCH] [Emacs] Open YouTube videos with mpv in Elfeed --- org/config/emacs.org | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/org/config/emacs.org b/org/config/emacs.org index 686dd2c..6f74f55 100644 --- a/org/config/emacs.org +++ b/org/config/emacs.org @@ -1312,12 +1312,36 @@ database is to be stored. (use-package elfeed :defer t :straight (:build t) + :config + <> :custom ((elfeed-search-filter "@6-months-ago") (elfeed-db-directory (expand-file-name ".elfeed-db" user-emacs-directory)))) #+end_src +<>I don’t want YouTube videos to be open with my web +browser when I invoke ~elfeed-show-visit~, so I’ll advise this function +so I can modify the behavior of said function. +#+name: elfeed-open-youtube-with-mpv +#+begin_src emacs-lisp +(defun my/elfeed-filter-youtube-videos (orig-fun &rest args) + "Open with mpv the video leading to PATH" + (let ((link (elfeed-entry-link elfeed-show-entry))) + (when link + (if (string-match-p ".*youtube\.com.*watch.*" link) + ;; This is a YouTube video, open it with mpv + (async-shell-command (format "mpv \"%s\"" link) (current-buffer) (current-buffer)) + (apply orig-fun args))))) + +(advice-add 'elfeed-show-visit :around #'my/elfeed-filter-youtube-videos) +#+end_src + +A future improvement to be made is to let the user chose the +resolution of the video before it is launched. I may not always have +the best internet connection, and viewing 4K videos on a 1080p display +is not something very useful. + Elfeed-goodies is a package which enhances the Elfeed experience. Aside from running its setup command as soon as possible, I also set in this code block all my keybinds for Elfeed here.