Compare commits

..

1 commit

Author SHA1 Message Date
dfdc9e5189
Merge remote-tracking branch 'upstream/master' into testing3 2024-10-31 20:22:59 -03:00
8 changed files with 53 additions and 62 deletions

View file

@ -37,15 +37,13 @@ jobs:
type=sha,format=short,prefix={{date 'YYYY.MM.DD'}}-,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} type=sha,format=short,prefix={{date 'YYYY.MM.DD'}}-,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
- uses: https://code.forgejo.org/docker/build-push-action@v6 - uses: https://code.forgejo.org/docker/build-push-action@v5
name: Build images name: Build images
with: with:
context: . context: .
file: docker/Dockerfile file: docker/Dockerfile
tags: ${{ steps.meta.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64 platforms: linux/amd64
# cache-from: type=gha
# cache-to: type=gha,mode=max
push: true push: true
build-args: | build-args: |
"release=1" "release=1"

View file

@ -1,4 +1,4 @@
FROM crystallang/crystal:1.14.0-alpine AS builder FROM crystallang/crystal:1.12.1-alpine AS builder
RUN apk add --no-cache sqlite-static yaml-static RUN apk add --no-cache sqlite-static yaml-static

View file

@ -23,22 +23,6 @@ def produce_channel_content_continuation(ucid, content_type, page = 1, auto_gene
else 15 # Fallback to "videos" else 15 # Fallback to "videos"
end end
sort_type_numerical =
case content_type
when "videos" then 3
when "livestreams" then 5
else 3 # Fallback to "videos"
end
if content_type == "livestreams"
sort_by_numerical =
case sort_by
when "newest" then 12_i64
when "popular" then 14_i64
when "oldest" then 13_i64
else 12_i64 # Fallback to "newest"
end
else
sort_by_numerical = sort_by_numerical =
case sort_by case sort_by
when "newest" then 1_i64 when "newest" then 1_i64
@ -46,7 +30,6 @@ def produce_channel_content_continuation(ucid, content_type, page = 1, auto_gene
when "oldest" then 4_i64 when "oldest" then 4_i64
else 1_i64 # Fallback to "newest" else 1_i64 # Fallback to "newest"
end end
end
object_inner_1 = { object_inner_1 = {
"110:embedded" => { "110:embedded" => {
@ -58,7 +41,7 @@ def produce_channel_content_continuation(ucid, content_type, page = 1, auto_gene
"2:embedded" => { "2:embedded" => {
"1:string" => "00000000-0000-0000-0000-000000000000", "1:string" => "00000000-0000-0000-0000-000000000000",
}, },
"#{sort_type_numerical}:varint" => sort_by_numerical, "3:varint" => sort_by_numerical,
}, },
}, },
}, },

View file

@ -6,14 +6,9 @@ module Tokens
def refresh_tokens def refresh_tokens
@@po_token = REDIS_DB.get("invidious:po_token") @@po_token = REDIS_DB.get("invidious:po_token")
@@visitor_data = REDIS_DB.get("invidious:visitor_data") @@visitor_data = REDIS_DB.get("invidious:visitor_data")
if !@@po_token.nil? && !@@visitor_data.nil? LOGGER.debug("RefreshTokens: Tokens are:")
LOGGER.debug("RefreshTokens: Successfully updated tokens") LOGGER.debug("RefreshTokens: po_token: #{@@po_token}")
else LOGGER.debug("RefreshTokens: visitor_data: #{@@visitor_data}")
LOGGER.warn("RefreshTokens: Tokens are empty!")
end
LOGGER.trace("RefreshTokens: Tokens are:")
LOGGER.trace("RefreshTokens: po_token: #{@@po_token}")
LOGGER.trace("RefreshTokens: visitor_data: #{@@visitor_data}")
end end
def get_tokens def get_tokens

View file

@ -4,28 +4,51 @@ module Invidious::HttpServer
module Utils module Utils
extend self extend self
@@proxy_alive : String = "" @@proxy_list : Array(String) = [] of String
@@current_proxy : String = ""
@@count : Int64 = Time.utc.to_unix
def check_external_proxy def check_external_proxy
CONFIG.external_videoplayback_proxy.each do |proxy| CONFIG.external_videoplayback_proxy.each do |proxy|
begin begin
response = HTTP::Client.get("#{proxy[:url]}/health") response = HTTP::Client.get("#{proxy[:url]}/health")
if response.status_code == 200 if response.status_code == 200
@@proxy_alive = proxy[:url] if @@proxy_list.includes?(proxy[:url])
LOGGER.debug("CheckExternalProxy: Proxy set to: '#{proxy[:url]}'") next
break end
if proxy[:balance]
@@proxy_list << proxy[:url]
LOGGER.debug("CheckExternalProxy: Adding proxy '#{proxy[:url]}' to the list of proxies")
end
break if proxy[:balance] == false && !@@proxy_list.empty?
@@proxy_list << proxy[:url]
end end
rescue rescue
if @@proxy_list.includes?(proxy[:url])
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available, removing it from the list of proxies")
@@proxy_list.delete(proxy[:url])
end
LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available") LOGGER.debug("CheckExternalProxy: Proxy '#{proxy[:url]}' is not available")
end end
end end
if @@proxy_alive.empty? LOGGER.trace("CheckExternalProxy: List of proxies:")
LOGGER.warn("CheckExternalProxy: No proxies alive! Using own server proxy") LOGGER.trace("#{@@proxy_list.inspect}")
end
# TODO: If the function is called many times, it will return a random
# proxy from the list. That is not how it should be.
# It should return the same proxy, in multiple function calls
def select_proxy
if (@@count - (Time.utc.to_unix - 30)) <= 0
return if @@proxy_list.size <= 0
@@current_proxy = @@proxy_list[Random.rand(@@proxy_list.size)]
LOGGER.debug("Current proxy is: '#{@@current_proxy}'")
@@count = Time.utc.to_unix
end end
end end
def get_external_proxy def get_external_proxy
return @@proxy_alive return @@current_proxy
end end
def proxy_video_url(raw_url : String, *, region : String? = nil, absolute : Bool = false) def proxy_video_url(raw_url : String, *, region : String? = nil, absolute : Bool = false)
@ -38,8 +61,8 @@ module Invidious::HttpServer
url.query_params = params url.query_params = params
if absolute if absolute
if !@@proxy_alive.empty? if !(proxy = get_external_proxy()).empty?
return "#{@@proxy_alive}#{url.request_target}" return "#{proxy}#{url.request_target}"
else else
return "#{HOST_URL}#{url.request_target}" return "#{HOST_URL}#{url.request_target}"
end end

View file

@ -5,8 +5,9 @@ class Invidious::Jobs::CheckExternalProxy < Invidious::Jobs::BaseJob
def begin def begin
loop do loop do
HttpServer::Utils.check_external_proxy HttpServer::Utils.check_external_proxy
LOGGER.info("CheckExternalProxy: Done, sleeping for 10 seconds") HttpServer::Utils.select_proxy
sleep 10.seconds LOGGER.info("CheckExternalProxy: Done, sleeping for 15 seconds")
sleep 15.seconds
Fiber.yield Fiber.yield
end end
end end

View file

@ -152,7 +152,6 @@ module Invidious::Routes::Watch
end end
end end
# Removes non default audio tracks
audio_streams.reject! do |z| audio_streams.reject! do |z|
z if z.dig?("audioTrack", "audioIsDefault") == false z if z.dig?("audioTrack", "audioIsDefault") == false
end end
@ -219,12 +218,6 @@ module Invidious::Routes::Watch
captions: video.captions captions: video.captions
) )
begin
video_url = fmt_stream[0]["url"].to_s
rescue
video_url = nil
end
templated "watch" templated "watch"
end end

View file

@ -13,13 +13,11 @@
<meta property="og:image" content="<%= HOST_URL %>/vi/<%= video.id %>/maxres.jpg"> <meta property="og:image" content="<%= HOST_URL %>/vi/<%= video.id %>/maxres.jpg">
<meta property="og:description" content="<%= HTML.escape(video.short_description) %>"> <meta property="og:description" content="<%= HTML.escape(video.short_description) %>">
<meta property="og:type" content="video.other"> <meta property="og:type" content="video.other">
<!-- This shouldn't be empty, ever. --> <meta property="og:video:url" content="<%= HOST_URL %>/embed/<%= video.id %>">
<meta property="og:video" content="<%= video_url %>"> <meta property="og:video:secure_url" content="<%= HOST_URL %>/embed/<%= video.id %>">
<meta property="og:video:url" content="<%= video_url %>"> <meta property="og:video:type" content="text/html">
<meta property="og:video:secure_url" content="<%= video_url %>"> <meta property="og:video:width" content="1280">
<meta property="og:video:type" content="video/mp4"> <meta property="og:video:height" content="720">
<meta property="og:video:width" content="640">
<meta property="og:video:height" content="360">
<meta name="twitter:card" content="player"> <meta name="twitter:card" content="player">
<meta name="twitter:url" content="<%= HOST_URL %>/watch?v=<%= video.id %>"> <meta name="twitter:url" content="<%= HOST_URL %>/watch?v=<%= video.id %>">
<meta name="twitter:title" content="<%= title %>"> <meta name="twitter:title" content="<%= title %>">