summaryrefslogtreecommitdiff
path: root/content/emacs/yeetube.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/emacs/yeetube.md')
-rw-r--r--content/emacs/yeetube.md121
1 files changed, 121 insertions, 0 deletions
diff --git a/content/emacs/yeetube.md b/content/emacs/yeetube.md
new file mode 100644
index 0000000..1d35a65
--- /dev/null
+++ b/content/emacs/yeetube.md
@@ -0,0 +1,121 @@
++++
+title = "Watch YouTube with Yeetube and mpv"
+author = ["MichaƂ Sapka"]
+date = 2024-02-23T16:16:00+01:00
+categories = ["emacs"]
+draft = false
+weight = 3003
+image_dir = "emacs"
+image_max_width = 480
+primary_menu = "cool-emacs-ways"
+abstract = "Let's use YouTube from the comfort of Emacs"
+aliases = ["/emacs/watching-youtube-with-emacs/", "/cool-emacs/watch-youtube"]
+[menu]
+ [menu.cool-emacs-ways]
+ weight = 3003
+ identifier = "watch-youtube-with-yeetube-and-mpv"
++++
+
+I may hate YouTube as a service, but I even I can't deny the quality of vlogs there.
+Even though I would strongly prefer to follow folks on PeerTube or Odysee, this will not happen anytime soon for most of the channels.
+Luckily, with the popularity of YouTube comes quite a few ways to use it in a better way
+
+
+## Yeetube {#yeetube}
+
+_Yeetube_[^fn:1] is an Emacs wrapper around searching and viewing videos on Youtube.
+The watching part happens via `mpv`[^fn:2].
+You simply pass the video link (not the page) in the shell and `mpv` will handle the rest.
+_Yeetube_ handles everything _before_ we have the actual file, and running `mpv`.
+
+First, let's install it:
+
+```emacs-lisp
+(use-package yeetube)
+```
+
+And, assuming `mpv` is already installed, you are ready to go.
+Run `yeetube-search`, type in whatever you want and press enter.
+A table with top results will show up.
+Now, select the one that interests you, run `yeetube-play`, wait a few seconds and mpv window will show.
+
+{{< image class="centered" alt="An Emacs screenshot showing a list using a dark mode" file="emacs-yeetube-search.png" >}}
+Yeetube search for Emacs Elements
+{{< /image >}}
+
+{{< image class="centered" alt="A screenshot of a DWM windows manager. Left of the screen is ocupied by MPV, the right one with Emacs." file="emacs-yeetube-play.png" >}}
+mpv playing a movie next to Emacs with Yeetube search.
+{{< /image >}}
+
+_Yeetube_ also supports downloading videos via `yt-dl` and saving videos for future reference.
+
+My full config, with evil keybindings looks like:
+
+```emacs-lisp
+(use-package yeetube
+ :general
+ (:states 'normal
+ :keymaps 'yeetube-mode-map
+ "RET" 'yeetube-play
+ "d" 'yeetube-download-video
+ "b" 'yeetube-play-saved-video
+ "B" 'yeetube-save-video
+ "x" 'yeetube-remove-saved-video
+ "/" 'yeetube-search
+ "0" 'yeetube-toggle-video
+ ))
+```
+
+Note that this comes with no ads, and less tracking, but also less revenue to the creator.
+Being a patron is a good way to feel better about it.
+
+
+## Link handler {#link-handler}
+
+This is nice, but we can make it _extra-nice_.
+I subscribe to quite a few YouTube channels via RSS[^fn:3] and want to use _Yeetube_ fast.
+We can write a very simple _elisp_ function:
+
+```emacs-lisp
+(defun mms-open-yt-under-point ()
+ (interactive)
+ (setq url (thing-at-point 'url))
+ (string-match "youtube.com" url)
+```
+
+Now, move the pointer on a YT[^fn:4] link and call this function.
+_Yeetube_ interface will open, so just play the top result.
+
+My (current) full function in use is:
+
+```emacs-lisp
+(defun mms-open-link-under-point ()
+ (interactive)
+ (let (url (thing-at-point 'url))
+ (cond
+ ((string-match "youtube.com" url) (yeetube-search url))
+ (t (eww url)))
+ ))
+```
+
+So it will use `eww` for anything that is not a YT link, and I can expand it further whenever I want.
+
+Then, just add a simple keyboard navigation, and you're done
+
+```emacs-lisp
+(mms-leader-keys
+ "RET RET" '(lambda () (interactive) (mms-open-link-under-point) :wk "follow link"))
+```
+
+
+## Errata {#errata}
+
+2024-02-26: Dave pointed me that using `let` inside custom method is preferable to `setq`
+
+[^fn:1]: ["yeetube | Emacs Front-End for YouTube"](https://thanosapollo.org/post/yeetube/) blog post from the author
+[^fn:2]: [mpv official website](https://mpv.io/)
+[^fn:3]: The secret URL: `https://www.youtube.com/feeds/videos.xml?channel_id=<channel_id>`.
+ You can find the channel ID using different online services, as it is not as straight forward as it should be.
+[^fn:4]: Only if the package registers itself as a provider for `thing-at-point`.
+ In Elfeed it will for main item URL, but not for items embedded in the body.
+ We need to use `eww` to open the page and we can get the URL from there.