RE: YouTube with mpv by JacksonChen666

mtime: 2023-09-11

N.B.: update at the end of the post!

Jackson’s blog is one of the blogs that I follow with my Atom/RSS feed reader. A bit over a month ago, he shared a blogpost describing how he uses mpv to watch youtube videos.

At the end of his post, he listed some disadvantages:

Also some disadvantages:

For the latter problem, he’s already got the first suggestion of using Atom/RSS feeds, which are available for YouTube channels.

But for the first problem, he doesn’t suggest anything, and I have a solution to it… And I probably have a solution to the second problem as well. I have described a lot of this on my gemini capsule, but I don’t think I went into detail about how I use newsboat for watching YouTube. Newsboat is an Atom/RSS feed reader.

Switching video resolution

So, regarding switching resolutions, mpv has a great configuration feature called profiles. Here’s my entire mpv config on this machine, in which you can see the profiles sections:

# ~/.config/mpv/mpv.conf

volume=50
geometry=50%:50%
autofit-larger=98%x94%
save-position-on-quit=yes
no-border

[360p]
ytdl-format="bestvideo[height<=?360]+bestaudio/best[height<=?360]"
geometry=99%:1%

[480p]
ytdl-format="bestvideo[height<=?480]+bestaudio/best[height<=?480]"
geometry=99%:1%

[720p]
ytdl-format="bestvideo[height<=?720]+bestaudio/best[height<=?720]"

[1080p]
ytdl-format="bestvideo[height<=?1080]+bestaudio/best[height<=?1080]"

[audio]
force-window
autofit=80%x80%
ytdl-format="bestaudio[acodec=opus]/bestaudio/worst"

Basically, the options at the beginning of the file (which aren’t preceded with any profile name encased in [ ] brackets) are applied every time you run mpv. But, the options from the sections below are only applied when we use the --profile= flag for mpv. Using this, you can write a simple script or simple bindings for opening selected videos in mpv at resolution no bigger than the desired resolution.

Now, I use this both from the command line and from scripts I wrote… And from Newsboat.

Newsboat + mpv ‘integration’

Here’s the section of my Newsboat config that’s responsible for setting my macros for opening videos in mpv at desired resolutions:

# macro for opening videos in mpv @ 1080p
macro b set browser "mpv --profile=1080p %u"; open-in-browser; set browser "/usr/bin/qutebrowser %u"

# macro for opening videos in mpv @ 720p
macro n set browser "mpv --profile=720p %u"; open-in-browser; set browser "/usr/bin/qutebrowser %u"

# macro for opening videos in mpv @ 480p
macro m set browser "mpv --profile=480p %u"; open-in-browser; set browser "/usr/bin/qutebrowser %u"

# macro for opening podcasts in mpv
macro a set browser "mpv --profile=audio %u"; open-in-browser; set browser "/usr/bin/qutebrowser %u"

The macros are triggered using comma (,) + the key assigned to the macro.

‘Feed of videos’ problem

Now, if I understood the problem of having a ‘feed of videos’, I’m guessing it’s having a feed of different feeds from all the channels you follow. Following a bunch of feeds individually isn’t how most of us consume youtube right now, and it’s clumsy with an Atom/RSS feed reader, but there is a way to ‘consolidate’ and hide feeds in Newsboat.

You can create something called a query feed. We can consolidate all the feeds with the same tag using this… And we can also hide all the feeds tagged with a ! (bang). Here’s how this looks in practice:

# youtube query feed
"query:YouTube Subscriptions:tags # \"yt-subs\""

# youtube channel feeds
https://www.youtube.com/feeds/videos.xml?channel_id=UCEKJKJ3FO-9SFv5x5BzyxhQ ! yt-subs
https://www.youtube.com/feeds/videos.xml?channel_id=UCYO_jab_esuFRV4b17AJtAw ! yt-subs
https://www.youtube.com/feeds/videos.xml?channel_id=UCmu9PVIZBk-ZCi-Sk2F2utA ! yt-subs
.
.
.

After setting everything up in this way, I have a single feed in my Newsboat called ‘YouTube Subscriptions’ and it’s a chronological feed of all the videos all the channels I subscribe to publish. I can easily open any of them in mpv by pressing ,+n or ,+b etc.

There you go, that’d be my solution to that proposed problem, Jackson, I’ll try to get this to you.


Update:

Jackson has replied to this post and there are a few corrections and additions which ought to be made here.

First of all, the way I specify resolutions (or rather formats) in my mpv config isn’t the only way to do it, and it might very well not be the best way to do it. Jackson has provided an example of how he’s doing it with his mpv.conf file.

Second, using profiles the way I do only lets you select the resolution you want the video to play at when you’re opening the link; that is, you can’t change the resolution of the stream during playback. As far as I know, mpv also doesn’t have support for DASH (adaptive quality) or a similar feature, so there’s no ‘dynamic’ resolution switching to adapt to the network conditions. I shouldn’t have omitted this.



Creative Commons License [Valid Atom 1.0] hacker antipixel 80x15 button bash button linux powered button RTFM button Vim text editor button Write your own website code! button