summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-07-31 23:55:51 +0800
committerJSDurand <mmemmew@gmail.com>2021-07-31 23:55:51 +0800
commite5da380d2cc776907e466cee0aeb7be11539ff2b (patch)
tree083889500745d4335e6fb328ced74fc2b9ed2d92
parent2dd587b640f65d3932f295514644e7bd990e04ca (diff)
new: yt-url in eshell
* eshell-conf.el (eshell/yt-url): The function that eshell calls. (eshell-yt-url): The function that actually does the job. It converts the name of the video to its corresponding YouTube URL, and either saves it to the kill-ring or opens it in the default external browser.
-rw-r--r--eshell-conf.el27
1 files changed, 27 insertions, 0 deletions
diff --git a/eshell-conf.el b/eshell-conf.el
index 6dbc49a..7386400 100644
--- a/eshell-conf.el
+++ b/eshell-conf.el
@@ -133,6 +133,33 @@ Add a time information at the beginning. -- Modified by Durand."
#'eshell-clear))
;;;###autoload
+(defun eshell/yt-url (&rest args)
+ "Run `durand-convert-youtube-video-to-url' on the first arg."
+ (eshell-eval-using-options
+ "yt-url" args
+ '((?o "open" nil open-p "Open in the default external browser.")
+ (?h "help" nil nil "Print this help message.")
+ :parse-leading-options-only
+ :usage "[-ho] video-name"
+ :show-usage)
+ (eshell-yt-url args open-p)))
+
+;;;###autoload
+(defun eshell-yt-url (&optional video-name open-p)
+ "Save the URL of a video downloaded from YouTube to the kill-ring.
+The video is given by VIDEO-NAME.
+
+If OPEN-P is non-nil, then open the video in the default external
+browser instead."
+ (let ((url (durand-convert-youtube-video-to-url
+ (eshell-flatten-and-stringify video-name))))
+ (cond
+ ((string= url "")
+ (user-error "Please specify VIDEO-NAME"))
+ (open-p (browse-url-default-browser url))
+ ((kill-new url)))))
+
+;;;###autoload
(defun eshell-clear ()
(interactive)
(let ((inhibit-read-only t))