diff options
author | Yuchen Pei <id@ypei.org> | 2023-06-17 17:20:29 +1000 |
---|---|---|
committer | Yuchen Pei <id@ypei.org> | 2023-06-17 17:20:29 +1000 |
commit | 093ffa5fbf7143f4668bb0a3dc9659a5cc836e12 (patch) | |
tree | 1ed4e14b2a43b8e338f4ad6a04d969b99b9239be /emacs/.emacs.d/lisp/my/my-ytdl.el | |
parent | abc686827ae38ee715d9eed1c5c29161c74127e6 (diff) |
Moving things one level deeper
To ease gnu stow usage. Now we can do
stow -t ~ emacs
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-ytdl.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-ytdl.el | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-ytdl.el b/emacs/.emacs.d/lisp/my/my-ytdl.el new file mode 100644 index 0000000..0571682 --- /dev/null +++ b/emacs/.emacs.d/lisp/my/my-ytdl.el @@ -0,0 +1,78 @@ +;;; my-ytdl.el -- ytdl client -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Free Software Foundation. + +;; Author: Yuchen Pei <id@ypei.org> +;; Package-Requires: ((emacs "28.2")) + +;; This file is part of dotfiles. + +;; dotfiles is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotfiles is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotfiles. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; ytdl client. Works with youtube-dl, yt-dlp etc. + +;;; Code: + + +(defvar my-ytdl-program "yt-dlp") + +(defvar my-ytdl-video-args + '("--download-archive" "yt-dlp-archive" "-o" +;; "%(id)s.%(ext)s" ;; for long names + "%(playlist|.)s/%(playlist_index|)s%(playlist_index&-|)s%(title)s.%(ext)s" + ;; https://github.com/yt-dlp/yt-dlp/issues/5630 + "-f" "bv*[height<=?720]+ba/best[height<=?720]" + "--write-subs" "--sub-langs" "en" + "--write-description" + "--write-thumbnail")) + +(defvar my-ytdl-video-download-dir "~/Downloads" + "Directory for ytdl to download videos to.") + +(defvar my-ytdl-audio-args + '("-x" "--download-archive" "yt-dlp-archive" "-o" + ;; "%(id)s.%(ext)s" ;; for long names + "%(playlist|.)s/%(playlist_index|)s%(playlist_index&-|)s%(title)s.%(ext)s" + "--write-description" + "--write-thumbnail")) + +(defvar my-ytdl-audio-download-dir "~/Downloads" + "Directory for ytdl to download audios to.") + +(defun my-ytdl-internal (urls type &optional cut-segments) + (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 nil (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))))) + +;;; fixme: autoload +(defun my-ytdl-video (urls) + "Download videos with ytdl." + (interactive "sURL(s): ") + (my-ytdl-internal urls 'video)) + +(defun my-ytdl-audio (urls) + "Download audio with ytdl." + (interactive "sURL(s): ") + (my-ytdl-internal urls 'audio)) + +(provide 'my-ytdl) +;;; my-ytdl.el ends here |