diff options
author | mms <michal@sapka.me> | 2024-02-23 16:27:41 +0100 |
---|---|---|
committer | mms <michal@sapka.me> | 2024-02-23 16:27:41 +0100 |
commit | 13189091e0eb0e9c40f8df87684586eb8cd9b0b1 (patch) | |
tree | 16eaeab0f6bfad408fb30bc35d65d23c5aece00f /content/emacs | |
parent | 1acc90e631460a69838299ae4128b36815b9a5ef (diff) |
feat: yeetube
Diffstat (limited to 'content/emacs')
-rw-r--r-- | content/emacs/watching-youtube-with-emacs.md | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/content/emacs/watching-youtube-with-emacs.md b/content/emacs/watching-youtube-with-emacs.md new file mode 100644 index 0000000..4aed17f --- /dev/null +++ b/content/emacs/watching-youtube-with-emacs.md @@ -0,0 +1,105 @@ ++++ +title = "Emacs: watching YouTube with Yeetube and mpv" +author = ["MichaĆ Sapka"] +date = 2024-02-23T16:16:00+01:00 +categories = ["emacs"] +draft = false +weight = 2007 +abstract = "Let's use YouTube from the comfort of Emacs" +[menu] + [menu.emacs-guides] + weight = 2007 + identifier = "emacs-watching-youtube-with-yeetube-and-mpv" + name = "Watching YouTube" ++++ + +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. + +_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) + (setq 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")) +``` + +[^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.
\ No newline at end of file |