From a3c7a9174ab7521acbe42784aa34edd994d48cd2 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Sun, 3 Mar 2024 20:54:29 +0200 Subject: [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. --- yeetube.el | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'yeetube.el') 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 () -- cgit v1.2.3