Rewrite Readme and some patches

This commit is contained in:
Sommerwiesel
2025-06-18 16:15:16 +02:00
parent 0898c862b7
commit 694c73c01d
3 changed files with 177 additions and 0 deletions
+10
View File
@@ -10,6 +10,16 @@ Based upon patches from:
- https://github.com/yewtudotbe/invidious-custom
- https://git.nadeko.net/Fijxu/invidious
# Requirements
You'll have to set these up yourself:
- HAProxy 2.x with my config under etc/haproxy/haproxy.conf
- PostgreSQL 16 Server
- (optional) PGBouncer, recommended when you want to host a public instance to pool connections to PSQL
- (optional) Anubis https://github.com/TecharoHQ/anubis, recommended when you want to host a public instance to prevent DDoS from bots and ai
- Nginx Web Server (1.26 or higher for quic support)
# Build instructions
Do this in a separate dir (for example /srv/invidious) under non-root permissions
+151
View File
@@ -0,0 +1,151 @@
From 7c4c24f829b4eeb8ca035b4a9d77eef53ca8aefa Mon Sep 17 00:00:00 2001
From: Emilien Devos <contact@emiliendevos.be>
Date: Sat, 10 Jun 2023 22:21:38 +0200
Subject: [PATCH 1/1] use redis for video cache
---
shard.lock | 8 ++++++++
shard.yml | 2 ++
src/invidious.cr | 8 +++++++-
src/invidious/config.cr | 3 +++
src/invidious/database/videos.cr | 16 +++++++++++++---
src/invidious/videos.cr | 2 +-
6 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/shard.lock b/shard.lock
index 397bd8bc..8c599d1b 100644
--- a/shard.lock
+++ b/shard.lock
@@ -36,6 +36,10 @@ shards:
git: https://github.com/will/crystal-pg.git
version: 0.28.0
+ pool:
+ git: https://github.com/ysbaddaden/pool.git
+ version: 0.2.4
+
protodec:
git: https://github.com/iv-org/protodec.git
version: 0.1.5
@@ -44,6 +48,10 @@ shards:
git: https://github.com/luislavena/radix.git
version: 0.4.1
+ redis:
+ git: https://github.com/stefanwille/crystal-redis.git
+ version: 2.9.1
+
spectator:
git: https://github.com/icy-arctic-fox/spectator.git
version: 0.10.6
diff --git a/shard.yml b/shard.yml
index 367f7c73..c46e1c42 100644
--- a/shard.yml
+++ b/shard.yml
@@ -31,6 +31,8 @@ dependencies:
http_proxy:
github: mamantoha/http_proxy
version: ~> 0.10.3
+ redis:
+ github: stefanwille/crystal-redis
development_dependencies:
spectator:
diff --git a/src/invidious.cr b/src/invidious.cr
index 3804197e..e2d40597 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -31,6 +31,7 @@ require "xml"
require "yaml"
require "compress/zip"
require "protodec/utils"
+require "redis"
require "./invidious/database/*"
require "./invidious/database/migrations/*"
@@ -60,7 +61,12 @@ alias IV = Invidious
CONFIG = Config.load
HMAC_KEY = CONFIG.hmac_key
-PG_DB = DB.open CONFIG.database_url
+PG_DB = DB.open CONFIG.database_url
+REDIS_DB = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: CONFIG.redis_url || nil, database: CONFIG.redis_db || 0, password: CONFIG.redis_auth || nil)
+
+if REDIS_DB.ping
+ puts "Connected to redis"
+end
ARCHIVE_URL = URI.parse("https://archive.org")
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
REDDIT_URL = URI.parse("https://www.reddit.com")
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
index c4ddcdb3..5b6c576c 100644
--- a/src/invidious/config.cr
+++ b/src/invidious/config.cr
@@ -77,6 +77,11 @@ class Config
# Used for crawling channels: threads should check all videos uploaded by a channel
property full_refresh : Bool = false
+ property redis_url : String?
+ property redis_socket : String?
+ property redis_auth : String?
+ property redis_db : Int32?
+
# Jobs config structure. See jobs.cr and jobs/base_job.cr
property jobs = Invidious::Jobs::JobsConfig.new
diff --git a/src/invidious/database/videos.cr b/src/invidious/database/videos.cr
index 695f5b33..776ef5b1 100644
--- a/src/invidious/database/videos.cr
+++ b/src/invidious/database/videos.cr
@@ -10,7 +10,8 @@ module Invidious::Database::Videos
ON CONFLICT (id) DO NOTHING
SQL
- PG_DB.exec(request, video.id, video.info.to_json, video.updated)
+ REDIS_DB.set(video.id, video.info.to_json, ex: 3600)
+ REDIS_DB.set(video.id + ":time", video.updated, ex: 3600)
end
def delete(id)
@@ -19,7 +20,8 @@ module Invidious::Database::Videos
WHERE id = $1
SQL
- PG_DB.exec(request, id)
+ REDIS_DB.del(id)
+ REDIS_DB.del(id + ":time")
end
def delete_expired
@@ -47,6 +49,14 @@ module Invidious::Database::Videos
WHERE id = $1
SQL
- return PG_DB.query_one?(request, id, as: Video)
+ if ((info = REDIS_DB.get(id)) && (time = REDIS_DB.get(id + ":time")))
+ return Video.new({
+ id: id,
+ info: JSON.parse(info).as_h,
+ updated: Time.parse(time, "%Y-%m-%d %H:%M:%S %z", Time::Location::UTC),
+ })
+ else
+ return nil
+ end
end
end
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 6d0cf9ba..dde35291 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -400,7 +400,7 @@ def get_video(id, refresh = true, region = nil, force_refresh = false)
video.schema_version != Video::SCHEMA_VERSION # cache control
begin
video = fetch_video(id, region, env)
- Invidious::Database::Videos.update(video)
+ Invidious::Database::Videos.insert(video)
rescue ex
Invidious::Database::Videos.delete(id)
raise ex
--
2.46.0
+16
View File
@@ -0,0 +1,16 @@
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index d137672a..776ea27c 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -72,6 +72,11 @@ we're going to need to do it here in order to allow for translations.
<%= rendered "components/feed_menu" %>
+<div id="watch-info">
+ If the video doesn't start playing with <i>The media could not be loaded</i> error, please just wait for a short while (Invidious will retry automatically) or try switching to another backend.<br />
+ This error is a simple timing problem with Invidious not waiting until the video data has been loaded from YouTube and will almost always just fix itself on its own.
+</div>
+
<div id="player-container" class="h-box">
<%= rendered "components/player" %>
</div>