___________________________________________

               HOW I USE EMACS FOR YOUTUBE SUBSCRIPTIONS
              ___________________________________________


1 Problem
=========

  I consume  youtube content daily  but I  don't like the  bloated web
  interface. If possible  I want to view videos in  my preferred video
  player and  not the browser. Also  I don't want to  create a youtube
  account for my subscriptions to reduce tracking. If I think about it
  I  hate nearly  everything about  youtube  ;_; Luckily  there is  an
  alternative  front-end  which  is  lightweight  and  free  software:
  invidio.us (official site[1], github[2]).

  UPDATE  Feb-2021: invidou.us  is no  more but  there are  many other
  instances[3].


2 Elfeed
========

  Every youtube channel has a RSS feed which youtube in their absolute
  curtesy hides  from us. Still we  can get the url  directly from the
  corresponding invidio.us channel page. So  the only thing we need is
  a RSS feed viewer for Emacs. For this I use elfeed[4]

  I put this in my .emacs file to add my feeds:

  ,----
  | (setq elfeed-feeds
  |       (quote
  |       ("https://www.invidiuo.us/feed/channel/ID1" youtube)
  |       ("https://www.invidiuo.us/feed/channel/ID2" youtube)))
  `----

  Now I add a search filter:

  ,----
  | (setq-default elfeed-search-filter "youtube #50")
  `----

  This means: show the last 50 entries tagged "youtube".

  Feed reader usage:

  - open the feed reader: M-x elfeed
  - update feeds: G
  - change filter on the fly: s
  - view entry: ENTER
  - close entry: q

  Easy.


3 Youtube-dl
============

  To download  the video I  use youtube-dl[5]. To directly  download a
  video from the feed-entry I wrote this function:

  UPDATE Nov-2021: It seems that  the youtube-dl project is abandoned.
  Now I use yt-dlp[6] (an actively maintained fork) as replacement

  ,----
  | (defun ytdl ()
  |   "Download URL with youtube-dl"
  |   (interactive)
  |   (beginning-of-buffer)
  |   (forward-line 2)
  |   (search-forward "http")  
  |   (shell-command
  |    (format "cd ~/ && yt-dlp '%s' &"
  | 	   (thing-at-point 'url)))
  |   (kill-buffer "*elfeed-entry*")
  |   (message "Download started..."))
  `----

  Now I can call this function via M-x or a keybinding, locate the video
  with dired and open it from within Emacs. Check my other writings on
  Emacs to learn more.



Footnotes
_________

[1] https://invidio.us
[2] https://github.com/omarroth/invidious
[3] https://github.com/iv-org/documentation/blob/master/Invidious-Instances.md
[4] https://github.com/skeeto/elfeed
[5] https://github.com/ytdl-org/youtube-dl/
[6] https://github.com/yt-dlp/yt-dlp