making a yt-dlp to empv function

This commit is contained in:
Chris Cochrun 2025-03-26 10:55:46 -05:00
parent d0ff0b78ad
commit 2f23e73011
2 changed files with 168 additions and 148 deletions

View file

@ -5066,27 +5066,37 @@ With empv we can perhaps control mpv much more fine grainly and even search yout
(let* ((item (when (not file) (empv-youtube-results--current-item))) (let* ((item (when (not file) (empv-youtube-results--current-item)))
(video-id (when (not file) (alist-get 'videoId item))) (video-id (when (not file) (alist-get 'videoId item)))
(playlist-id (when (not file) (alist-get 'playlistId item))) (playlist-id (when (not file) (alist-get 'playlistId item)))
(title (if file (shell-command (title (if file (shell-command-to-string
(format "yt-dlp --get-title %s" file)) (format "yt-dlp --no-warnings --quiet --get-title %s" file))
(alist-get 'title item))) (alist-get 'title item)))
(url (if file file (url (if file file
(format (format
"https://youtube.com/%s=%s" "https://youtube.com/%s=%s"
(if video-id "watch?v" "playlist?list") (if video-id "watch?v" "playlist?list")
(or video-id playlist-id))))) (or video-id playlist-id))))
(output-buffer (generate-new-buffer "*yt-dlp*"))
(process (progn
(message "Starting to download %s at %s" title url)
(make-process
:name "yt-dlp"
:buffer output-buffer
:command `("yt-dlp" "-o"
"~/vids/%(title)s.%(ext)s"
;; "-f best[ext=mp4]"
,(cl-coerce url 'string)
"--embed-thumbnail"
"--sponsorblock-remove=sponsor,intro,outro"))
(get-buffer-process output-buffer)))
(enqueue `(lambda (process event)
(message "running %s because %s" process event)
(empv-enqueue (concat "/home/chris/vids/" (string-trim ,title) ".mp4")))))
(message url) (message url)
(async-start-process (if (process-live-p process)
"yt-dlp" "yt-dlp" (set-process-sentinel
(lambda () process enqueue)
(let ((file (format "/home/chris/vids/%s.%s" title "webm"))) (message "No process running"))))
(empv-play-or-enqueue file))
(message "here be the url %s" url))
"-o" "'/home/chris/vids/%(title)s.%(ext)s'" url)))
(get-process "yt-dlp") (defun chris/empv-yt-dlp-jellyfin ()
(chris/empv-yt-dlp "https://inv.cochrun.xyz/watch?v=qRE6kf30u4g")
(defun chris/empv-yt-dlp-jellyfin ()
"Grabs the current video at point and downloads it to my jellyfin server" "Grabs the current video at point and downloads it to my jellyfin server"
(interactive) (interactive)
(let* ((server "jelly.cochrun.xyz") (let* ((server "jelly.cochrun.xyz")
@ -5107,7 +5117,7 @@ With empv we can perhaps control mpv much more fine grainly and even search yout
" '" url "'" "\"")) " '" url "'" "\""))
(message (format "%s is downloading to the %s folder on jellyfin" url location)))) (message (format "%s is downloading to the %s folder on jellyfin" url location))))
(defun chris/empv-org-play-link (&optional link) (defun chris/empv-org-play-link (&optional link)
"Play link in empv from either supplied link or link at point in org-mode" "Play link in empv from either supplied link or link at point in org-mode"
(interactive) (interactive)
(let ((link (if link (let ((link (if link
@ -5115,19 +5125,19 @@ With empv we can perhaps control mpv much more fine grainly and even search yout
(org-babel-read-link)))) (org-babel-read-link))))
(empv-play link))) (empv-play link)))
(defun chris/dired-empv-play-or-enqueue () (defun chris/dired-empv-play-or-enqueue ()
"Play file at point in dired" "Play file at point in dired"
(interactive) (interactive)
(let* ((file (dired-get-filename))) (let* ((file (dired-get-filename)))
(empv-play-or-enqueue file))) (empv-play-or-enqueue file)))
(defun chris/empv-seek-forward () (defun chris/empv-seek-forward ()
"Seek forward 20 seconds" "Seek forward 20 seconds"
(interactive) (interactive)
(empv-seek "20")) (empv-seek "20"))
:general :general
(chris/leader-keys (chris/leader-keys
:states 'normal :states 'normal
:keymaps 'override :keymaps 'override
"vo" 'empv-play-or-enqueue "vo" 'empv-play-or-enqueue
@ -5139,7 +5149,7 @@ With empv we can perhaps control mpv much more fine grainly and even search yout
"vp" 'empv-playlist-prev "vp" 'empv-playlist-prev
"vs" 'empv-playlist-select "vs" 'empv-playlist-select
"vS" 'chris/empv-seek-forward) "vS" 'chris/empv-seek-forward)
(general-def (general-def
:states 'normal :states 'normal
:keymaps 'empv-youtube-results-mode-map :keymaps 'empv-youtube-results-mode-map
"q" 'kill-current-buffer "q" 'kill-current-buffer
@ -5147,7 +5157,7 @@ With empv we can perhaps control mpv much more fine grainly and even search yout
"i" 'empv-youtube-results-inspect "i" 'empv-youtube-results-inspect
"d" 'chris/empv-yt-dlp "d" 'chris/empv-yt-dlp
"D" 'chris/empv-yt-dlp-jellyfin) "D" 'chris/empv-yt-dlp-jellyfin)
(general-def (general-def
:states 'normal :states 'normal
:keymaps 'dired-mode-map :keymaps 'dired-mode-map
"vi" 'chris/dired-empv-play-or-enqueue)) "vi" 'chris/dired-empv-play-or-enqueue))

52
init.el
View file

@ -3712,27 +3712,37 @@ targets."
(let* ((item (when (not file) (empv-youtube-results--current-item))) (let* ((item (when (not file) (empv-youtube-results--current-item)))
(video-id (when (not file) (alist-get 'videoId item))) (video-id (when (not file) (alist-get 'videoId item)))
(playlist-id (when (not file) (alist-get 'playlistId item))) (playlist-id (when (not file) (alist-get 'playlistId item)))
(title (if file (shell-command (title (if file (shell-command-to-string
(format "yt-dlp --get-title %s" file)) (format "yt-dlp --no-warnings --quiet --get-title %s" file))
(alist-get 'title item))) (alist-get 'title item)))
(url (if file file (url (if file file
(format (format
"https://youtube.com/%s=%s" "https://youtube.com/%s=%s"
(if video-id "watch?v" "playlist?list") (if video-id "watch?v" "playlist?list")
(or video-id playlist-id))))) (or video-id playlist-id))))
(output-buffer (generate-new-buffer "*yt-dlp*"))
(process (progn
(message "Starting to download %s at %s" title url)
(make-process
:name "yt-dlp"
:buffer output-buffer
:command `("yt-dlp" "-o"
"~/vids/%(title)s.%(ext)s"
;; "-f best[ext=mp4]"
,(cl-coerce url 'string)
"--embed-thumbnail"
"--sponsorblock-remove=sponsor,intro,outro"))
(get-buffer-process output-buffer)))
(enqueue `(lambda (process event)
(message "running %s because %s" process event)
(empv-enqueue (concat "/home/chris/vids/" (string-trim ,title) ".mp4")))))
(message url) (message url)
(async-start-process (if (process-live-p process)
"yt-dlp" "yt-dlp" (set-process-sentinel
(lambda () process enqueue)
(let ((file (format "/home/chris/vids/%s.%s" title "webm"))) (message "No process running"))))
(empv-play-or-enqueue file))
(message "here be the url %s" url))
"-o" "'/home/chris/vids/%(title)s.%(ext)s'" url)))
(get-process "yt-dlp") (defun chris/empv-yt-dlp-jellyfin ()
(chris/empv-yt-dlp "https://inv.cochrun.xyz/watch?v=qRE6kf30u4g")
(defun chris/empv-yt-dlp-jellyfin ()
"Grabs the current video at point and downloads it to my jellyfin server" "Grabs the current video at point and downloads it to my jellyfin server"
(interactive) (interactive)
(let* ((server "jelly.cochrun.xyz") (let* ((server "jelly.cochrun.xyz")
@ -3753,7 +3763,7 @@ targets."
" '" url "'" "\"")) " '" url "'" "\""))
(message (format "%s is downloading to the %s folder on jellyfin" url location)))) (message (format "%s is downloading to the %s folder on jellyfin" url location))))
(defun chris/empv-org-play-link (&optional link) (defun chris/empv-org-play-link (&optional link)
"Play link in empv from either supplied link or link at point in org-mode" "Play link in empv from either supplied link or link at point in org-mode"
(interactive) (interactive)
(let ((link (if link (let ((link (if link
@ -3761,19 +3771,19 @@ targets."
(org-babel-read-link)))) (org-babel-read-link))))
(empv-play link))) (empv-play link)))
(defun chris/dired-empv-play-or-enqueue () (defun chris/dired-empv-play-or-enqueue ()
"Play file at point in dired" "Play file at point in dired"
(interactive) (interactive)
(let* ((file (dired-get-filename))) (let* ((file (dired-get-filename)))
(empv-play-or-enqueue file))) (empv-play-or-enqueue file)))
(defun chris/empv-seek-forward () (defun chris/empv-seek-forward ()
"Seek forward 20 seconds" "Seek forward 20 seconds"
(interactive) (interactive)
(empv-seek "20")) (empv-seek "20"))
:general :general
(chris/leader-keys (chris/leader-keys
:states 'normal :states 'normal
:keymaps 'override :keymaps 'override
"vo" 'empv-play-or-enqueue "vo" 'empv-play-or-enqueue
@ -3785,7 +3795,7 @@ targets."
"vp" 'empv-playlist-prev "vp" 'empv-playlist-prev
"vs" 'empv-playlist-select "vs" 'empv-playlist-select
"vS" 'chris/empv-seek-forward) "vS" 'chris/empv-seek-forward)
(general-def (general-def
:states 'normal :states 'normal
:keymaps 'empv-youtube-results-mode-map :keymaps 'empv-youtube-results-mode-map
"q" 'kill-current-buffer "q" 'kill-current-buffer
@ -3793,7 +3803,7 @@ targets."
"i" 'empv-youtube-results-inspect "i" 'empv-youtube-results-inspect
"d" 'chris/empv-yt-dlp "d" 'chris/empv-yt-dlp
"D" 'chris/empv-yt-dlp-jellyfin) "D" 'chris/empv-yt-dlp-jellyfin)
(general-def (general-def
:states 'normal :states 'normal
:keymaps 'dired-mode-map :keymaps 'dired-mode-map
"vi" 'chris/dired-empv-play-or-enqueue)) "vi" 'chris/dired-empv-play-or-enqueue))