about summary refs log tree commit diff homepage
path: root/blog/youtu.md
blob: 6c188d29b7a3fab47232ed233b20795b4d9bc4b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
+++
rss = "Do you know de wey?  Lemme show you de wey!"
date = Date(2024, 1, 17)
tags = ["fun", "recipe", "net", "nix", "clipboard"]
+++

# Best Ways to Watch YouTube Videos

In today's episode of [guides nobody asked for and likely having
been covered by someone more qualified][idgaf], lemme show you
the _correct_ ways to view videos hosted on YouTube and other
hostile, tracker-riddled hellscapes.  Whilst I despise Google's
mass surveillance practices, it stores a large proportion
of culturally significant videos and clips that would be difficult
to mirror to user-respecting services due to copyright.  Hell, even YouTube
doesn't have the right to distribute many of them in the first place.

Because of YouTube's circumvention of advertisement blockers,
the ad-blocking arm race finally caught mainstream media attention
and tis kool to talk about that now.  Hence I'm happy to jump
on the bandwagon, albeit a wee bit late, but this ain't just that.
Since I feed you poison—over 4% of the pages linked from my site
are on YouTube—the least I can do is sell you my cures.

## Using a Proper Media Player

The most popular solutions are either to use for a good blocker
on a browser with (supposedly) long-term support for [Manifest V2]
like [uBlock Origin] on Firefox, or use alternative front-ends
such as [Invidious] or [Piped].  Although uBlock Origin is essential
for a pleasant experience on the modern interwebs and alternative frontends
offers the best UX for browsing videos, in-browser and service-specific
media players are inferior anyway when compared to programs properly designed
for a decent playback experience.

My favorite has been [mpv] for as long as I can remember,
as it makes it easy to adjust video brightness/contrast/etc.,
playback speed, subtitle size and placements, and to overamplify
quiet audios.  Out of the box, it integrates with [yt-dlp],
a time shifter with support for [most online media services][supported].
Just drop the URL into an mpv window and [boom], it werks!

Either [drag-and-drop] or invoking `mpv $url` is quite convenient,
but not that close to following an anchor, is it?  You'd need
to first open mpv or a program launcher[^launch], then drag the URL there,
or perhaps copy and paste it for the latter cases.
What if you [gotta go fast], aye?  As a [hedgehog-maxxer] meself,
of course I can do better, and here's how.

## With a Browser Add-on

While drafting this article, I noticed that the _ff2mpv_ extension I was using
had [technically been non-free][pacifist] for a while.  Albeit I understand
and respect the author's noble intention against violence, I believe
discrimination never ends up helping those oppressed due to the power imbalance
for the exclusion false-positives to be worth it.

For this reason, I switched to [Open in mpv] and recommend it instead.
The usage is practically the same: open context menu at the video URL
and select _Open this link in mpv_.  The internal mechanism
is a bit different though, and because it influences the installation process,
I will try to briefly explain [how it works].

The way _Open in mpv_ works is a bit convoluted.  First, it wraps
the specified URL in a `mpv` scheme.  The new URL starts with `mpv://`
is then passed back to Firefox, which must have been configured to open it
in the native program `open-in-mpv`.  This program parses the URL
into the equivalent mpv command and execute it.  If you are not on NixOS,
see the [extension's README] to set it up yourself.

Otherwise, it can be declared in [configuration.nix(5)] as follows.
The declarations should be self-explanatory after referencing
Firefox's documentation for [policies.json].  If you have trouble finding
an extension's ID and download URL, search for it in [Mozzarella].

```nix
{ pkgs, ... }:
{
  programs.firefox = {
    enable = true;
    policies = {
      ExtensionSettings."{d66c8515-1e0d-408f-82ee-2682f2362726}" = {
        default_area = "menupanel";
        installation_mode = "normal_installed";
        install_url =
          "https://addons.mozilla.org/firefox"
          + "/downloads/latest/iina-open-in-mpv/latest.xpi";
      };
      Handlers.scheme.mpv = {
        action = "useHelperApp";
        ask = false;
        handlers = [ {
          name = "open-in-mpv";
          path = "${pkgs.open-in-mpv}/bin/open-in-mpv";
        } ];
      };
    };
  };
}
```

Even though Mozzarella is supposed to only show libre add-ons, be aware
that the metadata it crawls from [addons.mozzila.org] might not always
be [correct][ff2mpv].  Ideally, browser extensions should be packaged
in the distribution's repository, but packaging discipline is not exactly
NixOS's strong suit.  I will probably post an update on how to declare
`policies.json` in Guix once I figure that out.

## From a Feed Reader

Now we can properly watch videos while browsing the web,
but subscribing to YouTube channels on its web interface
would require creating an account and subjecting one's self
to more surveillance.  Fortunately, at the time of writing,
YouTube still provide Atom [feeds] for syndication.
Funny enough, they are advertised on the channel pages as RSS:

```html
<link rel="alternate"
      type="application/rss+xml"
      title="RSS"
      href="https://www.youtube.com/feeds/videos.xml?channel_id=…">
```

The referenced feed employ [Media RSS] to communicate the video URL.
This extension is widely supported by feed readers, as well
as the previously mentioned feed-discovery mechanism.  I use [Liferea],
which allows me to directly paste the YouTube channel's URL[^ytc],
and displays each video's description, thumbnail and enclosed media, e.g.

![Liferea in action](/assets/liferea-youtube.png)

For each MIME type to, enclosures can be configured to be opened
by a user-preferred program.  In this case, I set `mpv --ytdl-format=b`
for `application/x-shockwave-flash` (a reminiscence of a time
when browsers needed [Flash] to play videos and animations)
for the _second_ best quality to save some bandwidth.  YouTube encodes
the highest resolution video separate from the audio, so the best combined
format `b` is one level lower than yt-dlp's default best video
and best audio together.

## Via Clipboard Integration

People also share videos with me via instant messaging.
I find it cumbersome to open the URL in the browser then redirect it
to the media player, so the clipboard is used as the bridge instead.
To do this, I simply create a key binding to the command below.[^wl]

```sh
mpv --ytdl-format=b "$(xclip -out -selection clipboard)"
```

## Musing

There, I shared how I do it so [you can too]!  If they seem
needlessly complex, you share my disappointment on the UX evolution
of the mainstream web.  I dream of a more semantic web, not necessarily
web 3.0, perhaps just more explicitly typed, where e.g. a YouTube URL
for embedding would be a `video/webm` instead of a `text/html`.

If `mailto` URIs can launch our email client, and social media pages
can bug us to open the post in their own app, why can't we have
interoperable media handling?  Maybe we should, but I'm not sure if we can.
[Greed] stands in our way.  Providers force us to use their proprietary
[malware] to consume their service.  [DRM] has become the foundation
of media distribution.  Grassroots movements like [Framasoft] might never
reach mainstream status.

I don't mean to tell you to give up though, just to direct your energy
to where it matters.  Spend less on developing [alternative front-ends]
than on ethical replacements, bridges and inviting people over.
We need more [videos], more [music], more [podcasts], more [knowledge],
better [instant][xmpp] [messaging][matrix], better [search engines],
better [translations], better [home] [automation][platypush], and whatnot.
Against all odds, maybe things will finally start to improve
even for those outside of our bubble.  [Perchance.]

[^launch]: Or a terminal emulator
[^ytc]: Something starting with https://www.youtube.com/@
[^wl]: On [Wayland], replace `xclip` with something equivalent

[idgaf]: https://www.alexmolas.com/2023/07/15/nobody-cares-about-your-blog.html
[Manifest V2]: https://github.com/uBlockOrigin/uBlock-issues/issues/338#issuecomment-1332300191
[uBlock Origin]: https://ublockorigin.com
[Invidious]: https://invidious.io
[Piped]: https://github.com/TeamPiped/Piped
[mpv]: https://mpv.io
[yt-dlp]: https://github.com/yt-dlp/yt-dlp
[supported]: https://github.com/yt-dlp/yt-dlp/raw/master/supportedsites.md
[boom]: https://www.youtube.com/watch?v=_FNzL5nW_u4
[drag-and-drop]: https://uno.starshard.studio/notes/9nmgldtdgghu8m2n
[gotta go fast]: https://ziglang.org/perf
[hedgehog-maxxer]: https://video.hardlimit.com/c/morbiwars

[pacifist]: https://github.com/woodruffw/ff2mpv/commit/2397193b36e6.patch
[Open in mpv]: https://addons.mozilla.org/en-US/firefox/addon/iina-open-in-mpv
[how it works]: https://www.youtube.com/watch?v=1Fl2sMV7Hcc
[extension's README]: https://github.com/Baldomo/open-in-mpv/raw/master/README.md
[configuration.nix(5)]: https://nixos.org/manual/nixos/stable/options#opt-programs.firefox.policies
[policies.json]: https://mozilla.github.io/policy-templates
[Mozzarella]: https://gnuzilla.gnu.org/mozzarella
[ff2mpv]: https://issues.guix.gnu.org/68361
[addons.mozzila.org]: https://addons.mozilla.org

[feeds]: https://en.wikipedia.org/wiki/Web_feed
[Media RSS]: https://www.rssboard.org/media-rss
[Liferea]: https://lzone.de/liferea
[MIME]: https://en.wikipedia.org/wiki/MIME
[Flash]: https://ruffle.rs

[Wayland]: https://wayland.social/@compositor/110768798303454842

[sandboxing]: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/design/sandbox.md
[you can too]: /blog/youtu
[Greed]: https://www.searchenginejournal.com/youtube-is-showing-ads-on-non-monetized-channels/388674
[malware]: https://pluralistic.net/2023/01/21/potemkin-ai
[DRM]: https://www.defectivebydesign.org
[Framasoft]: https://framasoft.org
[alternative front-ends]: https://sr.ht/~benbusby/farside
[videos]: https://sepiasearch.org
[music]: https://www.funkwhale.audio
[podcasts]: https://castopod.org
[knowledge]: https://en.wikipedia.org/wiki/Open_access
[xmpp]: https://xmpp.org
[matrix]: https://matrix.org
[search engines]: https://seirdy.one/posts/2021/03/10/search-engines-with-own-indexes
[translations]: https://browser.mt
[home]: https://www.home-assistant.io
[platypush]: https://platypush.tech
[Perchance.]: https://fe.disroot.org/@mcsinyx/posts/ALaW77HgCSPq4pLxpo