summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml39
-rw-r--r--docker/Dockerfile2
-rw-r--r--shard.yml6
-rw-r--r--src/invidious/helpers/handlers.cr26
-rw-r--r--src/invidious/helpers/proxy.cr8
-rw-r--r--src/invidious/videos.cr42
6 files changed, 58 insertions, 65 deletions
diff --git a/.travis.yml b/.travis.yml
index da787cf1..f5918bb1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,17 +1,28 @@
-language: crystal
-
-crystal:
- - latest
-
dist: bionic
-before_install:
- - shards update
- - shards install
-
-install:
- - crystal build --error-on-warnings src/invidious.cr
+jobs:
+ include:
+ - stage: build
+ language: crystal
+ crystal: latest
+ before_install:
+ - shards update
+ - shards install
+ install:
+ - crystal build --error-on-warnings src/invidious.cr
+ script:
+ - crystal tool format --check
+ - crystal spec
-script:
- - crystal tool format --check
- - crystal spec
+ - stage: build_docker
+ language: minimal
+ services:
+ - docker
+ install:
+ - docker-compose build
+ script:
+ - docker-compose up -d
+ - sleep 15 # Wait for cluster to become ready, TODO: do not sleep
+ - HEADERS="$(curl -I -s http://localhost:3000/)"
+ - STATUS="$(echo $HEADERS | head -n1)"
+ - if [[ "$STATUS" != *"200 OK"* ]]; then echo "$HEADERS"; exit 1; fi
diff --git a/docker/Dockerfile b/docker/Dockerfile
index c9fa6367..45fade57 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,4 +1,4 @@
-FROM alpine:latest AS builder
+FROM alpine:edge AS builder
RUN apk add -u crystal shards libc-dev \
yaml-dev libxml2-dev sqlite-dev sqlite-static zlib-dev openssl-dev
WORKDIR /invidious
diff --git a/shard.yml b/shard.yml
index 09c54a51..0f9beaf2 100644
--- a/shard.yml
+++ b/shard.yml
@@ -11,14 +11,14 @@ targets:
dependencies:
pg:
github: will/crystal-pg
- version: ~> 0.18.0
+ version: ~> 0.18.1
sqlite3:
github: crystal-lang/crystal-sqlite3
version: ~> 0.13.0
kemal:
github: kemalcr/kemal
- version: ~> 0.25.2
+ version: ~> 0.26.0
-crystal: 0.30.0
+crystal: 0.30.1
license: AGPLv3
diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr
index 7fbfb643..51bc9545 100644
--- a/src/invidious/helpers/handlers.cr
+++ b/src/invidious/helpers/handlers.cr
@@ -69,20 +69,20 @@ class FilteredCompressHandler < Kemal::Handler
return call_next env if exclude_match? env
{% if flag?(:without_zlib) %}
- call_next env
- {% else %}
- request_headers = env.request.headers
-
- if request_headers.includes_word?("Accept-Encoding", "gzip")
- env.response.headers["Content-Encoding"] = "gzip"
- env.response.output = Gzip::Writer.new(env.response.output, sync_close: true)
- elsif request_headers.includes_word?("Accept-Encoding", "deflate")
- env.response.headers["Content-Encoding"] = "deflate"
- env.response.output = Flate::Writer.new(env.response.output, sync_close: true)
- end
+ call_next env
+ {% else %}
+ request_headers = env.request.headers
+
+ if request_headers.includes_word?("Accept-Encoding", "gzip")
+ env.response.headers["Content-Encoding"] = "gzip"
+ env.response.output = Gzip::Writer.new(env.response.output, sync_close: true)
+ elsif request_headers.includes_word?("Accept-Encoding", "deflate")
+ env.response.headers["Content-Encoding"] = "deflate"
+ env.response.output = Flate::Writer.new(env.response.output, sync_close: true)
+ end
- call_next env
- {% end %}
+ call_next env
+ {% end %}
end
end
diff --git a/src/invidious/helpers/proxy.cr b/src/invidious/helpers/proxy.cr
index e3c9d2f5..fde282cd 100644
--- a/src/invidious/helpers/proxy.cr
+++ b/src/invidious/helpers/proxy.cr
@@ -31,10 +31,10 @@ class HTTPProxy
if resp[:code]? == 200
{% if !flag?(:without_openssl) %}
- if tls
- tls_socket = OpenSSL::SSL::Socket::Client.new(socket, context: tls, sync_close: true, hostname: host)
- socket = tls_socket
- end
+ if tls
+ tls_socket = OpenSSL::SSL::Socket::Client.new(socket, context: tls, sync_close: true, hostname: host)
+ socket = tls_socket
+ end
{% end %}
return socket
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index cf83d6c2..7fd06dd5 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -1132,35 +1132,20 @@ def fetch_video(id, region)
info = extract_player_config(response.body, html)
info["cookie"] = response.cookies.to_h.map { |name, cookie| "#{name}=#{cookie.value}" }.join("; ")
- # Try to use proxies for region-blocked videos
+ allowed_regions = html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).try &.["content"].split(",")
+ allowed_regions ||= [] of String
+
+ # Check for region-blocks
if info["reason"]? && info["reason"].includes? "your country"
- bypass_channel = Channel({XML::Node, HTTP::Params} | Nil).new
-
- PROXY_LIST.each do |proxy_region, list|
- spawn do
- client = make_client(YT_URL, proxy_region)
- proxy_response = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999")
-
- proxy_html = XML.parse_html(proxy_response.body)
- proxy_info = extract_player_config(proxy_response.body, proxy_html)
-
- if !proxy_info["reason"]?
- proxy_info["region"] = proxy_region
- proxy_info["cookie"] = proxy_response.cookies.to_h.map { |name, cookie| "#{name}=#{cookie.value}" }.join("; ")
- bypass_channel.send({proxy_html, proxy_info})
- else
- bypass_channel.send(nil)
- end
- end
- end
+ region = allowed_regions.sample(1)[0]?
+ client = make_client(YT_URL, region)
+ response = client.get("/watch?v=#{id}&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999")
- PROXY_LIST.size.times do
- response = bypass_channel.receive
- if response
- html, info = response
- break
- end
- end
+ html = XML.parse_html(response.body)
+ info = extract_player_config(response.body, html)
+
+ info["region"] = region if region
+ info["cookie"] = response.cookies.to_h.map { |name, cookie| "#{name}=#{cookie.value}" }.join("; ")
end
# Try to pull streams from embed URL
@@ -1215,9 +1200,6 @@ def fetch_video(id, region)
published ||= Time.utc.to_s("%Y-%m-%d")
published = Time.parse(published, "%Y-%m-%d", Time::Location.local)
- allowed_regions = html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).try &.["content"].split(",")
- allowed_regions ||= [] of String
-
is_family_friendly = html.xpath_node(%q(//meta[@itemprop="isFamilyFriendly"])).try &.["content"] == "True"
is_family_friendly ||= true