2024-10-20
invidious/piped to newsboat
Extracting youtube subscriptions from piped and invidious accounts and using the newsboat rss reader and mpv (and yt-dlp) to play videos.
You need newsboat, mpv, yt-dlp
This guide only makes sense, if you have an account on an invidious or piped instance that you use to subscribe to channels. Log in to your instance and do the following (obviously replace the urls):
invidious export
- go to https://invidious.instance/preferences/
- Select import/export data
- Export Invidious data as OPML
- you now have: subscription_manager
piped export
- go to https://piped.instance/subscriptions
- Export to JSON
- you now have: subscriptions.json
Install newsboat. Make sure ~/.newsboat/
directory exists.
export and convert the urls from invidious (opml)
Parse the opml file - you have to extract the youtube urls and convert them to a new syntax. (Previously you could feed your rss reader with the direct url to a youtube channel, not anymore.)
$ cat subscription_manager | tr ">" "\n" | grep http | cut -d '"' -f8 |\ cut -d "/" -f4- |\ sed 's/feed\/channel\//https:\/\/www.youtube.com\/feeds\/videos.xml?channel_id=/g' >> ~/.newsboat/urls
export and convert the urls from piped (json)
Parse the json file.
$ cat subscriptions.json | tr "{" "\n" | cut -d '"' -f4 |\ sed 's/channel\//feeds\/videos.xml?channel_id=/g' >> ~/.newsboat/urls
configure newsboat
Edit ~/.newsboat/config
. This is the bare minimum. Opening a link
will stream the selected video through mpv+yt-dlp and the feeds will be
sorted chronologically according to the date of the last video on the
channel.
#~/.newsboat/config browser mpv feed-sort-order lastupdated
Run newsboat and press Shift+R to refresh all the feeds. Done. Select a channel, select a video and press 'o'. After a short while mpv will start playing the video.
If you already use newsboat
...and don't want to polute your urls
file with
youtube channels, consider saving the file with channel urls to
a separate file, ie: ~/.newsboat/youtube
. Similarly
you can create a separate configuration file to use just when
viewing youtube feeds. ie: ~/.newsboat/yt-config
.
You would then run
$ newsboat -u ~/.newsboat/youtube -C ~/.newsboat/yt-config
You could alias the previous to something like `newsboat-yt'.
extra
By default, mpv/yt-dlp will stream the video in the highest
available quality. For the sake of old machines and bandwidth, you
can define yt-dlp options for mpv in ~/.config/mpv/mpv.conf
.
The following will stream youtube videos at 420p.
#~/.config/mpv/mpv.conf ytdl-format="bestvideo[height<=?420]+bestaudio[height<=?420]"
Have fun. Or maybe stop using youtube altogether.
More
[fediverse] mostlypat of patpatpat.xyz wrote a program to get youtube rss urls by simply typing the youtube channel's name, it comes in either a perl or python flavor:
[fediverse] Hund of hunden.linuxkompis.se wrote several articles in a similar minimalistic youtube watching vein: