mirror of
https://github.com/iv-org/invidious.git
synced 2026-10-24 22:09:13 -05:00
chore: update to ameba 1.7.0 and adapt most of the code to it (#6082)
* chore: update to ameba 1.7.0 and adapt most of the code to it * forgot to add this to build ameba into the ./bin directory for use, as ameba does not longer offer a postinstall script * forgot to update ameba in the shards files * remove leftover : in rescue * Use ameba linter action instead of installing it with shards
This commit is contained in:
parent
7286c6dea4
commit
907fe54aab
21
.ameba.yml
21
.ameba.yml
@ -8,6 +8,12 @@ Lint/UselessAssign:
|
|||||||
- src/invidious.cr
|
- src/invidious.cr
|
||||||
- src/invidious/helpers/errors.cr
|
- src/invidious/helpers/errors.cr
|
||||||
- src/invidious/routes/*.cr
|
- src/invidious/routes/*.cr
|
||||||
|
- src/invidious/views/**/**
|
||||||
|
|
||||||
|
# Exclude unused arguments for ECR files
|
||||||
|
Lint/UnusedArgument:
|
||||||
|
Excluded:
|
||||||
|
- src/invidious/views/**/**
|
||||||
|
|
||||||
# Ignore false negative (if !db.query_one?...)
|
# Ignore false negative (if !db.query_one?...)
|
||||||
Lint/UnreachableCode:
|
Lint/UnreachableCode:
|
||||||
@ -27,7 +33,6 @@ Lint/SpecFilename:
|
|||||||
Excluded:
|
Excluded:
|
||||||
- spec/parsers_helper.cr
|
- spec/parsers_helper.cr
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Style
|
# Style
|
||||||
#
|
#
|
||||||
@ -44,6 +49,15 @@ Style/RedundantNext:
|
|||||||
Style/ParenthesesAroundCondition:
|
Style/ParenthesesAroundCondition:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
# Disable this as it's really useful for functions and variables
|
||||||
|
# that belong to a same module, struct or class, and it can be confused
|
||||||
|
# by a global function.
|
||||||
|
# This is subject to change with https://github.com/iv-org/invidious/pull/6046
|
||||||
|
# where there will not be more global variables or functions, well, that's
|
||||||
|
# the goal.
|
||||||
|
Style/RedundantSelf:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
# This requires a rewrite of most data structs (and their usage) in Invidious.
|
# This requires a rewrite of most data structs (and their usage) in Invidious.
|
||||||
Naming/QueryBoolMethods:
|
Naming/QueryBoolMethods:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
@ -56,12 +70,11 @@ Naming/BlockParameterName:
|
|||||||
|
|
||||||
# Hides TODO comment warnings.
|
# Hides TODO comment warnings.
|
||||||
#
|
#
|
||||||
# Call `bin/ameba --only Documentation/DocumentationAdmonition` to
|
# Call `bin/ameba --only Documentation/Admonition` to
|
||||||
# list them
|
# list them
|
||||||
Documentation/DocumentationAdmonition:
|
Documentation/Admonition:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Metrics
|
# Metrics
|
||||||
#
|
#
|
||||||
|
|||||||
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -146,7 +146,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
./lib
|
./lib
|
||||||
./bin
|
|
||||||
key: shards-${{ hashFiles('shard.lock') }}-${{ steps.lint_step_install_crystal.outputs.crystal }}
|
key: shards-${{ hashFiles('shard.lock') }}-${{ steps.lint_step_install_crystal.outputs.crystal }}
|
||||||
|
|
||||||
- name: Install Shards
|
- name: Install Shards
|
||||||
@ -164,4 +163,4 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Run Ameba linter
|
- name: Run Ameba linter
|
||||||
run: bin/ameba
|
uses: crystal-ameba/github-action@v1
|
||||||
|
|||||||
@ -2,7 +2,7 @@ version: 2.0
|
|||||||
shards:
|
shards:
|
||||||
ameba:
|
ameba:
|
||||||
git: https://github.com/crystal-ameba/ameba.git
|
git: https://github.com/crystal-ameba/ameba.git
|
||||||
version: 1.6.4
|
version: 1.7.0
|
||||||
|
|
||||||
athena-negotiation:
|
athena-negotiation:
|
||||||
git: https://github.com/athena-framework/negotiation.git
|
git: https://github.com/athena-framework/negotiation.git
|
||||||
|
|||||||
@ -8,6 +8,8 @@ authors:
|
|||||||
targets:
|
targets:
|
||||||
invidious:
|
invidious:
|
||||||
main: src/invidious.cr
|
main: src/invidious.cr
|
||||||
|
ameba:
|
||||||
|
main: lib/ameba/bin/ameba.cr
|
||||||
|
|
||||||
description: |
|
description: |
|
||||||
Invidious is an alternative front-end to YouTube
|
Invidious is an alternative front-end to YouTube
|
||||||
@ -38,7 +40,7 @@ development_dependencies:
|
|||||||
version: ~> 0.12.4
|
version: ~> 0.12.4
|
||||||
ameba:
|
ameba:
|
||||||
github: crystal-ameba/ameba
|
github: crystal-ameba/ameba
|
||||||
version: ~> 1.6.4
|
version: ~> 1.7.0
|
||||||
|
|
||||||
crystal: ">= 1.14.1, < 2.0.0"
|
crystal: ">= 1.14.1, < 2.0.0"
|
||||||
|
|
||||||
|
|||||||
@ -123,7 +123,7 @@ Kemal.config.extra_options do |parser|
|
|||||||
parser.on("-c THREADS", "--channel-threads=THREADS", "Number of threads for refreshing channels (default: #{CONFIG.channel_threads})") do |number|
|
parser.on("-c THREADS", "--channel-threads=THREADS", "Number of threads for refreshing channels (default: #{CONFIG.channel_threads})") do |number|
|
||||||
begin
|
begin
|
||||||
CONFIG.channel_threads = number.to_i
|
CONFIG.channel_threads = number.to_i
|
||||||
rescue ex
|
rescue
|
||||||
puts "THREADS must be integer"
|
puts "THREADS must be integer"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
@ -131,7 +131,7 @@ Kemal.config.extra_options do |parser|
|
|||||||
parser.on("-f THREADS", "--feed-threads=THREADS", "Number of threads for refreshing feeds (default: #{CONFIG.feed_threads})") do |number|
|
parser.on("-f THREADS", "--feed-threads=THREADS", "Number of threads for refreshing feeds (default: #{CONFIG.feed_threads})") do |number|
|
||||||
begin
|
begin
|
||||||
CONFIG.feed_threads = number.to_i
|
CONFIG.feed_threads = number.to_i
|
||||||
rescue ex
|
rescue
|
||||||
puts "THREADS must be integer"
|
puts "THREADS must be integer"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|||||||
@ -107,7 +107,7 @@ class ChannelRedirect < Exception
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_batch_channels(channels)
|
def get_batch_channels(channels)
|
||||||
finished_channel = Channel(String | Nil).new
|
finished_channel = Channel(String?).new
|
||||||
max_threads = 10
|
max_threads = 10
|
||||||
|
|
||||||
spawn do
|
spawn do
|
||||||
@ -125,7 +125,7 @@ def get_batch_channels(channels)
|
|||||||
begin
|
begin
|
||||||
get_channel(ucid)
|
get_channel(ucid)
|
||||||
finished_channel.send(ucid)
|
finished_channel.send(ucid)
|
||||||
rescue ex
|
rescue
|
||||||
finished_channel.send(nil)
|
finished_channel.send(nil)
|
||||||
ensure
|
ensure
|
||||||
active_channel.send(nil)
|
active_channel.send(nil)
|
||||||
|
|||||||
@ -15,7 +15,7 @@ module Invidious::Comments
|
|||||||
|
|
||||||
if url.host.nil? || url.host.not_nil!.ends_with?("youtube.com") || url.host.not_nil!.ends_with?("youtu.be")
|
if url.host.nil? || url.host.not_nil!.ends_with?("youtube.com") || url.host.not_nil!.ends_with?("youtu.be")
|
||||||
if url.host.try &.ends_with? "youtu.be"
|
if url.host.try &.ends_with? "youtu.be"
|
||||||
url = "/watch?v=#{url.path.lstrip('/')}#{url.query_params}"
|
anchor["href"] = "/watch?v=#{url.path.lstrip('/')}#{url.query_params}"
|
||||||
else
|
else
|
||||||
if url.path == "/redirect"
|
if url.path == "/redirect"
|
||||||
params = HTTP::Params.parse(url.query.not_nil!)
|
params = HTTP::Params.parse(url.query.not_nil!)
|
||||||
@ -27,7 +27,7 @@ module Invidious::Comments
|
|||||||
elsif url.to_s == "#"
|
elsif url.to_s == "#"
|
||||||
begin
|
begin
|
||||||
length_seconds = decode_length_seconds(anchor.content)
|
length_seconds = decode_length_seconds(anchor.content)
|
||||||
rescue ex
|
rescue
|
||||||
length_seconds = decode_time(anchor.content)
|
length_seconds = decode_time(anchor.content)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ module Invidious::Database
|
|||||||
# Create table if it doesn't exist
|
# Create table if it doesn't exist
|
||||||
begin
|
begin
|
||||||
PG_DB.exec("SELECT * FROM #{table_name} LIMIT 0")
|
PG_DB.exec("SELECT * FROM #{table_name} LIMIT 0")
|
||||||
rescue ex
|
rescue
|
||||||
LOGGER.info("check_table: check_table: CREATE TABLE #{table_name}")
|
LOGGER.info("check_table: check_table: CREATE TABLE #{table_name}")
|
||||||
|
|
||||||
PG_DB.using_connection do |conn|
|
PG_DB.using_connection do |conn|
|
||||||
|
|||||||
@ -141,7 +141,6 @@ module Invidious::Frontend::Comments
|
|||||||
<div id="skip-#{child["commentId"]}"></div>
|
<div id="skip-#{child["commentId"]}"></div>
|
||||||
</section>
|
</section>
|
||||||
END_HTML
|
END_HTML
|
||||||
else nil # Ignore
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -68,7 +68,7 @@ class HTTP::Server::Response
|
|||||||
class Output
|
class Output
|
||||||
private def unbuffered_flush
|
private def unbuffered_flush
|
||||||
@io.flush
|
@io.flush
|
||||||
rescue ex : IO::Error
|
rescue IO::Error
|
||||||
unbuffered_close
|
unbuffered_close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -139,7 +139,7 @@ def error_json_helper(
|
|||||||
env : HTTP::Server::Context,
|
env : HTTP::Server::Context,
|
||||||
status_code : Int32,
|
status_code : Int32,
|
||||||
exception : Exception,
|
exception : Exception,
|
||||||
additional_fields : Hash(String, Object) | Nil = nil,
|
additional_fields : Hash(String, Object)? = nil,
|
||||||
)
|
)
|
||||||
if exception.is_a?(InfoException)
|
if exception.is_a?(InfoException)
|
||||||
return error_json_helper(env, status_code, exception.message || "", additional_fields)
|
return error_json_helper(env, status_code, exception.message || "", additional_fields)
|
||||||
@ -161,7 +161,7 @@ def error_json_helper(
|
|||||||
env : HTTP::Server::Context,
|
env : HTTP::Server::Context,
|
||||||
status_code : Int32,
|
status_code : Int32,
|
||||||
message : String,
|
message : String,
|
||||||
additional_fields : Hash(String, Object) | Nil = nil,
|
additional_fields : Hash(String, Object)? = nil,
|
||||||
)
|
)
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
env.response.status_code = status_code
|
env.response.status_code = status_code
|
||||||
|
|||||||
@ -20,7 +20,7 @@ module HTTP::Handler
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Kemal::RouteHandler
|
class Kemal::RouteHandler
|
||||||
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
|
{% for method in %w[GET POST PUT HEAD DELETE PATCH OPTIONS] %}
|
||||||
exclude ["/api/v1/*"], {{ method }}
|
exclude ["/api/v1/*"], {{ method }}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class Kemal::RouteHandler
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Kemal::ExceptionHandler
|
class Kemal::ExceptionHandler
|
||||||
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
|
{% for method in %w[GET POST PUT HEAD DELETE PATCH OPTIONS] %}
|
||||||
exclude ["/api/v1/*"], {{ method }}
|
exclude ["/api/v1/*"], {{ method }}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class FilteredCompressHandler < HTTP::CompressHandler
|
|||||||
end
|
end
|
||||||
|
|
||||||
class AuthHandler < Kemal::Handler
|
class AuthHandler < Kemal::Handler
|
||||||
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
|
{% for method in %w[GET POST PUT HEAD DELETE PATCH OPTIONS] %}
|
||||||
only ["/api/v1/auth/*"], {{ method }}
|
only ["/api/v1/auth/*"], {{ method }}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ class AuthHandler < Kemal::Handler
|
|||||||
end
|
end
|
||||||
|
|
||||||
class APIHandler < Kemal::Handler
|
class APIHandler < Kemal::Handler
|
||||||
{% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %}
|
{% for method in %w[GET POST PUT HEAD DELETE PATCH OPTIONS] %}
|
||||||
only ["/api/v1/*"], {{ method }}
|
only ["/api/v1/*"], {{ method }}
|
||||||
{% end %}
|
{% end %}
|
||||||
exclude ["/api/v1/auth/notifications"], "GET"
|
exclude ["/api/v1/auth/notifications"], "GET"
|
||||||
@ -134,9 +134,9 @@ class APIHandler < Kemal::Handler
|
|||||||
end
|
end
|
||||||
|
|
||||||
class DisableAbusableAPIHandler < Kemal::Handler
|
class DisableAbusableAPIHandler < Kemal::Handler
|
||||||
{% for method in %w(GET HEAD) %}
|
{% for method in %w[GET HEAD] %}
|
||||||
# This endpoints make a video request to Invidious companion.
|
# This endpoints make a video request to Invidious companion.
|
||||||
{% for endpoint in %w(videos clips transcripts) %}
|
{% for endpoint in %w[videos clips transcripts] %}
|
||||||
only ["/api/v1/{{ endpoint.id }}/:id"], {{ method }}
|
only ["/api/v1/{{ endpoint.id }}/:id"], {{ method }}
|
||||||
{% end %}
|
{% end %}
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|||||||
@ -93,7 +93,7 @@ module Helpers
|
|||||||
sleep 1.minute
|
sleep 1.minute
|
||||||
Fiber.yield
|
Fiber.yield
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -149,7 +149,7 @@ module Helpers
|
|||||||
|
|
||||||
id += 1
|
id += 1
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
ensure
|
ensure
|
||||||
connection_channel.send({false, connection})
|
connection_channel.send({false, connection})
|
||||||
end
|
end
|
||||||
@ -163,7 +163,7 @@ module Helpers
|
|||||||
env.response.flush
|
env.response.flush
|
||||||
sleep (20 + rand(11)).seconds
|
sleep (20 + rand(11)).seconds
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
ensure
|
ensure
|
||||||
connection_channel.send({false, connection})
|
connection_channel.send({false, connection})
|
||||||
end
|
end
|
||||||
|
|||||||
@ -103,7 +103,7 @@ module I18n
|
|||||||
return locales
|
return locales
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate(locale : String?, key : String, text : String | Hash(String, String) | Nil = nil) : String
|
def translate(locale : String?, key : String, text : String? | Hash(String, String)? = nil) : String
|
||||||
# Log a warning if "key" doesn't exist in en-US locale and return
|
# Log a warning if "key" doesn't exist in en-US locale and return
|
||||||
# that key as the text, so this is more or less transparent to the user.
|
# that key as the text, so this is more or less transparent to the user.
|
||||||
if !LOCALES["en-US"].has_key?(key)
|
if !LOCALES["en-US"].has_key?(key)
|
||||||
|
|||||||
@ -55,7 +55,7 @@ class Invidious::LogHandler < Kemal::BaseLogHandler
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
{% for level in %w(trace debug info warn error fatal) %}
|
{% for level in %w[trace debug info warn error fatal] %}
|
||||||
def {{ level.id }}(message : String)
|
def {{ level.id }}(message : String)
|
||||||
if LogLevel::{{ level.id.capitalize }} >= @level
|
if LogLevel::{{ level.id.capitalize }} >= @level
|
||||||
puts("#{Time.utc} [{{ level.id }}] #{message}".colorize(color(LogLevel::{{ level.id.capitalize }})))
|
puts("#{Time.utc} [{{ level.id }}] #{message}".colorize(color(LogLevel::{{ level.id.capitalize }})))
|
||||||
|
|||||||
@ -116,7 +116,7 @@ def scope_includes_scope(scope, subset)
|
|||||||
subset_endpoint = subset_endpoint.downcase
|
subset_endpoint = subset_endpoint.downcase
|
||||||
|
|
||||||
if methods.empty?
|
if methods.empty?
|
||||||
methods = %w(GET POST PUT HEAD DELETE PATCH OPTIONS)
|
methods = %w[GET POST PUT HEAD DELETE PATCH OPTIONS]
|
||||||
end
|
end
|
||||||
|
|
||||||
if methods & subset_methods != subset_methods
|
if methods & subset_methods != subset_methods
|
||||||
|
|||||||
@ -102,7 +102,7 @@ def decode_date(string : String)
|
|||||||
# Try to parse as format Jul 10, 2000
|
# Try to parse as format Jul 10, 2000
|
||||||
begin
|
begin
|
||||||
return Time.parse(string, "%b %-d, %Y", Time::Location.local)
|
return Time.parse(string, "%b %-d, %Y", Time::Location.local)
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
|
|
||||||
case string
|
case string
|
||||||
@ -110,7 +110,6 @@ def decode_date(string : String)
|
|||||||
return Time.utc
|
return Time.utc
|
||||||
when "yesterday"
|
when "yesterday"
|
||||||
return Time.utc - 1.day
|
return Time.utc - 1.day
|
||||||
else nil # Continue
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# String matches format "20 hours ago", "4 months ago", "20s ago", "15min ago"...
|
# String matches format "20 hours ago", "4 months ago", "20s ago", "15min ago"...
|
||||||
@ -177,7 +176,7 @@ def short_text_to_number(short_text : String) : Int64
|
|||||||
end
|
end
|
||||||
|
|
||||||
return number.to_i64
|
return number.to_i64
|
||||||
rescue ex
|
rescue
|
||||||
return 0_i64
|
return 0_i64
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,7 @@ class Invidious::Jobs::InstanceListRefreshJob < Invidious::Jobs::BaseJob
|
|||||||
|
|
||||||
raw_instance_list = JSON.parse(instance_api_client.get("/instances.json").body).as_a
|
raw_instance_list = JSON.parse(instance_api_client.get("/instances.json").body).as_a
|
||||||
instance_api_client.close
|
instance_api_client.close
|
||||||
rescue ex : Socket::ConnectError | IO::TimeoutError | JSON::ParseException
|
rescue Socket::ConnectError | IO::TimeoutError | JSON::ParseException
|
||||||
raw_instance_list = [] of JSON::Any
|
raw_instance_list = [] of JSON::Any
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -138,7 +138,7 @@ module Invidious::JSONify::APIv1
|
|||||||
|
|
||||||
if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"])
|
if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"])
|
||||||
json.field "container", fmt_info["ext"]
|
json.field "container", fmt_info["ext"]
|
||||||
json.field "encoding", fmt_info["vcodec"]? || fmt_info["acodec"]
|
json.field("encoding", fmt_info["vcodec"]? || fmt_info["acodec"])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Livestream chunk infos
|
# Livestream chunk infos
|
||||||
@ -198,8 +198,8 @@ module Invidious::JSONify::APIv1
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"])
|
if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"])
|
||||||
json.field "container", fmt_info["ext"]
|
json.field("container", fmt_info["ext"])
|
||||||
json.field "encoding", fmt_info["vcodec"]? || fmt_info["acodec"]
|
json.field("encoding", fmt_info["vcodec"]? || fmt_info["acodec"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -500,10 +500,10 @@ def extract_playlist_videos(playlist_id : String, initial_data : Hash(String, JS
|
|||||||
|
|
||||||
# Find the metadataParts with commandRuns inside, which contains author
|
# Find the metadataParts with commandRuns inside, which contains author
|
||||||
# information.
|
# information.
|
||||||
metadata_parts = metadata_rows.try &.find { |row|
|
metadata_parts = metadata_rows.try &.find do |row|
|
||||||
parts = row["metadataParts"]?.try &.as_a
|
parts = row["metadataParts"]?.try &.as_a
|
||||||
parts && parts.any? { |item2| item2.dig?("text", "commandRuns").try &.as_a }
|
parts && parts.any? { |item2| item2.dig?("text", "commandRuns").try &.as_a }
|
||||||
}.try &.["metadataParts"].as_a
|
end.try &.["metadataParts"].as_a
|
||||||
|
|
||||||
if author_info = metadata_parts.try &.find(&.dig?("text", "commandRuns"))
|
if author_info = metadata_parts.try &.find(&.dig?("text", "commandRuns"))
|
||||||
.try &.["text"]
|
.try &.["text"]
|
||||||
|
|||||||
@ -19,9 +19,9 @@ module Invidious::Routes::API::Manifest
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : NotFoundException
|
rescue NotFoundException
|
||||||
haltf env, status_code: 404
|
haltf env, status_code: 404
|
||||||
rescue ex
|
rescue
|
||||||
haltf env, status_code: 403
|
haltf env, status_code: 403
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -42,10 +42,10 @@ module Invidious::Routes::API::V1::Authenticated
|
|||||||
user = env.get("user").as(User)
|
user = env.get("user").as(User)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if body = env.request.body
|
body = if raw_body = env.request.body
|
||||||
body = env.request.body.not_nil!.gets_to_end
|
raw_body.gets_to_end
|
||||||
else
|
else
|
||||||
body = "{}"
|
"{}"
|
||||||
end
|
end
|
||||||
Invidious::User::Import.from_invidious(user, body)
|
Invidious::User::Import.from_invidious(user, body)
|
||||||
rescue
|
rescue
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
||||||
videos = get_playlist_videos(playlist, offset: 0)
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
videos = [] of PlaylistVideo
|
videos = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -118,7 +118,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
# Fetch related channels
|
# Fetch related channels
|
||||||
begin
|
begin
|
||||||
related_channels, _ = fetch_related_channels(channel)
|
related_channels, _ = fetch_related_channels(channel)
|
||||||
rescue ex
|
rescue
|
||||||
related_channels = [] of SearchChannel
|
related_channels = [] of SearchChannel
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
||||||
videos = get_playlist_videos(playlist, offset: 0)
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
videos = [] of PlaylistVideo
|
videos = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -203,7 +203,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UUSH"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UUSH"))
|
||||||
videos = get_playlist_videos(playlist, offset: 0)
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
videos = [] of PlaylistVideo
|
videos = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -249,7 +249,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UULV"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UULV"))
|
||||||
videos = get_playlist_videos(playlist, offset: 0)
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
videos = [] of PlaylistVideo
|
videos = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
|
|||||||
@ -53,7 +53,7 @@ module Invidious::Routes::API::V1::Misc
|
|||||||
playlist = get_playlist(plid)
|
playlist = get_playlist(plid)
|
||||||
rescue ex : InfoException
|
rescue ex : InfoException
|
||||||
return error_json(404, ex)
|
return error_json(404, ex)
|
||||||
rescue ex
|
rescue
|
||||||
return error_json(404, "Playlist does not exist.")
|
return error_json(404, "Playlist does not exist.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -47,9 +47,9 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : NotFoundException
|
rescue NotFoundException
|
||||||
haltf env, 404
|
haltf env, 404
|
||||||
rescue ex
|
rescue
|
||||||
haltf env, 500
|
haltf env, 500
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -187,9 +187,9 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : NotFoundException
|
rescue NotFoundException
|
||||||
haltf env, 404
|
haltf env, 404
|
||||||
rescue ex
|
rescue
|
||||||
haltf env, 500
|
haltf env, 500
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -265,8 +265,6 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
haltf env, 400
|
haltf env, 400
|
||||||
end
|
end
|
||||||
|
|
||||||
annotations = ""
|
|
||||||
|
|
||||||
case source
|
case source
|
||||||
when "archive"
|
when "archive"
|
||||||
if CONFIG.cache_annotations && (cached_annotation = Invidious::Database::Annotations.select(video_id))
|
if CONFIG.cache_annotations && (cached_annotation = Invidious::Database::Annotations.select(video_id))
|
||||||
@ -365,7 +363,7 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
comments, reddit_thread = Comments.fetch_reddit(id, sort_by: sort_by)
|
comments, reddit_thread = Comments.fetch_reddit(id, sort_by: sort_by)
|
||||||
rescue ex
|
rescue
|
||||||
comments = nil
|
comments = nil
|
||||||
reddit_thread = nil
|
reddit_thread = nil
|
||||||
end
|
end
|
||||||
|
|||||||
@ -44,7 +44,7 @@ module Invidious::Routes::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
||||||
items = get_playlist_videos(playlist, offset: 0)
|
items = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
items = [] of PlaylistVideo
|
items = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -79,7 +79,7 @@ module Invidious::Routes::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UUSH"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UUSH"))
|
||||||
items = get_playlist_videos(playlist, offset: 0)
|
items = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
items = [] of PlaylistVideo
|
items = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -114,7 +114,7 @@ module Invidious::Routes::Channels
|
|||||||
begin
|
begin
|
||||||
playlist = get_playlist(channel.ucid.sub("UC", "UULV"))
|
playlist = get_playlist(channel.ucid.sub("UC", "UULV"))
|
||||||
items = get_playlist_videos(playlist, offset: 0)
|
items = get_playlist_videos(playlist, offset: 0)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
# playlist doesnt exist.
|
# playlist doesnt exist.
|
||||||
items = [] of PlaylistVideo
|
items = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
@ -353,7 +353,7 @@ module Invidious::Routes::Channels
|
|||||||
begin
|
begin
|
||||||
resolved_url = YoutubeAPI.resolve_url("https://www.youtube.com#{env.request.path}#{yt_url_params.size > 0 ? "?#{yt_url_params}" : ""}")
|
resolved_url = YoutubeAPI.resolve_url("https://www.youtube.com#{env.request.path}#{yt_url_params.size > 0 ? "?#{yt_url_params}" : ""}")
|
||||||
ucid = resolved_url["endpoint"]["browseEndpoint"]["browseId"]
|
ucid = resolved_url["endpoint"]["browseEndpoint"]["browseId"]
|
||||||
rescue ex : InfoException | KeyError
|
rescue InfoException | KeyError
|
||||||
return error_template(404, I18n.translate(locale, "This channel does not exist."))
|
return error_template(404, I18n.translate(locale, "This channel does not exist."))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ module Invidious::Routes::Companion
|
|||||||
return self.proxy_companion(env, resp)
|
return self.proxy_companion(env, resp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ module Invidious::Routes::Companion
|
|||||||
return self.proxy_companion(env, resp)
|
return self.proxy_companion(env, resp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ module Invidious::Routes::Companion
|
|||||||
return self.proxy_companion(env, resp)
|
return self.proxy_companion(env, resp)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -119,7 +119,6 @@ module Invidious::Routes::Embed
|
|||||||
end
|
end
|
||||||
|
|
||||||
return env.redirect url
|
return env.redirect url
|
||||||
else nil # Continue
|
|
||||||
end
|
end
|
||||||
|
|
||||||
params = Invidious::Videos.process_video_params(env.params.query, preferences)
|
params = Invidious::Videos.process_video_params(env.params.query, preferences)
|
||||||
@ -182,14 +181,14 @@ module Invidious::Routes::Embed
|
|||||||
|
|
||||||
captions = video.captions
|
captions = video.captions
|
||||||
|
|
||||||
preferred_captions = captions.select { |caption|
|
preferred_captions = captions.select do |caption|
|
||||||
params.preferred_captions.includes?(caption.name) ||
|
params.preferred_captions.includes?(caption.name) ||
|
||||||
params.preferred_captions.includes?(caption.language_code.split("-")[0])
|
params.preferred_captions.includes?(caption.language_code.split("-")[0])
|
||||||
}
|
end
|
||||||
preferred_captions.sort_by! { |caption|
|
preferred_captions.sort_by! do |caption|
|
||||||
(params.preferred_captions.index(caption.name) ||
|
(params.preferred_captions.index(caption.name) ||
|
||||||
params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil!
|
params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil!
|
||||||
}
|
end
|
||||||
captions = captions - preferred_captions
|
captions = captions - preferred_captions
|
||||||
|
|
||||||
aspect_ratio = nil
|
aspect_ratio = nil
|
||||||
|
|||||||
@ -327,7 +327,6 @@ module Invidious::Routes::Feeds
|
|||||||
request_target = URI.parse(node[attribute.name]).request_target
|
request_target = URI.parse(node[attribute.name]).request_target
|
||||||
query_string_opt = request_target.starts_with?("/watch?v=") ? ("&#{params}" if !params.empty?) : ""
|
query_string_opt = request_target.starts_with?("/watch?v=") ? ("&#{params}" if !params.empty?) : ""
|
||||||
node[attribute.name] = "#{HOST_URL}#{request_target}#{query_string_opt}"
|
node[attribute.name] = "#{HOST_URL}#{request_target}#{query_string_opt}"
|
||||||
else nil # Skip
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -15,7 +15,7 @@ module Invidious::Routes::Images
|
|||||||
GGPHT_POOL.client &.get(url, headers) do |resp|
|
GGPHT_POOL.client &.get(url, headers) do |resp|
|
||||||
return self.proxy_image(env, resp)
|
return self.proxy_image(env, resp)
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ module Invidious::Routes::Images
|
|||||||
env.response.headers["Connection"] = "close"
|
env.response.headers["Connection"] = "close"
|
||||||
return self.proxy_image(env, resp)
|
return self.proxy_image(env, resp)
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ module Invidious::Routes::Images
|
|||||||
get_ytimg_pool(authority).client &.get(url, headers) do |resp|
|
get_ytimg_pool(authority).client &.get(url, headers) do |resp|
|
||||||
return self.proxy_image(env, resp)
|
return self.proxy_image(env, resp)
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ module Invidious::Routes::Images
|
|||||||
|
|
||||||
Helpers.proxy_file(response, env)
|
Helpers.proxy_file(response, env)
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ module Invidious::Routes::Images
|
|||||||
get_ytimg_pool("i").client &.get(url, headers) do |resp|
|
get_ytimg_pool("i").client &.get(url, headers) do |resp|
|
||||||
return self.proxy_image(env, resp)
|
return self.proxy_image(env, resp)
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -103,7 +103,7 @@ module Invidious::Routes::Login
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
validate_request(tokens[0], answer, env.request, HMAC_KEY, locale)
|
validate_request(tokens[0], answer, env.request, HMAC_KEY, locale)
|
||||||
rescue ex : InfoException
|
rescue InfoException
|
||||||
return error_template(400, InfoException.new("Erroneous CAPTCHA"))
|
return error_template(400, InfoException.new("Erroneous CAPTCHA"))
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_template(400, ex)
|
return error_template(400, ex)
|
||||||
|
|||||||
@ -164,7 +164,7 @@ module Invidious::Routes::Playlists
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
items = get_playlist_videos(playlist, offset: (page - 1) * 100)
|
items = get_playlist_videos(playlist, offset: (page - 1) * 100)
|
||||||
rescue ex
|
rescue
|
||||||
items = [] of PlaylistVideo
|
items = [] of PlaylistVideo
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ module Invidious::Routes::Playlists
|
|||||||
begin
|
begin
|
||||||
query = Invidious::Search::Query.new(env.params.query, :playlist, region)
|
query = Invidious::Search::Query.new(env.params.query, :playlist, region)
|
||||||
items = query.process.select(SearchVideo).map(&.as(SearchVideo))
|
items = query.process.select(SearchVideo).map(&.as(SearchVideo))
|
||||||
rescue ex
|
rescue
|
||||||
items = [] of SearchVideo
|
items = [] of SearchVideo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -362,7 +362,6 @@ module Invidious::Routes::PreferencesRoute
|
|||||||
response: error_template(415, "Uploaded file is too large")
|
response: error_template(415, "Uploaded file is too large")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else nil # Ignore
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -115,7 +115,7 @@ module Invidious::Routes::VideoPlayback
|
|||||||
|
|
||||||
IO.copy(resp.body_io, env.response)
|
IO.copy(resp.body_io, env.response)
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if query_params["title"]? && CONFIG.disabled?("downloads") ||
|
if query_params["title"]? && CONFIG.disabled?("downloads") ||
|
||||||
|
|||||||
@ -82,7 +82,7 @@ module Invidious::Routes::Watch
|
|||||||
if source == "youtube"
|
if source == "youtube"
|
||||||
begin
|
begin
|
||||||
comment_html = JSON.parse(Comments.fetch_youtube(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
|
comment_html = JSON.parse(Comments.fetch_youtube(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
|
||||||
rescue ex
|
rescue
|
||||||
if preferences.comments[1] == "reddit"
|
if preferences.comments[1] == "reddit"
|
||||||
comments, reddit_thread = Comments.fetch_reddit(id)
|
comments, reddit_thread = Comments.fetch_reddit(id)
|
||||||
comment_html = Frontend::Comments.template_reddit(comments, locale)
|
comment_html = Frontend::Comments.template_reddit(comments, locale)
|
||||||
@ -98,7 +98,7 @@ module Invidious::Routes::Watch
|
|||||||
|
|
||||||
comment_html = Comments.fill_links(comment_html, "https", "www.reddit.com")
|
comment_html = Comments.fill_links(comment_html, "https", "www.reddit.com")
|
||||||
comment_html = Comments.replace_links(comment_html)
|
comment_html = Comments.replace_links(comment_html)
|
||||||
rescue ex
|
rescue
|
||||||
if preferences.comments[1] == "youtube"
|
if preferences.comments[1] == "youtube"
|
||||||
comment_html = JSON.parse(Comments.fetch_youtube(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
|
comment_html = JSON.parse(Comments.fetch_youtube(id, nil, "html", locale, preferences.thin_mode, region))["contentHtml"]
|
||||||
end
|
end
|
||||||
@ -143,14 +143,14 @@ module Invidious::Routes::Watch
|
|||||||
|
|
||||||
captions = video.captions
|
captions = video.captions
|
||||||
|
|
||||||
preferred_captions = captions.select { |caption|
|
preferred_captions = captions.select do |caption|
|
||||||
params.preferred_captions.includes?(caption.name) ||
|
params.preferred_captions.includes?(caption.name) ||
|
||||||
params.preferred_captions.includes?(caption.language_code.split("-")[0])
|
params.preferred_captions.includes?(caption.language_code.split("-")[0])
|
||||||
}
|
end
|
||||||
preferred_captions.sort_by! { |caption|
|
preferred_captions.sort_by! do |caption|
|
||||||
(params.preferred_captions.index(caption.name) ||
|
(params.preferred_captions.index(caption.name) ||
|
||||||
params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil!
|
params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil!
|
||||||
}
|
end
|
||||||
captions = captions - preferred_captions
|
captions = captions - preferred_captions
|
||||||
|
|
||||||
aspect_ratio = "16:9"
|
aspect_ratio = "16:9"
|
||||||
|
|||||||
@ -39,7 +39,7 @@ module Invidious::Search
|
|||||||
def subscriptions(query : Query, user : Invidious::User) : Array(ChannelVideo)
|
def subscriptions(query : Query, user : Invidious::User) : Array(ChannelVideo)
|
||||||
view_name = "subscriptions_#{sha256(user.email)}"
|
view_name = "subscriptions_#{sha256(user.email)}"
|
||||||
|
|
||||||
return PG_DB.query_all("
|
return PG_DB.query_all(<<-SQL,
|
||||||
SELECT id,title,published,updated,ucid,author,length_seconds
|
SELECT id,title,published,updated,ucid,author,length_seconds
|
||||||
FROM (
|
FROM (
|
||||||
SELECT *,
|
SELECT *,
|
||||||
@ -47,7 +47,8 @@ module Invidious::Search
|
|||||||
to_tsvector(#{view_name}.author)
|
to_tsvector(#{view_name}.author)
|
||||||
as document
|
as document
|
||||||
FROM #{view_name}
|
FROM #{view_name}
|
||||||
) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;",
|
) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;
|
||||||
|
SQL
|
||||||
query.text, (query.page - 1) * 20,
|
query.text, (query.page - 1) * 20,
|
||||||
as: ChannelVideo
|
as: ChannelVideo
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2,10 +2,10 @@ def fetch_trending(trending_type, region, locale)
|
|||||||
region ||= "US"
|
region ||= "US"
|
||||||
region = region.upcase
|
region = region.upcase
|
||||||
|
|
||||||
|
# 2026-10-12: plid is only used in line 47
|
||||||
|
# so we can remove this later.
|
||||||
plid = nil
|
plid = nil
|
||||||
|
|
||||||
browse_id = ""
|
|
||||||
|
|
||||||
case trending_type.try &.downcase
|
case trending_type.try &.downcase
|
||||||
when "gaming"
|
when "gaming"
|
||||||
browse_id = "UCOpNcN46UbXVtpKMrmU4Abg"
|
browse_id = "UCOpNcN46UbXVtpKMrmU4Abg"
|
||||||
|
|||||||
@ -56,7 +56,7 @@ struct Invidious::User
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id)
|
video = get_video(video_id)
|
||||||
rescue ex
|
rescue
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ struct Invidious::User
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id, false)
|
video = get_video(video_id, false)
|
||||||
rescue ex
|
rescue
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ struct Preferences
|
|||||||
else
|
else
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
if value.read_bool
|
if value.read_bool
|
||||||
"dark"
|
"dark"
|
||||||
else
|
else
|
||||||
@ -199,7 +199,7 @@ struct Preferences
|
|||||||
value.read_array do
|
value.read_array do
|
||||||
result << HTML.escape(value.read_string[0, 100])
|
result << HTML.escape(value.read_string[0, 100])
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
result = [HTML.escape(value.read_string[0, 100]), ""]
|
result = [HTML.escape(value.read_string[0, 100]), ""]
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ struct Preferences
|
|||||||
|
|
||||||
result << HTML.escape(item.value[0, 100])
|
result << HTML.escape(item.value[0, 100])
|
||||||
end
|
end
|
||||||
rescue ex
|
rescue
|
||||||
if node.is_a?(YAML::Nodes::Scalar)
|
if node.is_a?(YAML::Nodes::Scalar)
|
||||||
result = [HTML.escape(node.value[0, 100]), ""]
|
result = [HTML.escape(node.value[0, 100]), ""]
|
||||||
else
|
else
|
||||||
|
|||||||
@ -19,7 +19,7 @@ struct Invidious::User
|
|||||||
def self.from_rs(rs)
|
def self.from_rs(rs)
|
||||||
begin
|
begin
|
||||||
Preferences.from_json(rs.read(String))
|
Preferences.from_json(rs.read(String))
|
||||||
rescue ex
|
rescue
|
||||||
Preferences.from_json("{}")
|
Preferences.from_json("{}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -45,7 +45,6 @@ def get_subscription_feed(user, max_results = 40, page = 1)
|
|||||||
notifications.sort_by!(&.author)
|
notifications.sort_by!(&.author)
|
||||||
when "channel name - reverse"
|
when "channel name - reverse"
|
||||||
notifications.sort_by!(&.author).reverse!
|
notifications.sort_by!(&.author).reverse!
|
||||||
else nil # Ignore
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if user.preferences.latest_only
|
if user.preferences.latest_only
|
||||||
@ -94,7 +93,6 @@ def get_subscription_feed(user, max_results = 40, page = 1)
|
|||||||
videos.sort_by!(&.author)
|
videos.sort_by!(&.author)
|
||||||
when "channel name - reverse"
|
when "channel name - reverse"
|
||||||
videos.sort_by!(&.author).reverse!
|
videos.sort_by!(&.author).reverse!
|
||||||
else nil # Ignore
|
|
||||||
end
|
end
|
||||||
|
|
||||||
notifications = Invidious::Database::Users.select_notifications(user)
|
notifications = Invidious::Database::Users.select_notifications(user)
|
||||||
|
|||||||
@ -48,7 +48,7 @@ struct Video
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(json : JSON::Builder | Nil = nil)
|
def to_json(json : JSON::Builder? = nil)
|
||||||
to_json(nil, json)
|
to_json(nil, json)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ struct Video
|
|||||||
|
|
||||||
def dash_manifest_url : String?
|
def dash_manifest_url : String?
|
||||||
raw_dash_url = info.dig?("streamingData", "dashManifestUrl").try &.as_s
|
raw_dash_url = info.dig?("streamingData", "dashManifestUrl").try &.as_s
|
||||||
return nil if raw_dash_url.nil?
|
return if raw_dash_url.nil?
|
||||||
|
|
||||||
# Use manifest v5 parameter to reduce file size
|
# Use manifest v5 parameter to reduce file size
|
||||||
# See https://github.com/iv-org/invidious/issues/4186
|
# See https://github.com/iv-org/invidious/issues/4186
|
||||||
@ -183,14 +183,14 @@ struct Video
|
|||||||
end
|
end
|
||||||
|
|
||||||
def music : Array(VideoMusic)
|
def music : Array(VideoMusic)
|
||||||
info["music"].as_a.map { |music_json|
|
info["music"].as_a.map do |music_json|
|
||||||
VideoMusic.new(
|
VideoMusic.new(
|
||||||
music_json["song"].as_s,
|
music_json["song"].as_s,
|
||||||
music_json["album"].as_s,
|
music_json["album"].as_s,
|
||||||
music_json["artist"].as_s,
|
music_json["artist"].as_s,
|
||||||
music_json["license"].as_s
|
music_json["license"].as_s
|
||||||
)
|
)
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if comments are enabled on the video
|
# Returns true if comments are enabled on the video
|
||||||
|
|||||||
@ -10,7 +10,7 @@ module Invidious::Videos::Parser
|
|||||||
# TODO: "compactRadioRenderer" (Mix) and
|
# TODO: "compactRadioRenderer" (Mix) and
|
||||||
# TODO: Use a proper struct/class instead of a hacky JSON object
|
# TODO: Use a proper struct/class instead of a hacky JSON object
|
||||||
def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
|
def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
|
||||||
return nil if !related["videoId"]?
|
return if !related["videoId"]?
|
||||||
|
|
||||||
# The compact renderer has video length in seconds, where the end
|
# The compact renderer has video length in seconds, where the end
|
||||||
# screen rendered has a full text version ("42:40")
|
# screen rendered has a full text version ("42:40")
|
||||||
@ -60,7 +60,7 @@ module Invidious::Videos::Parser
|
|||||||
player_response = YoutubeAPI.player(video_id: video_id)
|
player_response = YoutubeAPI.player(video_id: video_id)
|
||||||
|
|
||||||
if player_response.nil?
|
if player_response.nil?
|
||||||
return nil
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s
|
playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s
|
||||||
@ -150,7 +150,7 @@ module Invidious::Videos::Parser
|
|||||||
elsif playability_status == "OK"
|
elsif playability_status == "OK"
|
||||||
return response
|
return response
|
||||||
else
|
else
|
||||||
return nil
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -25,8 +25,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if captcha %>
|
<% if captcha %>
|
||||||
<% captcha = captcha.not_nil! %>
|
<img src='<%= captcha[:question] %>' style="width:50%"/>
|
||||||
<img style="width:50%" src='<%= captcha[:question] %>'/>
|
|
||||||
<% captcha[:tokens].each_with_index do |token, i| %>
|
<% captcha[:tokens].each_with_index do |token, i| %>
|
||||||
<input type="hidden" name="token[<%= i %>]" value="<%= HTML.escape(token) %>">
|
<input type="hidden" name="token[<%= i %>]" value="<%= HTML.escape(token) %>">
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -20,7 +20,7 @@ struct YoutubeConnectionPool
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
response = yield conn
|
response = yield conn
|
||||||
rescue ex
|
rescue
|
||||||
conn.close
|
conn.close
|
||||||
conn = make_client(url, force_resolve: true)
|
conn = make_client(url, force_resolve: true)
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ struct CompanionConnectionPool
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
response = yield wrapper
|
response = yield wrapper
|
||||||
rescue ex
|
rescue
|
||||||
wrapper.close
|
wrapper.close
|
||||||
|
|
||||||
companion = CONFIG.invidious_companion.sample
|
companion = CONFIG.invidious_companion.sample
|
||||||
|
|||||||
@ -152,7 +152,6 @@ private module Parsers
|
|||||||
when "Premium"
|
when "Premium"
|
||||||
# TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"]
|
# TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"]
|
||||||
badges |= VideoBadges::Premium
|
badges |= VideoBadges::Premium
|
||||||
else nil # Ignore
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -655,6 +654,10 @@ private module Parsers
|
|||||||
thumbnail_view_model = item_contents.dig(
|
thumbnail_view_model = item_contents.dig(
|
||||||
"contentImage", "thumbnailViewModel"
|
"contentImage", "thumbnailViewModel"
|
||||||
)
|
)
|
||||||
|
# TODO: This is an useless assignment, is not used anywhere
|
||||||
|
# so check if it can be used somewhere later.
|
||||||
|
#
|
||||||
|
# ameba:disable Lint/UselessAssign
|
||||||
thumbnail = thumbnail_view_model.dig("image", "sources", 0, "url").as_s
|
thumbnail = thumbnail_view_model.dig("image", "sources", 0, "url").as_s
|
||||||
|
|
||||||
video_id = item_contents["contentId"].as_s
|
video_id = item_contents["contentId"].as_s
|
||||||
@ -739,9 +742,9 @@ private module Parsers
|
|||||||
video_count = thumbnail_view_model.dig("overlays").as_a
|
video_count = thumbnail_view_model.dig("overlays").as_a
|
||||||
.compact_map(&.dig?("thumbnailOverlayBadgeViewModel", "thumbnailBadges").try &.as_a)
|
.compact_map(&.dig?("thumbnailOverlayBadgeViewModel", "thumbnailBadges").try &.as_a)
|
||||||
.flatten
|
.flatten
|
||||||
.find(nil, &.dig?("thumbnailBadgeViewModel", "text").try { |node|
|
.find(nil, &.dig?("thumbnailBadgeViewModel", "text").try do |node|
|
||||||
{"episodes", "videos", "lessons"}.any? { |str| node.as_s.ends_with?(str) }
|
{"episodes", "videos", "lessons"}.any? { |str| node.as_s.ends_with?(str) }
|
||||||
})
|
end)
|
||||||
.try &.dig("thumbnailBadgeViewModel", "text").as_s.to_i(strict: false)
|
.try &.dig("thumbnailBadgeViewModel", "text").as_s.to_i(strict: false)
|
||||||
|
|
||||||
metadata = item_contents.dig("metadata", "lockupMetadataViewModel")
|
metadata = item_contents.dig("metadata", "lockupMetadataViewModel")
|
||||||
@ -790,10 +793,10 @@ private module Parsers
|
|||||||
# ]
|
# ]
|
||||||
#
|
#
|
||||||
metadata_rows = metadata.dig?("metadata", "contentMetadataViewModel", "metadataRows").try &.as_a
|
metadata_rows = metadata.dig?("metadata", "contentMetadataViewModel", "metadataRows").try &.as_a
|
||||||
metadata_parts = metadata_rows.try &.find { |row|
|
metadata_parts = metadata_rows.try &.find do |row|
|
||||||
parts = row["metadataParts"]?.try &.as_a
|
parts = row["metadataParts"]?.try &.as_a
|
||||||
parts && !parts.any? { |item| item.dig?("text", "content").try &.as_s == "View full playlist" }
|
parts && !parts.any? { |item| item.dig?("text", "content").try &.as_s == "View full playlist" }
|
||||||
}.try &.["metadataParts"].as_a
|
end.try &.["metadataParts"].as_a
|
||||||
|
|
||||||
if author_info = metadata_parts.try &.find(&.dig?("text", "commandRuns"))
|
if author_info = metadata_parts.try &.find(&.dig?("text", "commandRuns"))
|
||||||
.try &.["text"]
|
.try &.["text"]
|
||||||
|
|||||||
@ -17,15 +17,13 @@
|
|||||||
# another nil will be returned.
|
# another nil will be returned.
|
||||||
def extract_text(item : JSON::Any?) : String?
|
def extract_text(item : JSON::Any?) : String?
|
||||||
if item.nil?
|
if item.nil?
|
||||||
return nil
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if text_container = item["simpleText"]?
|
if text_container = item["simpleText"]?
|
||||||
return text_container.as_s
|
return text_container.as_s
|
||||||
elsif text_container = item["runs"]?
|
elsif text_container = item["runs"]?
|
||||||
return text_container.as_a.map(&.["text"].as_s).join("")
|
return text_container.as_a.map(&.["text"].as_s).join("")
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ module UrlSanitizer
|
|||||||
when "results", "search"
|
when "results", "search"
|
||||||
return :search
|
return :search
|
||||||
else # hashtag, post, trending, brand URLs, etc..
|
else # hashtag, post, trending, brand URLs, etc..
|
||||||
return nil
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -210,7 +210,7 @@ module YoutubeAPI
|
|||||||
|
|
||||||
# Region to provide to youtube, e.g to alter search results
|
# Region to provide to youtube, e.g to alter search results
|
||||||
# (this is passed as the `gl` parameter).
|
# (this is passed as the `gl` parameter).
|
||||||
property region : String | Nil
|
property region : String?
|
||||||
|
|
||||||
# Initialization function
|
# Initialization function
|
||||||
def initialize(
|
def initialize(
|
||||||
@ -286,7 +286,7 @@ module YoutubeAPI
|
|||||||
# Return, as a Hash, the "context" data required to request the
|
# Return, as a Hash, the "context" data required to request the
|
||||||
# youtube API endpoints.
|
# youtube API endpoints.
|
||||||
#
|
#
|
||||||
private def make_context(client_config : ClientConfig | Nil, video_id = "dQw4w9WgXcQ") : Hash
|
private def make_context(client_config : ClientConfig?, video_id = "dQw4w9WgXcQ") : Hash
|
||||||
# Use the default client config if nil is passed
|
# Use the default client config if nil is passed
|
||||||
client_config ||= DEFAULT_CLIENT_CONFIG
|
client_config ||= DEFAULT_CLIENT_CONFIG
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ module YoutubeAPI
|
|||||||
#
|
#
|
||||||
# - A playlist ID (parameters MUST be an empty string)
|
# - A playlist ID (parameters MUST be an empty string)
|
||||||
#
|
#
|
||||||
def browse(continuation : String, client_config : ClientConfig | Nil = nil)
|
def browse(continuation : String, client_config : ClientConfig? = nil)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
"context" => self.make_context(client_config),
|
"context" => self.make_context(client_config),
|
||||||
@ -371,7 +371,7 @@ module YoutubeAPI
|
|||||||
browse_id : String,
|
browse_id : String,
|
||||||
*, # Force the following parameters to be passed by name
|
*, # Force the following parameters to be passed by name
|
||||||
params : String,
|
params : String,
|
||||||
client_config : ClientConfig | Nil = nil,
|
client_config : ClientConfig? = nil,
|
||||||
)
|
)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
@ -424,7 +424,7 @@ module YoutubeAPI
|
|||||||
# })
|
# })
|
||||||
# ```
|
# ```
|
||||||
#
|
#
|
||||||
def next(continuation : String, *, client_config : ClientConfig | Nil = nil)
|
def next(continuation : String, *, client_config : ClientConfig? = nil)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
"context" => self.make_context(client_config),
|
"context" => self.make_context(client_config),
|
||||||
@ -435,7 +435,7 @@ module YoutubeAPI
|
|||||||
end
|
end
|
||||||
|
|
||||||
# :ditto:
|
# :ditto:
|
||||||
def next(data : Hash, *, client_config : ClientConfig | Nil = nil)
|
def next(data : Hash, *, client_config : ClientConfig? = nil)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data2 = data.merge({
|
data2 = data.merge({
|
||||||
"context" => self.make_context(client_config),
|
"context" => self.make_context(client_config),
|
||||||
@ -445,7 +445,7 @@ module YoutubeAPI
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Allow a NamedTuple to be passed, too.
|
# Allow a NamedTuple to be passed, too.
|
||||||
def next(data : NamedTuple, *, client_config : ClientConfig | Nil = nil)
|
def next(data : NamedTuple, *, client_config : ClientConfig? = nil)
|
||||||
return self.next(data.to_h, client_config: client_config)
|
return self.next(data.to_h, client_config: client_config)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -466,7 +466,7 @@ module YoutubeAPI
|
|||||||
if CONFIG.invidious_companion.present?
|
if CONFIG.invidious_companion.present?
|
||||||
return self._post_invidious_companion("/youtubei/v1/player", data)
|
return self._post_invidious_companion("/youtubei/v1/player", data)
|
||||||
else
|
else
|
||||||
return nil
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ module YoutubeAPI
|
|||||||
# channel_b = YoutubeAPI.resolve_url("https://www.youtube.com/c/invalid")
|
# channel_b = YoutubeAPI.resolve_url("https://www.youtube.com/c/invalid")
|
||||||
# ```
|
# ```
|
||||||
#
|
#
|
||||||
def resolve_url(url : String, client_config : ClientConfig | Nil = nil)
|
def resolve_url(url : String, client_config : ClientConfig? = nil)
|
||||||
data = {
|
data = {
|
||||||
"context" => self.make_context(nil),
|
"context" => self.make_context(nil),
|
||||||
"url" => url,
|
"url" => url,
|
||||||
@ -524,7 +524,7 @@ module YoutubeAPI
|
|||||||
def search(
|
def search(
|
||||||
search_query : String,
|
search_query : String,
|
||||||
params : String,
|
params : String,
|
||||||
client_config : ClientConfig | Nil = nil,
|
client_config : ClientConfig? = nil,
|
||||||
)
|
)
|
||||||
# JSON Request data, required by the API
|
# JSON Request data, required by the API
|
||||||
data = {
|
data = {
|
||||||
@ -550,7 +550,7 @@ module YoutubeAPI
|
|||||||
|
|
||||||
def get_transcript(
|
def get_transcript(
|
||||||
params : String,
|
params : String,
|
||||||
client_config : ClientConfig | Nil = nil,
|
client_config : ClientConfig? = nil,
|
||||||
) : Hash(String, JSON::Any)
|
) : Hash(String, JSON::Any)
|
||||||
data = {
|
data = {
|
||||||
"context" => self.make_context(client_config),
|
"context" => self.make_context(client_config),
|
||||||
@ -572,7 +572,7 @@ module YoutubeAPI
|
|||||||
def _post_json(
|
def _post_json(
|
||||||
endpoint : String,
|
endpoint : String,
|
||||||
data : Hash,
|
data : Hash,
|
||||||
client_config : ClientConfig | Nil,
|
client_config : ClientConfig?,
|
||||||
) : Hash(String, JSON::Any)
|
) : Hash(String, JSON::Any)
|
||||||
# Use the default client config if nil is passed
|
# Use the default client config if nil is passed
|
||||||
client_config ||= DEFAULT_CLIENT_CONFIG
|
client_config ||= DEFAULT_CLIENT_CONFIG
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user