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