aboutsummaryrefslogtreecommitdiff
path: root/bard-elisp/bard-media.el
diff options
context:
space:
mode:
authorBardofSprites <[email protected]>2025-04-22 18:03:56 -0400
committerBardofSprites <[email protected]>2025-04-22 18:05:37 -0400
commit480dfe2c09070cf4c710e6806cb3a6cbdc93f7cf (patch)
tree50d28c5456737b20f047dcc1c50ba76a4ab23d54 /bard-elisp/bard-media.el
parentf9a7af16c077b89a3db907746d8e1f946b064b02 (diff)
update YouTube/EMMS functions
New Features: - Download currently playing video to prompted locations. - Tacking on current elfeed entry to bard/watch-later-file - Play YouTube video at point
Diffstat (limited to 'bard-elisp/bard-media.el')
-rw-r--r--bard-elisp/bard-media.el36
1 files changed, 33 insertions, 3 deletions
diff --git a/bard-elisp/bard-media.el b/bard-elisp/bard-media.el
index 22d54c9..9efa88d 100644
--- a/bard-elisp/bard-media.el
+++ b/bard-elisp/bard-media.el
@@ -5,10 +5,14 @@
(require 'dired-x)
(defun bard/play-youtube-video ()
- "Prompt for a YouTube URL and play it in mpv."
+ "Play the YouTube URL at point or prompt for one if none is found."
(interactive)
- (let ((url (read-string "Enter YouTube URL: ")))
- (if (and url (string-match-p "https?://\\(www\\.\\)?youtube\\.com\\|youtu\\.be" url))
+ (let* ((url-at-point (thing-at-point 'url t))
+ (url (if (and url-at-point
+ (string-match-p "https?://\\(www\\.\\)?\\(youtube\\.com\\|youtu\\.be\\)" url-at-point))
+ url-at-point
+ (read-string "Enter YouTube URL: "))))
+ (if (and url (string-match-p "https?://\\(www\\.\\)?\\(youtube\\.com\\|youtu\\.be\\)" url))
(async-shell-command (format "mpv '%s'" url))
(message "The URL is not a valid YouTube link: %s" url))))
@@ -66,4 +70,30 @@ Asks the user whether to enable recursive mode."
(erase-buffer)))))
(pop-to-buffer "*nsxiv*")))))
+(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 -f best -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)