前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用 Emacs 收听 elfeed 中的播客

使用 Emacs 收听 elfeed 中的播客

作者头像
飞驰的西瓜
发布2023-11-15 19:05:48
1720
发布2023-11-15 19:05:48
举报
文章被收录于专栏:EmacsTalkEmacsTalk

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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2023-11-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 EmacsTalk 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 参考资料
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档