Skip to content

Commit

Permalink
Merge branch 'master' into invidious-companion
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox authored Nov 1, 2024
2 parents 8738eb5 + 2e3a7ad commit f6d8ddc
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 102 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ jobs:
matrix:
stable: [true]
crystal:
- 1.9.2
- 1.10.1
- 1.11.2
- 1.12.1
- 1.13.2
- 1.14.0
include:
- crystal: nightly
stable: false
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

### Full list of pull requests merged since the last release (newest first)

* Add "Filipino (auto-generated)" to the list of caption languages ([#4995], by @SamantazFox)
* Makefile: Add MT option to enable the 'preview_mt' flag ([#4993], by @SamantazFox)
* SigHelper: Reconnect to signature helper ([#4991], thanks @Fijxu)
* Fix player menus hiding onHover ready ([#4750], thanks @giacomocerquone)
* Use connection pools when requesting images from YouTube ([#4326], thanks @syeopite)
* Add support for using Invidious through a HTTP Proxy ([#4270], thanks @syeopite)
* Search: Fix 'youtu.be' URLs in sanitizer ([#4894], by @SamantazFox)
* Ameba: Disable Style/RedundantNext rule ([#4888], thanks @syeopite)
* Playlists: Fix 'invalid byte sequence' error when subscribing ([#4887], thanks @DmitrySandalov)
Expand All @@ -22,7 +28,10 @@

[#4122]: https://github.com/iv-org/invidious/pull/4122
[#4193]: https://github.com/iv-org/invidious/pull/4193
[#4270]: https://github.com/iv-org/invidious/pull/4270
[#4326]: https://github.com/iv-org/invidious/pull/4326
[#4652]: https://github.com/iv-org/invidious/pull/4652
[#4750]: https://github.com/iv-org/invidious/pull/4750
[#4850]: https://github.com/iv-org/invidious/pull/4850
[#4862]: https://github.com/iv-org/invidious/pull/4862
[#4863]: https://github.com/iv-org/invidious/pull/4863
Expand All @@ -33,6 +42,9 @@
[#4928]: https://github.com/iv-org/invidious/pull/4928
[#4930]: https://github.com/iv-org/invidious/pull/4930
[#4942]: https://github.com/iv-org/invidious/pull/4942
[#4991]: https://github.com/iv-org/invidious/pull/4991
[#4993]: https://github.com/iv-org/invidious/pull/4993
[#4995]: https://github.com/iv-org/invidious/pull/4995


## v2.20240825.2 (2024-08-26)
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ STATIC := 0

NO_DBG_SYMBOLS := 0

# Enable multi-threading.
# Warning: Experimental feature!!
# invidious is not stable when MT is enabled.
MT := 0


FLAGS ?=

Expand All @@ -19,6 +24,10 @@ ifeq ($(STATIC), 1)
FLAGS += --static
endif

ifeq ($(MT), 1)
FLAGS += -Dpreview_mt
endif


ifeq ($(NO_DBG_SYMBOLS), 1)
FLAGS += --no-debug
Expand Down
1 change: 1 addition & 0 deletions assets/css/player.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

.video-js.player-style-youtube .vjs-menu-button-popup .vjs-menu {
margin-bottom: 2em;
padding-top: 2em
}

.video-js.player-style-youtube .vjs-progress-control .vjs-progress-holder, .video-js.player-style-youtube .vjs-progress-control {height: 5px;
Expand Down
11 changes: 11 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ https_only: false
##
#force_resolve:

##
## Configuration for using a HTTP proxy
##
## If unset, then no HTTP proxy will be used.
##
http_proxy:
user:
password:
host:
port:


##
## Use Innertube's transcripts API instead of timedtext for closed captions
Expand Down
1 change: 1 addition & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"Esperanto": "Esperanto",
"Estonian": "Estonian",
"Filipino": "Filipino",
"Filipino (auto-generated)": "Filipino (auto-generated)",
"Finnish": "Finnish",
"French": "French",
"French (auto-generated)": "French (auto-generated)",
Expand Down
8 changes: 6 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shards:

backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.1
version: 1.2.2

db:
git: https://github.com/crystal-lang/crystal-db.git
Expand All @@ -20,6 +20,10 @@ shards:
git: https://github.com/crystal-loot/exception_page.git
version: 0.2.2

http_proxy:
git: https://github.com/mamantoha/http_proxy.git
version: 0.10.3

kemal:
git: https://github.com/kemalcr/kemal.git
version: 1.1.2
Expand All @@ -42,7 +46,7 @@ shards:

spectator:
git: https://github.com/icy-arctic-fox/spectator.git
version: 0.10.4
version: 0.10.6

sqlite3:
git: https://github.com/crystal-lang/crystal-sqlite3.git
Expand Down
3 changes: 3 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ dependencies:
athena-negotiation:
github: athena-framework/negotiation
version: ~> 0.1.1
http_proxy:
github: mamantoha/http_proxy
version: ~> 0.10.3

development_dependencies:
spectator:
Expand Down
5 changes: 5 additions & 0 deletions src/invidious.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require "kilt"
require "./ext/kemal_content_for.cr"
require "./ext/kemal_static_file_handler.cr"

require "http_proxy"
require "athena-negotiation"
require "openssl/hmac"
require "option_parser"
Expand Down Expand Up @@ -92,6 +93,10 @@ SOFTWARE = {

YT_POOL = YoutubeConnectionPool.new(YT_URL, capacity: CONFIG.pool_size)

# Image request pool

GGPHT_POOL = YoutubeConnectionPool.new(URI.parse("https://yt3.ggpht.com"), capacity: CONFIG.pool_size)

# CLI
Kemal.config.extra_options do |parser|
parser.banner = "Usage: invidious [arguments]"
Expand Down
11 changes: 11 additions & 0 deletions src/invidious/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ struct ConfigPreferences
end
end

struct HTTPProxyConfig
include YAML::Serializable

property user : String
property password : String
property host : String
property port : Int32
end

class Config
include YAML::Serializable

Expand Down Expand Up @@ -129,6 +138,8 @@ class Config
property host_binding : String = "0.0.0.0"
# Pool size for HTTP requests to youtube.com and ytimg.com (each domain has a separate pool of `pool_size`)
property pool_size : Int32 = 100
# HTTP Proxy configuration
property http_proxy : HTTPProxyConfig? = nil

# Use Innertube's transcripts API instead of timedtext for closed captions
property use_innertube_for_captions : Bool = false
Expand Down
34 changes: 34 additions & 0 deletions src/invidious/helpers/crystal_class_overrides.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,40 @@ end
class HTTP::Client
property family : Socket::Family = Socket::Family::UNSPEC

# Override stdlib to automatically initialize proxy if configured
#
# Accurate as of crystal 1.12.1

def initialize(@host : String, port = nil, tls : TLSContext = nil)
check_host_only(@host)

{% if flag?(:without_openssl) %}
if tls
raise "HTTP::Client TLS is disabled because `-D without_openssl` was passed at compile time"
end
@tls = nil
{% else %}
@tls = case tls
when true
OpenSSL::SSL::Context::Client.new
when OpenSSL::SSL::Context::Client
tls
when false, nil
nil
end
{% end %}

@port = (port || (@tls ? 443 : 80)).to_i

self.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy
end

def initialize(@io : IO, @host = "", @port = 80)
@reconnect = false

self.proxy = make_configured_http_proxy_client() if CONFIG.http_proxy
end

private def io
io = @io
return io if io
Expand Down
23 changes: 20 additions & 3 deletions src/invidious/helpers/sig_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ module Invidious::SigHelper
@queue = {} of TransactionID => Transaction

@conn : Connection
@uri_or_path : String

def initialize(uri_or_path)
def initialize(@uri_or_path)
@conn = Connection.new(uri_or_path)
listen
end
Expand All @@ -186,10 +187,26 @@ module Invidious::SigHelper

LOGGER.debug("SigHelper: Multiplexor listening")

# TODO: reopen socket if unexpectedly closed
spawn do
loop do
receive_data
begin
receive_data
rescue ex
LOGGER.info("SigHelper: Connection to helper died with '#{ex.message}' trying to reconnect...")
# We close the socket because for some reason is not closed.
@conn.close
loop do
begin
@conn = Connection.new(@uri_or_path)
LOGGER.info("SigHelper: Reconnected to SigHelper!")
rescue ex
LOGGER.debug("SigHelper: Reconnection to helper unsuccessful with error '#{ex.message}'. Retrying")
sleep 500.milliseconds
next
end
break if !@conn.closed?
end
end
Fiber.yield
end
end
Expand Down
Loading

0 comments on commit f6d8ddc

Please sign in to comment.