summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-10-03 07:20:49 +0300
committerThanos Apollo <[email protected]>2023-10-03 07:20:49 +0300
commite4ab8b311402ad9c64a56ef134575d8dce564316 (patch)
treecb64fa06edbe14d59e592afec6b5382d0311e136
parent16f993a69e0157ad3211e3507fe0b996056b668c (diff)
[Rewrite] yeetube: Rewrite all yeetube-download functionality
Add yeetube-download-ytdlp - Checks if yt-dlp is installed - Runs shell command with yt-dlp with url, name & audio format Rewrite yeetube-download functions to use yeetube-download-yt-dlp Rewrite yeetube-download-videos to start downloading content immediately after each loop and not wait for the user to quit the loop to start yt-dlp process.
-rw-r--r--yeetube.el84
1 files changed, 44 insertions, 40 deletions
diff --git a/yeetube.el b/yeetube.el
index 1374a7c..f96a4f3 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -191,6 +191,44 @@ then for item."
`(,title ,videoid ,view-count ,video-duration ,channel)
yeetube-content))))))))))
+(defun yeetube-version ()
+ "Show Yeetube Version."
+ (interactive)
+ (message "Yeetube Version: %s" yeetube--version))
+
+(add-variable-watcher 'yeetube-saved-videos #'yeetube-update-saved-videos-list)
+
+;; Yeetube Downlaod:
+
+(defvar yeetube-ytdlp (executable-find "yt-dlp")
+ "Path for yt-dlp executable.")
+
+(defun yeetube-download-change-directory ()
+ "Change download directory."
+ (interactive)
+ (setf yeetube-download-directory
+ (read-directory-name "Select a directory: ")))
+
+(defun yeetube-download-change-audio-format (audio-format)
+ "Change download format to AUDIO-FORMAT."
+ (interactive "sSpecify Audio Format(no for nil): ")
+ (setf yeetube-download-audio-format audio-format)
+ (when (equal yeetube-download-audio-format "no")
+ (setf yeetube-download-audio-format nil)))
+
+(defun yeetube-download-ytdlp (url name &optional audio-format)
+ "Use yt-dlp with URL as NAME, when AUDIO-FORMAT extract content as audio format.
+
+Name can be left as nil to keep the default name."
+ (interactive)
+ (unless yeetube-ytdlp
+ (error "Executable for yt-dlp not found. Please install yt-dlp"))
+ (call-process-shell-command
+ (concat yeetube-ytdlp " '" url "' -o '" name "'"
+ (when yeetube-download-audio-format
+ " --extract-audio --audio-format '" audio-format "'"))
+ nil 0))
+
;;;###autoload
(defun yeetube-download-video ()
"Download using link at point in *yeetube* buffer with yt-dlp."
@@ -198,12 +236,7 @@ then for item."
(let ((url (yeetube-get-url)))
(when (string-prefix-p "http" url)
(let ((default-directory yeetube-download-directory))
- (call-process-shell-command
- (if yeetube-download-audio-format
- (format "%s '%s' --extract-audio --audio-format %s"
- (executable-find "yt-dlp") url yeetube-download-audio-format)
- (format "%s '%s'" (executable-find "yt-dlp") url))
- nil 0)
+ (yeetube-download-ytdlp url nil yeetube-download-audio-format)
(message "Downloading %s " url)))))
;;;###autoload
@@ -217,43 +250,14 @@ then run this command interactively. You can leave the 'Custom name:'
prompt blank to keep the default name."
(interactive)
(let ((url "")
- (name "")
- (download-counter 1)
- (stored-contents nil))
- ;; Read links and names until "q" is entered
+ (name "")
+ (download-counter 1))
(while (not (string= url "q"))
(setf url (read-string "Enter URL (q to quit): "))
(unless (string= url "q")
- (setf name (read-string (format "Custom name (download counter: %d) " download-counter)))
- (push (cons url name) stored-contents)
- (setf download-counter (1+ download-counter))))
- ;; Process the collected links and names
- (dolist (pair stored-contents)
- (let ((url (car pair))
- (name (cdr pair)))
- (call-process-shell-command
- (format "%s '%s' -o %s" (executable-find "yt-dlp") url name)
- nil 0)))))
-
-(defun yeetube-change-download-directory ()
- "Change download directory."
- (interactive)
- (setf yeetube-download-directory
- (read-directory-name "Select a directory: ")))
-
-(defun yeetube-change-download-audio-format (audio-format)
- "Change download format to AUDIO-FORMAT."
- (interactive "sSpecify Audio Format(no for nil): ")
- (setf yeetube-download-audio-format audio-format)
- (when (equal yeetube-download-audio-format "no")
- (setf yeetube-download-audio-format nil)))
-
-(defun yeetube-version ()
- "Show Yeetube Version."
- (interactive)
- (message "Yeetube Version: %s" yeetube--version))
-
-(add-variable-watcher 'yeetube-saved-videos #'yeetube-update-saved-videos-list)
+ (setf name (read-string (format "Custom name (download counter: %d) " download-counter)))
+ (setf download-counter (1+ download-counter))
+ (yeetube-download-ytdlp url name yeetube-download-audio-format)))))
;; Yeetube Mode
(defvar-keymap yeetube-mode-map