(or emacs irrelevant)

My org-protocol setup, part 2.

This continues the code from the part 1.

I tried to make the first call to youtube-dl asynchronous, but it wasn't working out. So for the current code, there's still about a 2 second delay before the capture buffer appears.

(require 'async)
(defun org-handle-link-youtube (link)
      ((file-name (org-trim
                     "youtube-dl \""
                     " -o \"%(title)s.%(ext)s\" --get-filename"))))
       (dir "~/Downloads/Videos")
        (expand-file-name file-name dir)))
    (add-hook 'org-link-hook
              (lambda ()
                 (org-make-link-string dir dir)
                 (org-make-link-string full-name file-name))))
     (format "youtube-dl \"%s\" -o \"%s\"" link full-name))
    (find-file (org-expand "ent.org"))
    (goto-char (point-min))
    (re-search-forward "^\\*+ +Videos" nil t)))

Some notes for people who want to learn more Elisp:

  • lexical-let* is needed to have dir and full-name visible in the lambda.
  • org-make-link-string is a nice utility command that escapes all sorts of characters that org-mode doesn't like, e.g. brackets etc.

You can see my full org-capture and org-protocol setup here.