# Watching YouTube in Private

Posted on Dec 10, 2022

I recently stumbled upon yewtu.be and found it intriguing. It not only allows you to watch YouTube without being on YouTube, but it also allows you to create an account and subscribe to channels without a Google account. What sort of wizardry is going on under the hood? It turns out that it’s a hosted instance of invidious.

This layout is simple, and JavaScript is not required.

I started using yewtu.be as my primary client for watching videos. I subscribe to several YouTube channels and I prefer the interface invidiuous provides due to its simplicity. It’s also nice to be in control of my search and watch history.

A few days ago, yewtu.be went down briefly, and that motivated me enough to self-host invidious. There are several other hosted instances listed here, but being able to easily backup my own instance (including subscriptions and watch history) is more compelling in my case.

### Hosting invidious#

The quickest way to get invidious up is with docker-compose as mentioned in the docs.

I made a few modifications (such as pinning the container’s tag), and ended up with:

    version: "3"
    services:

      invidious:
        image: quay.io/invidious/invidious:5160d8bae39dc5cc5d51abee90571a03c08d0f2b
        restart: unless-stopped
        ports:
          - "0.0.0.0:3000:3000"
        environment:
          INVIDIOUS_CONFIG: |
            db:
              dbname: invidious
              user: kemal
              password: kemal
              host: invidious-db
              port: 5432
            check_tables: true
        healthcheck:
          test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/comments/jNQXAC9IVRw || exit 1
          interval: 30s
          timeout: 5s
          retries: 2
        depends_on:
          - invidious-db

      invidious-db:
        image: docker.io/library/postgres:14
        restart: unless-stopped
        volumes:
          - postgresdata:/var/lib/postgresql/data
          - ./config/sql:/config/sql
          - ./docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh
        environment:
          POSTGRES_DB: invidious
          POSTGRES_USER: kemal
          POSTGRES_PASSWORD: kemal
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]

    volumes:
      postgresdata:

After invidious was up and running, I installed Tailscale on it to leverage its MagicDNS, and I’m now able to access this instance from anywhere at http://invidious:3000/feed/subscriptions.

### Redirecting YouTube links#

I figured it would be nice to redirect existing YouTube links that others send me, so that I could seamlessly watch the videos using invidious.

I went looking for a way to redirect paths at the browser level. I found the lightweight proxy requestly, which can be used to modify http requests in my browser. I created the following rules:

Now the link https://www.youtube.com/watch?v=-lz30by8-sU will redirect to http://invidious:3000/watch?v=-lz30by8-sU

I’m still looking for ways to improve this invidious setup. There doesn’t appear to be a way to stream in 4K yet.