Copy youtube link converted to invidious to the system clipboard


I got this idea just now that it would be cool to be able to copy the current youtube link converted to invidious to the system clipboard.

I’d like to do this in one go.

Visit youtubepage

Press keybinding to get the invidious link for it copied to my clipboard.

Does the existing invidious plugin allow that? I haven’t tried or installed it yet.


That should be pretty easy. You can re-use the nx-freestance (I’m guessing that you mean this by “invidious plugin”?) internals to get the most relevant instance, and then construct a link to copy to clipboard. The code for that would be

(define-command-global copy-youtube-url-as-invidious-url ()
  "Copy the current buffer URL (implied to have YouTube video open) as an Invidious URL."
  (if (search "" (quri:uri-host (url (current-buffer))))
      (let* ((url (url (current-buffer)))
             (priority-instance (or nx-freestance-handler:*preferred-invidious-instance*
                                    (first (mapcar #'nx-freestance-handler::invidious-instance-name
             (invidious-url (quri:copy-uri url :host priority-instance)))
        ;; Implies you're on bleeding edge master. If not, use
        ;; `nyxt/document-mode::%copy' instead.
        (ffi-buffer-copy (current-buffer) (quri:render-uri invidious-url)))
      (echo-warning "You're not on YouTube, I can't copy this URL :(")))