]>
Commit | Line | Data |
---|---|---|
2c707b05 JN |
1 | --- |
2 | title: "Adventures with YouTube" | |
3 | date: 2020-08-02T05:40:09+05:30 | |
4 | lastmod: 2019-11-04T15:40:09+05:30 | |
5 | tags : [ "free-software", "YouTube", "privacy", "MPV", "NimCoon" ] | |
6 | categories : [ "free-software", "privacy" ] | |
7 | layout: post | |
8 | type: "post" | |
9 | highlight: false | |
10 | --- | |
11 | ||
12 | ## Why? | |
13 | ||
14 | ||
15 | I stopped using my Google account several years ago. This means that I can no | |
16 | longer subscribe to YouTube channels directly in YouTube. | |
17 | ||
18 | I have been playing YouTube links that I find directly using the [MPV](https://mpv.io) player, | |
19 | which internally uses [youtube-dl](https://youtube-dl.org) to fetch the video. | |
20 | ||
21 | ![Y U No Use YouTube Website](/blog/youtube-yuno.png) | |
22 | ||
23 | Not using the YouTube | |
24 | website directly has several advantages. YouTube's revenue is based on the | |
25 | number of advertisements you see on the website. So, the more time you spend on | |
26 | YouTube the more money they earn. It is easy to get around the advertisements by | |
27 | using ad-blockers, but the site itself is optimized for binge-watching with | |
28 | features such as auto-play being turned on by default. If your objective is to | |
29 | just watch one useful video and leave, YouTube's website doesn't make it easy. | |
30 | ||
31 | ## Playing YouTube videos on the desktop | |
32 | ||
33 | Over the years, I experimented with several solutions for playing YouTube videos | |
34 | without going to the YouTube website. | |
35 | ||
36 | One of the oldest solutions in this category is SMTube + SMPlayer. SMPlayer is a | |
37 | GUI player based on MPlayer. [SMTube](https://www.smtube.org/) is add-on for | |
38 | [SMPlayer](http://www.smplayer.info/) that can fetch YouTube videos from a proxy | |
39 | called [Tonvid](https://tonvid.com). On clicking on any of the videos in the | |
40 | interface, it launches the video in SMPlayer. It can also be configured to use | |
41 | other backends like MPV + youtube-dl (my personal favorite). | |
42 | ||
43 | ![SMTube](/blog/smtube.png) | |
44 | ||
45 | There are two other YouTube proxies worth mentioning: | |
46 | 1. [HookTube](hooktube.com) | |
47 | 2. [Invidious](invidio.us) | |
48 | ||
49 | HookTube is a closed-source project with some amount of advertising. I used this | |
50 | till the better free software alternative Invidious was released. These proxies | |
51 | work by downloading the video to the server first and then streaming the video | |
52 | to the user. There is usually a noticeable lag in fetching the video unless it | |
53 | has already been cached. Sometimes, the YouTube API key used might run out of | |
54 | its daily allowed quota. This will be less of a problem if you self-host | |
55 | Invidious. | |
56 | ||
57 | [FreeTubeApp](https://freetubeapp.io) is an electron-based desktop app that | |
58 | allows subscriptions. It fetches its search results using an Invidious backend | |
59 | and subscriptions using RSS feeds. It is easy to import and export | |
60 | subscriptions, since they are basically just RSS feeds. | |
61 | ||
62 | ![FreeTubeApp](https://freetubeapp.io/images/FreeTube1.png) | |
63 | ||
64 | For a while, I also used a bash script called `ytview` from the | |
65 | [Bash-Snippets](https://github.com/alexanderepstein/Bash-Snippets) project to | |
66 | search and play YouTube videos from the commandline. However, over time I was | |
67 | dissatisfied with the limitations of this script. I extended some of its | |
68 | features, but writing bash is not fun. So, I ended up writing a commandline | |
69 | YouTube player called [NimCoon](https://gitlab.com/njoseph/nimcoon). You can see | |
70 | the list of supported features in the [project | |
71 | page](https://gitlab.com/njoseph/nimcoon/-/blob/master/README.md#features). I | |
72 | keep adding features to this project as and when I need them. | |
73 | ||
74 | ## RSS Feeds? 🤔 | |
75 | ||
76 | Once I exported and imported the list of subscriptions on my FreeTubeApp from | |
77 | one machine to another, I realized that I might as well import the subscriptions | |
78 | into my RSS feed reader. The feed reader I use is [Tiny Tiny | |
79 | RSS](https://tt-rss.org/). It is self-hosted on my | |
80 | [FreedomBox](https://freedombox.org). The file with the RSS feeds that I | |
81 | imported from FreeTubeApp was added as a separate category called "YouTube | |
82 | Subscriptions" in TT-RSS. | |
83 | ||
84 | TT-RSS was able to fetch the videos from my YouTube subscriptions. All I need | |
85 | from the feed reader is just the video name and URL. However, TT-RSS decided to | |
86 | embed the YouTube video into the page itself which my Firefox extension uMatrix | |
87 | was happy to block. I ended up having pages that look like this: | |
88 | ||
89 | ![YouTube feeds displayed in Tiny Tiny RSS](/blog/youtube-tt-rss.png) | |
90 | ||
91 | I needed a way of playing the video links from my feed reader in my preferred | |
92 | player (MPV, of course). I found a useful Firefox extension for this purpose | |
93 | called [ff2mpv](https://github.com/woodruffw/ff2mpv). | |
94 | ||
95 | ![ff2mpv extension](/blog/ff2mpv.png) | |
96 | ||
97 | ff2mpv makes use of the "native messaging hosts" feature in Firefox that allows you to | |
98 | invoke a system executable from Firefox. In this case, ff2mpv uses a [Python | |
99 | script](https://github.com/woodruffw/ff2mpv/blob/master/ff2mpv.py#L12) to invoke | |
100 | the MPV player with a YouTube URL. | |
101 | ||
102 | A right-click option called "Play in MPV" is added to every hyperlink in | |
103 | Firefox, which when clicked loads the video in MPV. So far, so good. | |
104 | ||
105 | But I found myself trying to play [PeerTube](https://joinpeertube.org/#/) video | |
106 | links that I find on the [Fediverse](https://en.wikipedia.org/wiki/Fediverse) | |
107 | the same way. Well, MPV + youtube-dl can still play PeerTube videos but it uses | |
108 | the HTTP stream instead of the WebTorrent stream and doesn't always pick the | |
109 | highest resolution available. Fortunately, both of these problems have already | |
110 | been solved in NimCoon. All I had to do was to change the executable invoked by | |
111 | ff2mpv's Python script from `mpv` to `nimcoon`. | |
112 | ||
113 | Before: | |
114 | ```python | |
115 | args = ["mpv", "--no-terminal", "--", url] | |
116 | ``` | |
117 | After: | |
118 | ```python | |
119 | args = ["/home/joseph/.nimble/bin/nimcoon", url] | |
120 | ``` | |
121 | ||
122 | There isn't much else to do in the RSS feed reader and the browser. Any | |
123 | improvements that I make to this setup will be in NimCoon. | |
124 | ||
125 | ## What else? | |
126 | ||
127 | While I was on this journey, many people recommended that I use elfeed in emacs | |
128 | for YouTube subscriptions and use MPV to play the videos. If I had taken that | |
129 | route, maybe most of NimCoon would've been implemented in emacs Lisp instead of | |
130 | the Nim language. Using a self-hosted RSS feed reader gives me the advantage of | |
131 | being able to use it from multiple devices. Also, I was already using TT-RSS | |
132 | well before I had heard of elfeed. ¯\\_(ツ)_/¯ | |
133 | ||
134 | If you're interested in finding out what other tools I use for reasons of | |
135 | privacy and digital minimalism, please check out my [Privacy | |
136 | Stack](https://njoseph.me/mediawiki/Privacy_Stack). |