Compare commits

...

6 commits

Author SHA1 Message Date
sf.nadeko.net ~root
baba8f8010
Add History feed menu 2024-03-15 01:31:49 -03:00
c92603246e
Add history tab in feed menu 2024-03-15 01:31:49 -03:00
a1b32c91e0
Use legit User-Agent instead of Crystal User-Agent. 2024-03-15 01:31:49 -03:00
40d7d04803
test123 2024-03-15 01:31:49 -03:00
sf.nadeko.net ~root
8a76e64ec1
Add some links and change some things in the CSS 2024-03-15 01:31:48 -03:00
Emilien Devos
1784f6cd38
use redis for video cache
Signed-off-by: zzls Selfhost <root@selfhost.zzls.xyz>
2024-03-15 01:31:48 -03:00
17 changed files with 64 additions and 16 deletions

View file

@ -121,6 +121,7 @@ body a.channel-owner {
display: flex;
justify-content: center;
flex-wrap: wrap;
margin-bottom: 1.2vh;
}
.feed-menu-item {
@ -614,7 +615,7 @@ span > select {
}
body.dark-theme {
background-color: rgba(35, 35, 35, 1);
background-color: rgba(18, 18, 18, 1);
color: #f0f0f0;
}
@ -668,7 +669,7 @@ body.dark-theme {
}
body.no-theme {
background-color: rgba(35, 35, 35, 1);
background-color: rgba(18, 18, 18, 1);
color: #f0f0f0;
}

View file

@ -163,6 +163,7 @@
"unsubscribe": "unsubscribe",
"revoke": "revoke",
"Subscriptions": "Subscriptions",
"History": "History",
"subscriptions_unseen_notifs_count": "{{count}} unseen notification",
"subscriptions_unseen_notifs_count_plural": "{{count}} unseen notifications",
"search": "search",

View file

@ -116,6 +116,7 @@
"unsubscribe": "desuscribirse",
"revoke": "revocar",
"Subscriptions": "Suscripciones",
"History": "Historial",
"search": "buscar",
"Log out": "Cerrar la sesión",
"Released under the AGPLv3 on Github.": "Publicado bajo la AGPLv3 en GitHub.",

View file

@ -32,6 +32,10 @@ shards:
git: https://github.com/will/crystal-pg.git
version: 0.24.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
@ -40,6 +44,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.4

View file

@ -28,6 +28,8 @@ dependencies:
athena-negotiation:
github: athena-framework/negotiation
version: ~> 0.1.1
redis:
github: stefanwille/crystal-redis
development_dependencies:
spectator:

View file

@ -31,6 +31,7 @@ require "xml"
require "yaml"
require "compress/zip"
require "protodec/utils"
require "redis"
require "./invidious/database/*"
require "./invidious/database/migrations/*"
@ -61,6 +62,11 @@ CONFIG = Config.load
HMAC_KEY = CONFIG.hmac_key
PG_DB = DB.open CONFIG.database_url
REDIS_DB = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: CONFIG.redis_url || 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")

View file

@ -30,7 +30,7 @@ struct ConfigPreferences
property quality : String = "hd720"
property quality_dash : String = "auto"
property default_home : String? = "Popular"
property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"]
property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists", "History"]
property automatic_instance_redirect : Bool = false
property region : String = "US"
property related_videos : Bool = true
@ -74,6 +74,8 @@ class Config
# Database configuration using 12-Factor "Database URL" syntax
@[YAML::Field(converter: Preferences::URIConverter)]
property database_url : URI = URI.parse("")
property redis_url : String?
property redis_socket : String?
# Use polling to keep decryption function up to date
property decrypt_polling : Bool = false
# Used for crawling channels: threads should check all videos uploaded by a channel

View file

@ -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

View file

@ -23,6 +23,12 @@ module Invidious::Routes::Misc
else
env.redirect "/feed/popular"
end
when "History"
if user
env.redirect "/feed/history"
else
env.redirect "/feed/popular"
end
else
templated "search_homepage", navbar_search: false
end

View file

@ -99,7 +99,7 @@ module Invidious::Routes::PreferencesRoute
default_home = env.params.body["default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
feed_menu = [] of String
4.times do |index|
5.times do |index|
option = env.params.body["feed_menu[#{index}]"]?.try &.as(String) || ""
if !option.empty?
feed_menu << option
@ -186,7 +186,7 @@ module Invidious::Routes::PreferencesRoute
CONFIG.default_user_preferences.default_home = env.params.body["admin_default_home"]?.try &.as(String) || CONFIG.default_user_preferences.default_home
admin_feed_menu = [] of String
4.times do |index|
5.times do |index|
option = env.params.body["admin_feed_menu[#{index}]"]?.try &.as(String) || ""
if !option.empty?
admin_feed_menu << option

View file

@ -42,6 +42,10 @@ module Invidious::Routes::VideoPlayback
headers["Range"] = "bytes=#{range_for_head}"
end
headers["Origin"] = "https://www.youtube.com"
headers["Referer"] = "https://www.youtube.com/"
headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0"
client = make_client(URI.parse(host), region, force_resolve = true)
response = HTTP::Client::Response.new(500)
error = ""

View file

@ -369,7 +369,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)
Invidious::Database::Videos.update(video)
Invidious::Database::Videos.insert(video)
rescue ex
Invidious::Database::Videos.delete(id)
raise ex

View file

@ -1,7 +1,7 @@
<div class="feed-menu">
<% feed_menu = env.get("preferences").as(Preferences).feed_menu.dup %>
<% if !env.get?("user") %>
<% feed_menu.reject! {|item| {"Subscriptions", "Playlists"}.includes? item} %>
<% feed_menu.reject! {|item| {"Subscriptions", "Playlists", "History"}.includes? item} %>
<% end %>
<% feed_menu.each do |feed| %>
<a href="/feed/<%= feed.downcase %>" class="feed-menu-item pure-menu-heading">

View file

@ -9,12 +9,11 @@
<div class="pure-u-1-3">
<h3>
<a href="/subscription_manager"><%= translate(locale, "Manage subscriptions") %></a>
<br>
<a href="/feed/history"><%= translate(locale, "Watch history") %></a>
</h3>
</div>
<div class="pure-u-1-3">
<h3 style="text-align:center">
<a href="/feed/history"><%= translate(locale, "Watch history") %></a>
</h3>
</div>
<div class="pure-u-1-3">
<h3 style="text-align:right">

View file

@ -128,6 +128,9 @@
<i class="icon ion-ios-paper"></i>
<a href="https://github.com/iv-org/documentation"><%= translate(locale, "footer_documentation") %></a>
</span>
<span>
<a href="https://nadeko.net"><u>nadeko.net</u></a>
</span>
</div>
<div class="pure-u-1 pure-u-md-1-3">
@ -147,7 +150,10 @@
<div class="pure-u-1 pure-u-md-1-3">
<span>
<i class="icon ion-ios-wallet"></i>
<a href="https://invidious.io/donate/"><%= translate(locale, "footer_donate_page") %></a>
<a href="https://nadeko.net/donate"><b><%= translate(locale, "footer_donate_page") %></b></a>
</span>
<span>
<a href="https://nadeko.net/contact"><b>Contact the Owner</b></a>
</span>
<span><%= translate(locale, "Current version: ") %> <%= CURRENT_VERSION %>-<%= CURRENT_COMMIT %> @ <%= CURRENT_BRANCH %></span>
</div>

View file

@ -68,6 +68,8 @@
<%= translate(locale, "Sign In") %>/<%= translate(locale, "Register") %>
</button>
<% end %>
<p>Please, do not use your E-mail address!. If you lost your password there is no way to recover it using a Password Recovery E-mail. If you lose your password, your should <a href="https://nadeko.net/contact">contact the admin</a> instead or just create a new account (If you don't care about your subscriptions, history and playlists.)</p>
<p>
</fieldset>
</form>
<% end %>

View file

@ -165,7 +165,7 @@
</div>
<% if env.get?("user") %>
<% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists"} %>
<% feed_options = {"", "Popular", "Trending", "Subscriptions", "Playlists", "History"} %>
<% else %>
<% feed_options = {"", "Popular", "Trending"} %>
<% end %>