From 2e9594274ec34907500d439063b316c85eec0cd9 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Sat, 20 Sep 2025 16:31:29 -0400 Subject: [PATCH] [skip ci] tools - add an invidious testing instance --- tools/invidious/README.md | 19 ++++ .../config/docker/init-invidious-db.sh | 12 +++ tools/invidious/config/sql/annotations.sql | 12 +++ tools/invidious/config/sql/channel_videos.sql | 30 +++++++ tools/invidious/config/sql/channels.sql | 25 ++++++ tools/invidious/config/sql/nonces.sql | 22 +++++ .../invidious/config/sql/playlist_videos.sql | 19 ++++ tools/invidious/config/sql/playlists.sql | 29 +++++++ tools/invidious/config/sql/session_ids.sql | 23 +++++ tools/invidious/config/sql/users.sql | 29 +++++++ tools/invidious/config/sql/videos.sql | 23 +++++ tools/invidious/docker-compose.yml | 86 +++++++++++++++++++ 12 files changed, 329 insertions(+) create mode 100644 tools/invidious/README.md create mode 100755 tools/invidious/config/docker/init-invidious-db.sh create mode 100644 tools/invidious/config/sql/annotations.sql create mode 100644 tools/invidious/config/sql/channel_videos.sql create mode 100644 tools/invidious/config/sql/channels.sql create mode 100644 tools/invidious/config/sql/nonces.sql create mode 100644 tools/invidious/config/sql/playlist_videos.sql create mode 100644 tools/invidious/config/sql/playlists.sql create mode 100644 tools/invidious/config/sql/session_ids.sql create mode 100644 tools/invidious/config/sql/users.sql create mode 100644 tools/invidious/config/sql/videos.sql create mode 100644 tools/invidious/docker-compose.yml diff --git a/tools/invidious/README.md b/tools/invidious/README.md new file mode 100644 index 00000000..2596a794 --- /dev/null +++ b/tools/invidious/README.md @@ -0,0 +1,19 @@ +# Invidious + +Just an Invidious docker-compose setup for quick testing with Playlet. +Detailed instructions in + +To run: + +- Create a `.env` file next to `docker-compose.yml` +- Generate two random passwords of 16 characters (e.g. using command `pwgen 16 1`) +- Add the two variables to your `.env` file + +```sh +INVIDIOUS_HMAC_KEY=PASSWORD_1 +INVIDIOUS_COMPANION_KEY=PASSWORD_2 +``` + +- Run `docker-compose up` + +Invidious should now be running locally on port 3000. diff --git a/tools/invidious/config/docker/init-invidious-db.sh b/tools/invidious/config/docker/init-invidious-db.sh new file mode 100755 index 00000000..22b4cc5f --- /dev/null +++ b/tools/invidious/config/docker/init-invidious-db.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -eou pipefail + +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channels.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/videos.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/channel_videos.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/users.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/session_ids.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/nonces.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/annotations.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlists.sql +psql --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" < config/sql/playlist_videos.sql diff --git a/tools/invidious/config/sql/annotations.sql b/tools/invidious/config/sql/annotations.sql new file mode 100644 index 00000000..3705829d --- /dev/null +++ b/tools/invidious/config/sql/annotations.sql @@ -0,0 +1,12 @@ +-- Table: public.annotations + +-- DROP TABLE public.annotations; + +CREATE TABLE IF NOT EXISTS public.annotations +( + id text NOT NULL, + annotations xml, + CONSTRAINT annotations_id_key UNIQUE (id) +); + +GRANT ALL ON TABLE public.annotations TO current_user; diff --git a/tools/invidious/config/sql/channel_videos.sql b/tools/invidious/config/sql/channel_videos.sql new file mode 100644 index 00000000..cd4e0ffd --- /dev/null +++ b/tools/invidious/config/sql/channel_videos.sql @@ -0,0 +1,30 @@ +-- Table: public.channel_videos + +-- DROP TABLE public.channel_videos; + +CREATE TABLE IF NOT EXISTS public.channel_videos +( + id text NOT NULL, + title text, + published timestamp with time zone, + updated timestamp with time zone, + ucid text, + author text, + length_seconds integer, + live_now boolean, + premiere_timestamp timestamp with time zone, + views bigint, + CONSTRAINT channel_videos_id_key UNIQUE (id) +); + +GRANT ALL ON TABLE public.channel_videos TO current_user; + +-- Index: public.channel_videos_ucid_idx + +-- DROP INDEX public.channel_videos_ucid_idx; + +CREATE INDEX IF NOT EXISTS channel_videos_ucid_idx + ON public.channel_videos + USING btree + (ucid COLLATE pg_catalog."default"); + diff --git a/tools/invidious/config/sql/channels.sql b/tools/invidious/config/sql/channels.sql new file mode 100644 index 00000000..55772da6 --- /dev/null +++ b/tools/invidious/config/sql/channels.sql @@ -0,0 +1,25 @@ +-- Table: public.channels + +-- DROP TABLE public.channels; + +CREATE TABLE IF NOT EXISTS public.channels +( + id text NOT NULL, + author text, + updated timestamp with time zone, + deleted boolean, + subscribed timestamp with time zone, + CONSTRAINT channels_id_key UNIQUE (id) +); + +GRANT ALL ON TABLE public.channels TO current_user; + +-- Index: public.channels_id_idx + +-- DROP INDEX public.channels_id_idx; + +CREATE INDEX IF NOT EXISTS channels_id_idx + ON public.channels + USING btree + (id COLLATE pg_catalog."default"); + diff --git a/tools/invidious/config/sql/nonces.sql b/tools/invidious/config/sql/nonces.sql new file mode 100644 index 00000000..644ac32a --- /dev/null +++ b/tools/invidious/config/sql/nonces.sql @@ -0,0 +1,22 @@ +-- Table: public.nonces + +-- DROP TABLE public.nonces; + +CREATE TABLE IF NOT EXISTS public.nonces +( + nonce text, + expire timestamp with time zone, + CONSTRAINT nonces_id_key UNIQUE (nonce) +); + +GRANT ALL ON TABLE public.nonces TO current_user; + +-- Index: public.nonces_nonce_idx + +-- DROP INDEX public.nonces_nonce_idx; + +CREATE INDEX IF NOT EXISTS nonces_nonce_idx + ON public.nonces + USING btree + (nonce COLLATE pg_catalog."default"); + diff --git a/tools/invidious/config/sql/playlist_videos.sql b/tools/invidious/config/sql/playlist_videos.sql new file mode 100644 index 00000000..4b48b46a --- /dev/null +++ b/tools/invidious/config/sql/playlist_videos.sql @@ -0,0 +1,19 @@ +-- Table: public.playlist_videos + +-- DROP TABLE public.playlist_videos; + +CREATE TABLE IF NOT EXISTS public.playlist_videos +( + title text, + id text, + author text, + ucid text, + length_seconds integer, + published timestamptz, + plid text references playlists(id), + index int8, + live_now boolean, + PRIMARY KEY (index,plid) +); + +GRANT ALL ON TABLE public.playlist_videos TO current_user; diff --git a/tools/invidious/config/sql/playlists.sql b/tools/invidious/config/sql/playlists.sql new file mode 100644 index 00000000..83efce48 --- /dev/null +++ b/tools/invidious/config/sql/playlists.sql @@ -0,0 +1,29 @@ +-- Type: public.privacy + +-- DROP TYPE public.privacy; + +CREATE TYPE public.privacy AS ENUM +( + 'Public', + 'Unlisted', + 'Private' +); + +-- Table: public.playlists + +-- DROP TABLE public.playlists; + +CREATE TABLE IF NOT EXISTS public.playlists +( + title text, + id text primary key, + author text, + description text, + video_count integer, + created timestamptz, + updated timestamptz, + privacy privacy, + index int8[] +); + +GRANT ALL ON public.playlists TO current_user; diff --git a/tools/invidious/config/sql/session_ids.sql b/tools/invidious/config/sql/session_ids.sql new file mode 100644 index 00000000..c493769a --- /dev/null +++ b/tools/invidious/config/sql/session_ids.sql @@ -0,0 +1,23 @@ +-- Table: public.session_ids + +-- DROP TABLE public.session_ids; + +CREATE TABLE IF NOT EXISTS public.session_ids +( + id text NOT NULL, + email text, + issued timestamp with time zone, + CONSTRAINT session_ids_pkey PRIMARY KEY (id) +); + +GRANT ALL ON TABLE public.session_ids TO current_user; + +-- Index: public.session_ids_id_idx + +-- DROP INDEX public.session_ids_id_idx; + +CREATE INDEX IF NOT EXISTS session_ids_id_idx + ON public.session_ids + USING btree + (id COLLATE pg_catalog."default"); + diff --git a/tools/invidious/config/sql/users.sql b/tools/invidious/config/sql/users.sql new file mode 100644 index 00000000..ad002ec2 --- /dev/null +++ b/tools/invidious/config/sql/users.sql @@ -0,0 +1,29 @@ +-- Table: public.users + +-- DROP TABLE public.users; + +CREATE TABLE IF NOT EXISTS public.users +( + updated timestamp with time zone, + notifications text[], + subscriptions text[], + email text NOT NULL, + preferences text, + password text, + token text, + watched text[], + feed_needs_update boolean, + CONSTRAINT users_email_key UNIQUE (email) +); + +GRANT ALL ON TABLE public.users TO current_user; + +-- Index: public.email_unique_idx + +-- DROP INDEX public.email_unique_idx; + +CREATE UNIQUE INDEX IF NOT EXISTS email_unique_idx + ON public.users + USING btree + (lower(email) COLLATE pg_catalog."default"); + diff --git a/tools/invidious/config/sql/videos.sql b/tools/invidious/config/sql/videos.sql new file mode 100644 index 00000000..55da3967 --- /dev/null +++ b/tools/invidious/config/sql/videos.sql @@ -0,0 +1,23 @@ +-- Table: public.videos + +-- DROP TABLE public.videos; + +CREATE UNLOGGED TABLE IF NOT EXISTS public.videos +( + id text NOT NULL, + info text, + updated timestamp with time zone, + CONSTRAINT videos_pkey PRIMARY KEY (id) +); + +GRANT ALL ON TABLE public.videos TO current_user; + +-- Index: public.id_idx + +-- DROP INDEX public.id_idx; + +CREATE UNIQUE INDEX IF NOT EXISTS id_idx + ON public.videos + USING btree + (id COLLATE pg_catalog."default"); + diff --git a/tools/invidious/docker-compose.yml b/tools/invidious/docker-compose.yml new file mode 100644 index 00000000..8ef8a03d --- /dev/null +++ b/tools/invidious/docker-compose.yml @@ -0,0 +1,86 @@ +version: "3" +services: + + invidious: + image: quay.io/invidious/invidious:latest + restart: unless-stopped + ports: + - "3000:3000" + environment: + # Please read the following file for a comprehensive list of all available + # configuration options and their associated syntax: + # https://github.com/iv-org/invidious/blob/master/config/config.example.yml + INVIDIOUS_CONFIG: | + db: + dbname: invidious + user: kemal + password: kemal + host: invidious-db + port: 5432 + check_tables: true + invidious_companion: + # URL used for the internal communication between invidious and invidious companion + # There is no need to change that except if Invidious companion does not run on the same docker compose file. + - private_url: "http://companion:8282/companion" + # IT is NOT recommended to use the same key as HMAC KEY. Generate a new key! + # Use the key generated in the 2nd step + invidious_companion_key: $INVIDIOUS_COMPANION_KEY + # external_port: + # domain: + # https_only: false + # statistics_enabled: false + # Use the key generated in the 2nd step + hmac_key: $INVIDIOUS_HMAC_KEY + healthcheck: + test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/trending || exit 1 + interval: 30s + timeout: 5s + retries: 2 + logging: + options: + max-size: "1G" + max-file: "4" + depends_on: + - invidious-db + + companion: + image: quay.io/invidious/invidious-companion:latest + environment: + # Use the key generated in the 2nd step + - SERVER_SECRET_KEY=$INVIDIOUS_COMPANION_KEY + restart: unless-stopped + # Uncomment only if you have configured "public_url" for Invidious companion + # Or if you want to use Invidious companion as an API in your program. + # Remove "127.0.0.1:" if used from an external IP + #ports: + # - "127.0.0.1:8282:8282" + logging: + options: + max-size: "1G" + max-file: "4" + cap_drop: + - ALL + read_only: true + # cache for youtube library + volumes: + - companioncache:/var/tmp/youtubei.js:rw + security_opt: + - no-new-privileges:true + + 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: + companioncache: \ No newline at end of file