aboutsummaryrefslogtreecommitdiff
path: root/emacs/.emacs.d/lisp/my/my-ytdl.el
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-ytdl.el')
-rw-r--r--emacs/.emacs.d/lisp/my/my-ytdl.el44
1 files changed, 34 insertions, 10 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-ytdl.el b/emacs/.emacs.d/lisp/my/my-ytdl.el
index b3b1cf7..7cdda43 100644
--- a/emacs/.emacs.d/lisp/my/my-ytdl.el
+++ b/emacs/.emacs.d/lisp/my/my-ytdl.el
@@ -26,6 +26,7 @@
;;; Code:
+(require 'tor)
(defvar my-ytdl-program "yt-dlp")
@@ -60,21 +61,34 @@
;; "%(id)s.%(ext)s" ;; for long names
"%(playlist|.)s/%(playlist_index|)s%(playlist_index&-|)s%(title)s.%(ext)s"
"--write-description"
+ "--write-info-json"
"--write-thumbnail"))
(defvar my-ytdl-audio-download-dir "~/Downloads"
"Directory for ytdl to download audios to.")
+(defvar my-ytdl-music-download-dir "~/Downloads"
+ "Directory for ytdl to download music to.")
+
(defun my-ytdl-internal (urls type &optional no-tor)
- (my-with-default-directory (if (eq type 'video)
- my-ytdl-video-download-dir
- my-ytdl-audio-download-dir)
- (apply 'my-start-process-with-torsocks
- (append
- (list no-tor (format "ytdl-%s" urls) (format "*ytdl-%s*" urls)
- my-ytdl-program)
- (if (eq type 'video) my-ytdl-video-args my-ytdl-audio-args)
- (split-string urls)))))
+ (my-with-default-directory (pcase type
+ ('video my-ytdl-video-download-dir)
+ ('audio my-ytdl-audio-download-dir)
+ ('music my-ytdl-music-download-dir)
+ (_ (error "Unsupported type: %s" type)))
+ (set-process-sentinel
+ (apply 'my-start-process-with-torsocks
+ (append
+ (list no-tor (format "ytdl-%s" urls) (format "*ytdl-%s*" urls)
+ my-ytdl-program)
+ (if (eq type 'video) my-ytdl-video-args my-ytdl-audio-args)
+ (split-string urls)))
+ (lambda (proc event)
+ (let ((status (process-exit-status proc)))
+ (if (eq status 0)
+ (progn
+ (message "ytdl-%s %s: DONE" type urls))
+ (message "ytdl-%s %s FAILED: %s" type urls event)))))))
(defun my-ytdl-video-info (url)
"Given a video URL, return an alist of its properties."
@@ -91,7 +105,7 @@
(defun my-ytdl-video-url-p (url)
(let ((urlobj (url-generic-parse-url url)))
(or (and (string-match-p
- "^\\(www\\.\\)?\\(youtube\\.com\\|yewtu\\.be\\)"
+ "^\\(www\\.\\|m\\.\\)?\\(youtube\\.com\\|yewtu\\.be\\)"
(url-host urlobj))
(string-match-p "^/watch\\?v=.*" (url-filename urlobj)))
(equal "youtu.be" (url-host urlobj)))))
@@ -148,11 +162,21 @@
(interactive "sURL(s): ")
(my-ytdl-internal urls 'audio))
+(defun my-ytdl-music (urls)
+ "Download music with ytdl."
+ (interactive "sURL(s): ")
+ (my-ytdl-internal urls 'music))
+
(defun my-ytdl-audio-no-tor (urls)
"Download audio with ytdl."
(interactive "sURL(s): ")
(my-ytdl-internal urls 'audio t))
+(defun my-ytdl-music-no-tor (urls)
+ "Download music with ytdl."
+ (interactive "sURL(s): ")
+ (my-ytdl-internal urls 'music t))
+
;;; fixme: autoload
(defun my-ytdl-video-no-tor (urls)
"Download videos with ytdl."