From e5da380d2cc776907e466cee0aeb7be11539ff2b Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 31 Jul 2021 23:55:51 +0800 Subject: 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. --- eshell-conf.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'eshell-conf.el') diff --git a/eshell-conf.el b/eshell-conf.el index 6dbc49a..7386400 100644 --- a/eshell-conf.el +++ b/eshell-conf.el @@ -132,6 +132,33 @@ Add a time information at the beginning. -- Modified by Durand." (define-key eshell-mode-map (vector #xf) ; C-o #'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) -- cgit v1.2.3-18-g5258