summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-06-30 04:22:58 +0300
committerThanos Apollo <[email protected]>2023-06-30 04:22:58 +0300
commit05dae71762fae2d63d3f6db352d07b8563990e19 (patch)
tree3fbe26d8f7093063ada34906c68446d0acfe2c68
parent3760bb37ee29784814ab314901b5d293cad53a14 (diff)
Add func to download multiple videos by manually
yt-download-videos should be used from within a Dired buffer in the desired path. yt-dlp is not youtube specific, just like this package. User should be able to manually run yt-dlp anywhere, downloading videos without being restricted to a predefined search query
-rw-r--r--org-yt.el36
1 files changed, 34 insertions, 2 deletions
diff --git a/org-yt.el b/org-yt.el
index f6f5488..6db46a0 100644
--- a/org-yt.el
+++ b/org-yt.el
@@ -32,8 +32,6 @@
-;; TODO: Download videos using yt-dlp
-
;; TODO: let user decide custom name and path
(defun yt-download-video ()
"Download using link at point in an `'org-mode buffer with yt-dlp."
@@ -44,6 +42,40 @@
(async-shell-command (format "yt-dlp %s" url))
(message "Downloading %s " url))))
+(defun yt-download-videos ()
+ "Download one or multiple videos using yt-dlp.
+
+Usage Example:
+Open a Dired buffer and navigate where you want to download your videos,
+then run this command interactively."
+ (interactive)
+ (let ((links '())
+ (names '())
+ (url "")
+ (name "")
+ (buffer-counter 1)
+ (name-counter 1))
+ ;; Read links and names until "q" is entered
+ (while (not (string= url "q"))
+ (setq url (read-string "Enter URL (q to quit): "))
+ (unless (string= url "q")
+ (setq links (cons url links))
+ (setq name (read-string (format "Enter name (%d-NAME): " name-counter)))
+ (while (get-buffer (format "download-video-%d" buffer-counter))
+ (setq buffer-counter (1+ buffer-counter)))
+ (setq names (cons name names))
+ (setq buffer-counter (1+ buffer-counter))
+ (setq name-counter (1+ name-counter))))
+ ;; Process the collected links and names
+ (setq links (reverse links))
+ (setq names (reverse names))
+ (dolist (pair (cl-mapcar 'cons links names))
+ (let ((url (car pair))
+ (name (cdr pair))
+ (buffer-name (format "download-video-%d" buffer-counter)))
+ (async-shell-command (format "yt-dlp %s -o %s" url name) buffer-name)
+ (setq buffer-counter (1+ buffer-counter))))))
+
(provide 'org-yt)
;;; org-yt.el ends here