diff --git a/.emacs.d/init.el b/.emacs.d/init.el index adc94e72..c9c7f50d 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -419,7 +419,13 @@ (with-eval-after-load 'ytdl (setq ytdl-always-query-default-filename 'yes) (setq ytdl-max-mini-buffer-download-type-entries 0) - (setq ytdl-download-extra-args '("-f" "best"))) + (setq ytdl-download-extra-args '("-f" "best")) + (require 'patch-ytdl) + (defun ytdl-no-proxy () + (interactive) + (let ((ytdl-download-extra-args (cons "--proxy=" + ytdl-download-extra-args))) + (ytdl-download)))) (with-eval-after-load 'ztree (set-face-foreground 'ztreep-diff-model-add-face "deep sky blue")) diff --git a/.emacs.d/lisp/patch-ytdl.el b/.emacs.d/lisp/patch-ytdl.el new file mode 100644 index 00000000..e9b2dbdb --- /dev/null +++ b/.emacs.d/lisp/patch-ytdl.el @@ -0,0 +1,28 @@ +(defun ytdl--get-default-filename (url) + "Get default filename from web server. + +Query the default-filename of URL using '--get-filename' argument +of ytdl." + (if (equal ytdl-always-query-default-filename + 'never) + nil + (with-temp-buffer + (apply #'call-process ytdl-command nil t nil + (append ytdl-download-extra-args + (list + "--get-filename" + "--restrict-filenames" + "--" url))) + (goto-char (point-min)) + (if (search-forward-regexp "^ERROR" nil t) + (progn + (beginning-of-line) + (error (buffer-substring-no-properties (line-beginning-position) + (line-end-position)))) + (search-forward ".") + (replace-regexp-in-string "/\\|_" + "-" + (buffer-substring-no-properties (line-beginning-position) + (1- (point)))))))) + +(provide 'patch-ytdl)