Elfeed[1] 是 Emacs 中一个非常好用的 RSS 客户端,之前笔者也写过相关文章[2]进行介绍,强烈建议读者尝试一下跨平台的 RSS 客户端。
对于播客,主要的分发形式就是基于 RSS,所以用 elfeed 来听是在自然不过的事情,只需要一个支持命令行启动的音乐播放器即可,常见的有:vlc[3]、mpv[4],而且它们都支持直接播放网络流,这样我们就省去了下载音频文件的步骤。
GitHub 上的 elcast[5] 已经解决这个问题,但是过于定制,因此笔者 fork 过来修改了一版,修改后的代码在:
代码语言:javascript复制;;; elcast.el --- Play podcast within elfeed. -*- lexical-binding: t; -*-
(require 'elfeed-show)
(defgroup elcast nil
"Tool for playing podcasts from `elfeed' enclosures."
:group 'tools)
(defcustom elcast-player-executable (or (executable-find "vlc")
(executable-find "mpv"))
"Music player used for playing podcast."
:type 'string
:group 'elcast)
(defcustom elcast-player-params '()
"Music player params"
:type '(repeat string)
:group 'elcast)
(defcustom elcast-buffer-name "*elcast-%s*"
"Name of buffer for mpv process."
:type 'string)
(defun elcast--get-url (show-entry)
"Get the enclosure url associated with SHOW-ENTRY."
(let ((enclosure (elfeed-entry-enclosures show-entry)))
(car (elt enclosure 0))))
(defun elcast--launch-for-feed (feed)
(let* ((exe elcast-player-executable)
(url (elcast--get-url feed))
(title (elfeed-entry-title feed))
(buf-name (format elcast-buffer-name title)))
(if-let (buf (get-buffer buf-name))
(when (yes-or-no-p "Already playing this, stop and play again?")
(apply 'start-process buf-name buf exe
`(,@elcast-player-params ,url)))
(apply 'start-process buf-name buf-name exe
`(,@elcast-player-params ,url)))))
;;;###autoload
(defun elcast-play ()
"Play the `elfeed' podcast entry enclosure."
(interactive)
(if-let ((entry elfeed-show-entry))
(elcast--launch-for-feed entry)
(user-error "No show entry")))
(provide 'elcast)
- https://github.com/jiacai2050/blog-snippets/blob/main/elcast.el
由于笔者一直使用的是 vlc,而且它支持 socks 代理(mpv 只支持 http 代理[6]),因此这里给出使用 vlc 时的相关配置:
代码语言:javascript复制 (use-package elcast
:load-path "/path/to/elcast"
:init
(setq elcast-player-params '("--socks" "127.0.0.1:1080" "--verbose" "2" "--no-color")))
以后,在 *elfeed-entry*
中浏览某个播客时,可以直接使用 M-x elcast-play
进行播放了!
参考资料
[1]
Elfeed: https://github.com/skeeto/elfeed
[2]
相关文章: https://liujiacai.net/blog/2021/03/05/emacs-love-mail-feed/
[3]
vlc: https://www.videolan.org/
[4]
mpv: https://mpv.io/
[5]
elcast: https://github.com/douglasdavis/elcast
[6]
只支持 http 代理: https://github.com/mpv-player/mpv/issues/3373