summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-06-30 04:42:01 +0300
committerThanos Apollo <[email protected]>2023-06-30 04:42:01 +0300
commit4f9fbd1f032669ea94ec0f6cf25048e925558c50 (patch)
tree055d6d19ad4e7dc35fbf1f2bda204428d8e118f1
parentb4c8ed66622ce64b5bc1317cedb81f289d8072b8 (diff)
parent12343f095057f7f79fbcf586a42d39e160db31be (diff)
Merge branch '#download-videos' into dev
-rw-r--r--org-yt.el59
1 files changed, 58 insertions, 1 deletions
diff --git a/org-yt.el b/org-yt.el
index 0cdb94d..602bc9c 100644
--- a/org-yt.el
+++ b/org-yt.el
@@ -24,8 +24,20 @@
;;; Code:
+
(require 'org-element)
+
+(defcustom yt-download-audio-format nil
+ "Select download video as audio FORMAT.
+If nil yt-download-videos output will be the default format.
+
+Example Usage:
+ (setq yt-download-audio-format \"m4a\")"
+ :type 'string
+ :group 'youtube)
+
+
;; TODO: Make a defcustom for video player
(defun yt-play ()
"Open the link at point in an `'org-mode buffer with `'mpv."
@@ -37,13 +49,58 @@
(message "Opening %s with mpv" url))))
+;; TODO: play a video link using a video player from an org-mode read only buffer
+
+
+
;; TODO: Search Youtube videos play them using a video player
-;; 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."
+ (interactive)
+ (let ((url (org-element-property
+ :raw-link (org-element-context))))
+ (when (string-prefix-p "http" url)
+ (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)