From 69b94225ed37613df6fcb158ab07427b0c496ad4 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 28 Aug 2021 19:31:44 +0800 Subject: Add more feeds and a playing feature * elfeed-conf.el (elfeed-feeds): More feeds. (durand-elfeed-play-video, durand-eshell-download-play-sentinel) (durand-elfeed-download-video, elfeed-search-mode-map) (elfeed-show-mode-map): Add a function to instantaneously play the video in the feed. --- elfeed-conf.el | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 10 deletions(-) (limited to 'elfeed-conf.el') diff --git a/elfeed-conf.el b/elfeed-conf.el index 00893a2..3619a34 100644 --- a/elfeed-conf.el +++ b/elfeed-conf.el @@ -28,7 +28,9 @@ (use-package "elfeed" 'elfeed) (setq elfeed-feeds - (list (list "https://wiwi.video/feeds/videos.atom?sort=-publishedAt" + (list (list "https://blog.tanyakhovanova.com/feed/" + 'math 'khovanova 'blog) + (list "https://wiwi.video/feeds/videos.atom?sort=-publishedAt" 'wiwi) (list "https://wiwikuan.com/index.xml" 'wiwi 'blog) @@ -40,9 +42,13 @@ 'prot 'politics) (list "https://www.youtube.com/feeds/videos.xml?channel_id=UCcXhhVwCT6_WqjkEniejRJQ" 'wintergaten 'youtube) + (list "https://wintergatan.net/blogs/wintergatan.atom" + 'wintergaten 'blog) (list "https://notrelated.xyz/rss" 'lukesmith 'notrelated) (list "https://lukesmith.xyz/peertube" + 'lukesmith 'peertube) + (list "https://www.youtube.com/feeds/videos.xml?channel_id=UC2eYFnH61tmytImy1mTYvhA" 'lukesmith 'youtube) (list "https://www.youtube.com/feeds/videos.xml?channel_id=UCiWXd0nmBjlKROwzMyPV-Nw" 'zhichi 'youtube))) @@ -80,6 +86,42 @@ (kill-buffer buffer))))) (buffer-list))) +;;;###autoload +(defun durand-elfeed-play-video (process) + "Play the video file downloaded by PROCESS." + (let* ((command (process-command process)) + (link (car (last command))) + (dir "/Users/durand/Desktop/Centre/Vidéos/") + (id (process-get process 'id)) + (title (process-get process 'title)) + (ytp (string-match + (rx-to-string '(seq bos "yt:" + (one-or-more (not ":")) + ":" + (group (one-or-more anything)) + eos) + t) + id)) + (video-file + (cond + (ytp (concat title "-" (match-string 1 id))) + ("^/xxx"))) + buffer) + (cond + ((let* ((files (directory-files dir t video-file t))) + (and files (= (length files) 1) + (setq video-file (car files)))) + (setq buffer (generate-new-buffer "*mpv*")) + (start-process "elfeed-mpv" + buffer + "mpv" + video-file) + (display-buffer buffer + '(durand-display-in-one-window))) + ((message + "The file %S does not exist, and id = %s, title = %s" + video-file id title))))) + ;;;###autoload (defun durand-eshell-download-sentinel (process status) "Inform the user when the download process is terminated. @@ -92,6 +134,16 @@ This informs the user when STATUS is the string \"finished\\n\"." (cond ((string-equal status "finished\n") (message "Downloading videos has finished.")))) +;;;###autoload +(defun durand-eshell-download-play-sentinel (process status) + "A combination of `durand-eshell-download-sentinel' and \ +`durand-elfeed-play-video'." + (durand-eshell-download-sentinel process status) + (cond + ((and (string= status "finished\n") + (y-or-n-p "Play video?")) + (durand-elfeed-play-video process)))) + ;;;###autoload (defun durand-eshell-download-filter (process output) "Display OUTPUT in the buffer associated with PROCESS. @@ -110,24 +162,44 @@ will first be erased." "Download the video in the feed." (interactive) (let ((default-directory "/Users/durand/Desktop/Centre/Vidéos/") - link) + (entry (cond + ((derived-mode-p 'elfeed-show-mode) + elfeed-show-entry) + ((derived-mode-p 'elfeed-search-mode) + (elfeed-search-selected :ignore-region)))) + link proc) (cond ((derived-mode-p 'elfeed-search-mode) (setq link (elfeed-entry-link (elfeed-search-selected :ignore-region)))) ((derived-mode-p 'elfeed-show-mode) (setq link (elfeed-entry-link elfeed-show-entry))) ((user-error "Not in an elfeed buffer"))) (message "Downloading starts.") - (make-process - :name "elfeed download video" - :buffer "*elfeed download*" - :sentinel #'durand-eshell-download-sentinel - :filter #'durand-eshell-download-filter - :command (list - "youtube-dl" "-f" "bestvideo[height<=720]+bestaudio/best[height<=720]/best" - link)))) + (setq proc + (make-process + :name "elfeed download video" + :buffer "*elfeed download*" + :sentinel #'durand-eshell-download-sentinel + :filter #'durand-eshell-download-filter + :command (list + "youtube-dl" "-f" "bestvideo[height<=720]+bestaudio/best[height<=720]/best" + link))) + (process-put proc 'id (cdr (elfeed-entry-id entry))) + (process-put proc 'title (elfeed-entry-title entry)) + proc)) + +;;;###autoload +(defun durand-elfeed-download-play-video () + "Download and confirm to play the video." + (interactive) + (let ((proc (durand-elfeed-download-video))) + (set-process-sentinel proc #'durand-eshell-download-play-sentinel))) (define-key elfeed-search-mode-map (vector ?w) #'durand-elfeed-download-video) (define-key elfeed-show-mode-map (vector ?w) #'durand-elfeed-download-video) +(define-key elfeed-search-mode-map (vector ?W) #'durand-elfeed-download-play-video) +(define-key elfeed-show-mode-map (vector ?W) #'durand-elfeed-download-play-video) + + (provide 'elfeed-conf) ;;; elfeed-conf.el ends here -- cgit v1.2.3-18-g5258