From 5fe7d70d08118381c21f68122f509d43281a8e5c Mon Sep 17 00:00:00 2001
From: Case Duckworth
Date: Mon, 17 Jan 2022 01:10:01 -0600
Subject: Add ytdious

---
 init.el          | 20 +++++++++++++++-----
 lisp/+ytdious.el | 21 +++++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)
 create mode 100644 lisp/+ytdious.el

diff --git a/init.el b/init.el
index 560da6f..a938db0 100644
--- a/init.el
+++ b/init.el
@@ -153,7 +153,9 @@
                                            #'browse-url-default-browser)
    browse-url-new-window-flag nil
    browse-url-firefox-arguments '("--new-tab")
-   browse-url-firefox-new-window-is-tab t)
+   browse-url-firefox-new-window-is-tab t
+   ;; TODO: Add variables for other transformations and what-not.
+   +invidious-host "invidious.snopyta.org")
   ;; Set up external browsing URLs.
   (add-to-list '+custom-variable-allowlist
                '+browse-url-secondary-browser-regexps)
@@ -180,7 +182,7 @@
                    (t #'eww-browse-url))
              args)))
     (cons (rx (or ;; videos
-               "youtube.com" "youtu.be" "yewtu.be" "invidious"
+               "youtube.com" "youtu.be" (eval +invidious-host) "invidious"
                (seq "." (or "mp4" "gif" "mov" "MOV" "webm") eos)
                ;; music
                "soundcloud.com" "bandcamp.com"
@@ -195,9 +197,9 @@
     (cons "."                           ; everything else
           +browse-url-browser-function)))
   ;; Transform URLs before passing to `browse-url'
-  (:option +browse-url-transformations `((,(rx "//" (or "youtube.com"
-                                                        "youtu.be"))
-                                          . "//yewtu.be")
+  (:option +browse-url-transformations `((,(rx (or "youtube.com"
+                                                   "youtu.be"))
+                                          . ,+invidious-host)
                                          ("twitter\\.com"
                                           . "nitter.net")
                                          ("instagram\\.com"
@@ -1633,3 +1635,11 @@ See also `crux-reopen-as-root-mode'."
   (:require +zzz-to-char)
   (:option zzz-to-char-reach 1024)
   (:global "M-z" #'+zzz-to-char))
+
+(setup (:straight (ytdious
+                   :fork (:host github :repo "duckwork/ytdious")))
+  (:also-load +ytdious)
+  (:option ytdious-invidious-api-url (if +invidious-host
+                                         (concat "https://" invidious-host)
+                                       "https://invidious.snopyta.org"))
+  (:bind "y" #'+ytdious-watch))
diff --git a/lisp/+ytdious.el b/lisp/+ytdious.el
new file mode 100644
index 0000000..6124149
--- /dev/null
+++ b/lisp/+ytdious.el
@@ -0,0 +1,21 @@
+;;; +ytdious.el --- Ytdious customizations -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;; https://github.com/spiderbit/ytdious
+
+;;; Code:
+
+(defun +ytdious-watch ()
+  "Stream video at point in mpv."
+  (interactive)
+  (let* ((video (ytdious-get-current-video))
+         (id    (ytdious-video-id-fun video)))
+    (start-process "ytdious mpv" nil
+                   "mpv"
+                   (concat "https://www.youtube.com/watch?v=" id))
+    "--ytdl-format=bestvideo[height<=?720]+bestaudio/best")
+  (message "Starting streaming..."))
+
+(provide '+ytdious)
+;;; +ytdious.el ends here
-- 
cgit 1.4.1-21-gabe81