module-elfeed.el (3390B)
1 ;;; module-elfeed.el 2 3 ;; Author: Mark Feller <mark.feller@member.fsf.org> 4 5 ;; This file is not part of GNU Emacs. 6 7 ;; This file is free software; you can redistribute it and/or modify 8 ;; it under the terms of the GNU General Public License as published by 9 ;; the Free Software Foundation; either version 3, or (at your option) 10 ;; any later version. 11 12 ;; This file is distributed in the hope that it will be useful, 13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ;; GNU General Public License for more details. 16 17 ;; You should have received a copy of the GNU General Public License 18 ;; along with this file. If not, see <http://www.gnu.org/licenses/>. 19 20 ;;; Commentary: 21 22 ;; elfeed provides an RSS feed viewer. I added some helper functions for 23 ;; tracking youtube channels and playlists as well as a mechanism to 24 ;; watch videos with mpv. Hopefully this will allow me to follow 25 ;; channels I care about without getting sucked into the YouTube 26 ;; algorithm. 27 28 ;;; Code: 29 30 (defvar mjf/elfeed-ytdl-format 31 "bestvideo[height<=?720][fps<=?30]+bestaudio/best" 32 "Video and audio format for downloaded youtube content") 33 34 (defvar mjf/ytdl-audo-format 35 "--extract-audio --audio-quality 0 --audio-format flac" 36 "Youtube Download audio format flags") 37 38 (defun mjf/play-video-at-point () 39 "Play the link at point with mpv" 40 (interactive) 41 (shell-command (format "mpv --ytdl-format='%s' '%s' &" 42 mjf/elfeed-ytdl-format 43 (thing-at-point 'url)))) 44 45 (defun mjf/ytdl-audio (url) 46 "Download a youtube video as audio" 47 (let ((default-directory "~/Downloads")) 48 (async-shell-command (format "youtube-dl %s '%s'" 49 mjf/ytdl-audo-format 50 url)))) 51 52 (defun mjf/yt-channel-feed (channel) 53 "Create an elfeed feed for a given YouTube channel" 54 (let ((feed (format "https://www.youtube.com/feeds/videos.xml?channel_id=%s" 55 channel))) 56 `(,feed youtube))) 57 58 (defun mjf/yt-playlist-feed (playlist) 59 "Create an elfeed feed for a given YouTube playlist" 60 (let ((feed (format "https://www.youtube.com/feeds/videos.xml?playlist_id=%s" 61 playlist))) 62 `(,feed youtube))) 63 64 (defun mjf/elfeed-search-download-audio () 65 "Visit the current entry in your browser using `browse-url'. 66 If there is a prefix argument, visit the current entry in the 67 browser defined by `browse-url-generic-program'." 68 (interactive) 69 (let ((entries (elfeed-search-selected))) 70 (cl-loop for entry in entries 71 do (elfeed-untag entry 'unread) 72 when (elfeed-entry-link entry) 73 do (mjf/ytdl-audio it)) 74 (mapc #'elfeed-search-update-entry entries) 75 (unless (or elfeed-search-remain-on-entry (use-region-p)) 76 (forward-line)))) 77 78 (use-package elfeed 79 :bind 80 (:map elfeed-show-mode-map 81 ("C-c o" . mjf/play-video-at-point)) 82 (:map elfeed-search-mode-map 83 ("a" . mjf/elfeed-search-download-audio)) 84 85 :config 86 (setq elfeed-db-directory "~/.local/share/elfeed") 87 88 (add-hook 'elfeed-search-mode-hook 'disable-line-numbers) 89 (add-hook 'elfeed-search-mode-hook 'evil-emacs-state) 90 (add-hook 'elfeed-show-mode-hook 'disable-line-numbers) 91 (add-hook 'elfeed-show-mode-hook 'evil-emacs-state)) 92 93 (provide 'module-elfeed) 94 95 ;;; module-elfeed.el ends here