From e4a0853b306c054e5554f866d731020a7a6f5206 Mon Sep 17 00:00:00 2001 From: BardofSprites <89086143+BardofSprites@users.noreply.github.com> Date: Sat, 27 Dec 2025 15:57:53 -0500 Subject: MAJOR formatting and documentation --- bard-elisp/bard-media.el | 53 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'bard-elisp/bard-media.el') diff --git a/bard-elisp/bard-media.el b/bard-elisp/bard-media.el index b5d1707..b7ebacd 100644 --- a/bard-elisp/bard-media.el +++ b/bard-elisp/bard-media.el @@ -23,6 +23,32 @@ (emms-playlist-save bard/emms-playlist-format bard/watch-later-file) (message "Playlist saved to %s" bard/watch-later-file))) +(defun bard/emms-download-current-video (destination) + "Download the currently playing EMMS video and move it to DESTINATION." + (interactive "DSelect destination directory: ") + (require 'emms) + (let* ((track (emms-playlist-current-selected-track)) + (url (emms-track-get track 'name)) + (default-directory (file-name-as-directory temporary-file-directory)) + (downloader (executable-find "yt-dlp")) + (output-template "%(title)s.%(ext)s")) + (unless downloader + (error "yt-dlp or youtube-dl is not installed or not in PATH")) + (unless (string-match-p "^https?://" url) + (error "Current track is not a valid video URL")) + + (let ((cmd (format "%s -o \"%s\" \"%s\"" + downloader output-template url))) + (message "Downloading video from: %s" url) + (let ((exit-code (shell-command cmd))) + (if (not (eq exit-code 0)) + (error "Download failed, see *Messages* for details") + ;; Move the downloaded file + (let* ((downloaded-file (car (directory-files default-directory t ".*\\(mp4\\|mkv\\|webm\\)$" 'time))) + (target-path (expand-file-name (file-name-nondirectory downloaded-file) destination))) + (rename-file downloaded-file target-path t) + (message "Video saved to: %s" target-path))))))) + (defun bard/image-browser-choose (directory) "Open nsxiv in thumbnail mode on DIRECTORY. Asks the user whether to enable recursive mode and whether to output marked files to a buffer." @@ -31,7 +57,6 @@ Asks the user whether to enable recursive mode and whether to output marked file (stdout (if (y-or-n-p "Output marked files to buffer? ") "-o" "")) (full-dir (expand-file-name directory)) (args (remove "" (list "nsxiv" "-t" stdout recursive full-dir)))) - ;; Pre-clear the output buffer if needed (when (string= stdout "-o") (with-current-buffer (get-buffer-create "*nsxiv*") @@ -91,30 +116,4 @@ Assumes that files have already been validated." (message "Not in Dired. Prompting for directory...") (call-interactively #'bard/image-browser-choose)))) -(defun bard/emms-download-current-video (destination) - "Download the currently playing EMMS video and move it to DESTINATION." - (interactive "DSelect destination directory: ") - (require 'emms) - (let* ((track (emms-playlist-current-selected-track)) - (url (emms-track-get track 'name)) - (default-directory (file-name-as-directory temporary-file-directory)) - (downloader (executable-find "yt-dlp")) - (output-template "%(title)s.%(ext)s")) - (unless downloader - (error "yt-dlp or youtube-dl is not installed or not in PATH")) - (unless (string-match-p "^https?://" url) - (error "Current track is not a valid video URL")) - - (let ((cmd (format "%s -o \"%s\" \"%s\"" - downloader output-template url))) - (message "Downloading video from: %s" url) - (let ((exit-code (shell-command cmd))) - (if (not (eq exit-code 0)) - (error "Download failed, see *Messages* for details") - ;; Move the downloaded file - (let* ((downloaded-file (car (directory-files default-directory t ".*\\(mp4\\|mkv\\|webm\\)$" 'time))) - (target-path (expand-file-name (file-name-nondirectory downloaded-file) destination))) - (rename-file downloaded-file target-path t) - (message "Video saved to: %s" target-path))))))) - (provide 'bard-media.el) -- cgit v1.2.3