Youtube Without Youtube; Watching Videos on the Command Line

I don’t have a Google account. This is a “problem” that is sometimes surprisingly easy to navigate, and sometimes surprisingly hard. At other times it is just very annoying. One particular annoyance is Youtube. Because I don’t have any way to “subscribe” to channels, I just end up using a mixture of the algorithm and manually searching specific channels using the search bar. This works, but is quite annoying and time-consuming. It also does not really allow me to “prioritize” videos, and I’ve had some times where I “missed” a video that I wanted to watch earlier. One additional caveat is that I like to watch videos with mpv, because it is an excellent player, has good CLI-Integration, sensible keybindings and support for a lot of Codecs. It also allows me to queue up multiple videos using umpv. So ideally, my solution will allow me to continue doing this.

The first solution that came to mind were alternative Youtube frontends. I found a list with different options that I had a look at. Most of these solutions support accounts. That would mean I could create an account on their public instance, and then use that instance to watch the videos. This seemed like a nice idea at first, but in such cases I’m more at ease with self-hosting. Most of these services support that though. I started diving into the documentation of these different services and the more I did, the less I became interested. In general these services are very resource-heavy, requiring about 4G of RAM. They are also frequently buggy. One service claims that to function: “[the application] must be restarted often, at least once a day, ideally every hour.” That doesn’t inspire much confidence. Another service only runs as a docker container, which is something I try to avoid as much as possible.

At this point I realised I was falling into a rabbit hole, and getting nowhere. At this point, I asked some of my friends and one of them pointed me towards this:

https://www.youtube.com/feeds/videos.xml?channel_id=UCyhnYIvIKK_--PiJXCMKxQQ

If we open that link, we get an Atom feed. These feeds can be plugged into an RSS reader, which gives a great overview over all the channels that I’m interested in. There’s just one tiny hitch: we need the channel ID. This is not the same thing as the name of the channel and isn’t “shown” normally. Because I didn’t need to find the ID of many channels I just ended up using a web tool to get the IDs. This worked pretty well. Apparently, there are other ways, as outlined in this SO discussion.

After gathering all channel IDs, we just have to plug them into an RSS reader. Since I hadn’t used one for quite a while, I took this opportunity to find a new (preferably TUI-based) one. I started my search with the excellent List of applications on the Arch Wiki and found canto. From their website:

“Canto is an Atom/RSS feed reader for the console that is meant to be quick, concise, and colorful. It’s meant to provide a minimal, yet information packed interface. No navigating menus. No dense blocks of unreadable white text. An interface with almost infinite customization and extensibility using the excellent Python programming language.”

That sums it up pretty well. I won’t go through all of the features Canto has, because most of them are pretty standard for an RSS/Atom reader, but I want to highlight the specific features that make it ideal for this use case. Canto allows us to set a default browser to open links, and also has a built-in reader, but its killer feature is its so-called “smart link plugin”. This plugin makes it possible to open specific file types or URLs with specific programs. This means I can use canto to open the Youtube entries with umpv, and all other entries with my normal browser. To make this possible, we just need to copy the plugin into our configuration directory, and change some settings:

cp /usr/lib/canto/plugins/smartlink.py ~/.config/canto/plugins/
vim ~/.config/canto/plugins

To change the settings, we just change the HANDLERS variable.

HANDLERS = [
    { "match-file" : "image data",
      "handler" : "feh",
    },
    { "match-file" : "PDF",
      "handler" : "evince",
    },
    { "match-url" : "youtube.com",
      "handler": "umpv",
    }
]

Now we can press f on an entry to open it with umpv, which adds it to our mpv queue. If we press g, the entry is opened in the browser we configured.

I’ve been using this setup for a few days now, and I’m very happy with it. It is exactly what I wanted: lightweight, simple, uses mpv for playback and terminal-based.


Articles from blogs I read - Generated by openring