aboutsummaryrefslogtreecommitdiffstats
path: root/yeetube.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-03-03 20:54:29 +0200
committerThanos Apollo <[email protected]>2024-03-03 20:54:29 +0200
commita3c7a9174ab7521acbe42784aa34edd994d48cd2 (patch)
treeb56cd735973d734d712b6c345d6a1bb6b1d7344a /yeetube.el
parent68f9f626e3eb63c1bcdc49c958eefc0ff3536f09 (diff)
[fix] Refactor yeetube-download--ytdlp
- Used 'executable-find' to validate the presence of 'yt-dlp' and 'torsocks' binaries. - Separated the construction of each part of the command for better readability. - Utilized 'mapconcat' to assemble the final command, removing nil values and unnecessary spaces. - Factored out string literals in the command construction and reduced unnecessary string concatenation.
Diffstat (limited to 'yeetube.el')
-rw-r--r--yeetube.el35
1 files changed, 13 insertions, 22 deletions
diff --git a/yeetube.el b/yeetube.el
index 80b9798..7ffc480 100644
--- a/yeetube.el
+++ b/yeetube.el
@@ -462,28 +462,19 @@ SUBSTRING-END is the end of the string to return, interger."
Optional values:
NAME for custom file name.
AUDIO-FORMAT to extract and keep contents as specified audio-format only."
- (unless yeetube-ytdlp
- (error "Executable for yt-dlp not found. Please install yt-dlp"))
- (call-process-shell-command
- (concat (when yeetube-enable-tor "torsocks ")
- "yt-dlp " (shell-quote-argument url)
- (when name
- " -o "(shell-quote-argument name))
- (when audio-format
- " --extract-audio --audio-format " (shell-quote-argument audio-format)))
- nil 0))
-
-(defun yeetube-download--ffmpeg (url name)
- "Download URL as NAME using ffmpeg."
- (let ((ffmpeg (executable-find "ffmpeg")))
- (unless ffmpeg
- (error "Executable ffmpeg not found. Please install ffmpeg"))
- (call-process-shell-command
- (concat ffmpeg
- " -protocol_whitelist file,crypto,data,https,tls,tcp -stats -i "
- (shell-quote-argument url)
- " -codec copy "
- name))))
+ (unless (executable-find "yt-dlp")
+ (error "Executable for yt-dlp not found. Please install yt-dlp"))
+ (let* ((tor-command (when yeetube-enable-tor (executable-find "torsocks")))
+ (name-command (when name (format "-o %s" (shell-quote-argument name))))
+ (format-command (when audio-format
+ (format "--extract-audio --audio-format %s" (shell-quote-argument audio-format))))
+ (command (mapconcat 'identity (delq nil
+ (list tor-command
+ (executable-find "yt-dlp")
+ (shell-quote-argument url)
+ name-command format-command))
+ " ")))
+ (call-process-shell-command command nil 0)))
;;;###autoload
(defun yeetube-download-video ()