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,91 +5066,101 @@ 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") "Grabs the current video at point and downloads it to my jellyfin server"
(interactive)
(let* ((server "jelly.cochrun.xyz")
(item (empv-youtube-results--current-item))
(video-id (alist-get 'videoId item))
(playlist-id (alist-get 'playlistId item))
(title (alist-get 'title item))
(location (completing-read "location: " '("dev" "house" "ministry" "misc")))
(url (format
"https://youtube.com/%s=%s"
(if video-id "watch?v" "playlist?list")
(or video-id playlist-id))))
(async-shell-command (concat
"ssh " server " \"" "yt-dlp"
" -o '/storage/media/media/chris/extras/yt/"
location
"/%(title)s.%(ext)s'"
" '" url "'" "\""))
(message (format "%s is downloading to the %s folder on jellyfin" url location))))
(defun chris/empv-yt-dlp-jellyfin () (defun chris/empv-org-play-link (&optional link)
"Grabs the current video at point and downloads it to my jellyfin server" "Play link in empv from either supplied link or link at point in org-mode"
(interactive) (interactive)
(let* ((server "jelly.cochrun.xyz") (let ((link (if link
(item (empv-youtube-results--current-item)) link
(video-id (alist-get 'videoId item)) (org-babel-read-link))))
(playlist-id (alist-get 'playlistId item)) (empv-play link)))
(title (alist-get 'title item))
(location (completing-read "location: " '("dev" "house" "ministry" "misc")))
(url (format
"https://youtube.com/%s=%s"
(if video-id "watch?v" "playlist?list")
(or video-id playlist-id))))
(async-shell-command (concat
"ssh " server " \"" "yt-dlp"
" -o '/storage/media/media/chris/extras/yt/"
location
"/%(title)s.%(ext)s'"
" '" url "'" "\""))
(message (format "%s is downloading to the %s folder on jellyfin" url location))))
(defun chris/empv-org-play-link (&optional link) (defun chris/dired-empv-play-or-enqueue ()
"Play link in empv from either supplied link or link at point in org-mode" "Play file at point in dired"
(interactive) (interactive)
(let ((link (if link (let* ((file (dired-get-filename)))
link (empv-play-or-enqueue file)))
(org-babel-read-link))))
(empv-play link)))
(defun chris/dired-empv-play-or-enqueue () (defun chris/empv-seek-forward ()
"Play file at point in dired" "Seek forward 20 seconds"
(interactive) (interactive)
(let* ((file (dired-get-filename))) (empv-seek "20"))
(empv-play-or-enqueue file)))
(defun chris/empv-seek-forward () :general
"Seek forward 20 seconds" (chris/leader-keys
(interactive) :states 'normal
(empv-seek "20")) :keymaps 'override
"vo" 'empv-play-or-enqueue
:general "vt" 'empv-toggle
(chris/leader-keys "vv" 'empv-play-video
:states 'normal "vx" 'empv-chapter-select
:keymaps 'override "vy" 'empv-youtube-tabulated
"vo" 'empv-play-or-enqueue "vn" 'empv-playlist-next
"vt" 'empv-toggle "vp" 'empv-playlist-prev
"vv" 'empv-play-video "vs" 'empv-playlist-select
"vx" 'empv-chapter-select "vS" 'chris/empv-seek-forward)
"vy" 'empv-youtube-tabulated (general-def
"vn" 'empv-playlist-next :states 'normal
"vp" 'empv-playlist-prev :keymaps 'empv-youtube-results-mode-map
"vs" 'empv-playlist-select "q" 'kill-current-buffer
"vS" 'chris/empv-seek-forward) "RET" 'empv-youtube-results-play-or-enqueue-current
(general-def "i" 'empv-youtube-results-inspect
:states 'normal "d" 'chris/empv-yt-dlp
:keymaps 'empv-youtube-results-mode-map "D" 'chris/empv-yt-dlp-jellyfin)
"q" 'kill-current-buffer (general-def
"RET" 'empv-youtube-results-play-or-enqueue-current :states 'normal
"i" 'empv-youtube-results-inspect :keymaps 'dired-mode-map
"d" 'chris/empv-yt-dlp "vi" 'chris/dired-empv-play-or-enqueue))
"D" 'chris/empv-yt-dlp-jellyfin)
(general-def
:states 'normal
:keymaps 'dired-mode-map
"vi" 'chris/dired-empv-play-or-enqueue))
#+end_src #+end_src
I need to update the new normal mode pieces to this... I need to update the new normal mode pieces to this...

158
init.el
View file

@ -3712,91 +3712,101 @@ 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") "Grabs the current video at point and downloads it to my jellyfin server"
(interactive)
(let* ((server "jelly.cochrun.xyz")
(item (empv-youtube-results--current-item))
(video-id (alist-get 'videoId item))
(playlist-id (alist-get 'playlistId item))
(title (alist-get 'title item))
(location (completing-read "location: " '("dev" "house" "ministry" "misc")))
(url (format
"https://youtube.com/%s=%s"
(if video-id "watch?v" "playlist?list")
(or video-id playlist-id))))
(async-shell-command (concat
"ssh " server " \"" "yt-dlp"
" -o '/storage/media/media/chris/extras/yt/"
location
"/%(title)s.%(ext)s'"
" '" url "'" "\""))
(message (format "%s is downloading to the %s folder on jellyfin" url location))))
(defun chris/empv-yt-dlp-jellyfin () (defun chris/empv-org-play-link (&optional link)
"Grabs the current video at point and downloads it to my jellyfin server" "Play link in empv from either supplied link or link at point in org-mode"
(interactive) (interactive)
(let* ((server "jelly.cochrun.xyz") (let ((link (if link
(item (empv-youtube-results--current-item)) link
(video-id (alist-get 'videoId item)) (org-babel-read-link))))
(playlist-id (alist-get 'playlistId item)) (empv-play link)))
(title (alist-get 'title item))
(location (completing-read "location: " '("dev" "house" "ministry" "misc")))
(url (format
"https://youtube.com/%s=%s"
(if video-id "watch?v" "playlist?list")
(or video-id playlist-id))))
(async-shell-command (concat
"ssh " server " \"" "yt-dlp"
" -o '/storage/media/media/chris/extras/yt/"
location
"/%(title)s.%(ext)s'"
" '" url "'" "\""))
(message (format "%s is downloading to the %s folder on jellyfin" url location))))
(defun chris/empv-org-play-link (&optional link) (defun chris/dired-empv-play-or-enqueue ()
"Play link in empv from either supplied link or link at point in org-mode" "Play file at point in dired"
(interactive) (interactive)
(let ((link (if link (let* ((file (dired-get-filename)))
link (empv-play-or-enqueue file)))
(org-babel-read-link))))
(empv-play link)))
(defun chris/dired-empv-play-or-enqueue () (defun chris/empv-seek-forward ()
"Play file at point in dired" "Seek forward 20 seconds"
(interactive) (interactive)
(let* ((file (dired-get-filename))) (empv-seek "20"))
(empv-play-or-enqueue file)))
(defun chris/empv-seek-forward () :general
"Seek forward 20 seconds" (chris/leader-keys
(interactive) :states 'normal
(empv-seek "20")) :keymaps 'override
"vo" 'empv-play-or-enqueue
:general "vt" 'empv-toggle
(chris/leader-keys "vv" 'empv-play-video
:states 'normal "vx" 'empv-chapter-select
:keymaps 'override "vy" 'empv-youtube-tabulated
"vo" 'empv-play-or-enqueue "vn" 'empv-playlist-next
"vt" 'empv-toggle "vp" 'empv-playlist-prev
"vv" 'empv-play-video "vs" 'empv-playlist-select
"vx" 'empv-chapter-select "vS" 'chris/empv-seek-forward)
"vy" 'empv-youtube-tabulated (general-def
"vn" 'empv-playlist-next :states 'normal
"vp" 'empv-playlist-prev :keymaps 'empv-youtube-results-mode-map
"vs" 'empv-playlist-select "q" 'kill-current-buffer
"vS" 'chris/empv-seek-forward) "RET" 'empv-youtube-results-play-or-enqueue-current
(general-def "i" 'empv-youtube-results-inspect
:states 'normal "d" 'chris/empv-yt-dlp
:keymaps 'empv-youtube-results-mode-map "D" 'chris/empv-yt-dlp-jellyfin)
"q" 'kill-current-buffer (general-def
"RET" 'empv-youtube-results-play-or-enqueue-current :states 'normal
"i" 'empv-youtube-results-inspect :keymaps 'dired-mode-map
"d" 'chris/empv-yt-dlp "vi" 'chris/dired-empv-play-or-enqueue))
"D" 'chris/empv-yt-dlp-jellyfin)
(general-def
:states 'normal
:keymaps 'dired-mode-map
"vi" 'chris/dired-empv-play-or-enqueue))
(use-package elfeed (use-package elfeed
:commands (elfeed) :commands (elfeed)