From 8c4439c1875796fe40a0b49295cba152ce9a596f Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:29:04 +0100 Subject: [PATCH 01/27] Bump Ameba to the latest version --- shard.lock | 2 +- shard.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shard.lock b/shard.lock index 1265eda67..12f36d309 100644 --- a/shard.lock +++ b/shard.lock @@ -2,7 +2,7 @@ version: 2.0 shards: ameba: git: https://github.com/crystal-ameba/ameba.git - version: 1.6.1 + version: 1.7.0-dev+git.commit.9dbeb92f89d7a668940029bd7b935bef370f26c1 athena-negotiation: git: https://github.com/athena-framework/negotiation.git diff --git a/shard.yml b/shard.yml index bc6c4bf48..494c64081 100644 --- a/shard.yml +++ b/shard.yml @@ -6,7 +6,7 @@ authors: - Contributors! description: | - Invidious is an alternative front-end to YouTube + Invidious is an alternative front-end to YouTube dependencies: pg: @@ -34,7 +34,7 @@ development_dependencies: version: ~> 0.10.4 ameba: github: crystal-ameba/ameba - version: ~> 1.6.1 + branch: master crystal: ">= 1.10.0, < 2.0.0" From 92aaec8dd9ab623d5a39ac01ea1f00a7fc42ef61 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:30:03 +0100 Subject: [PATCH 02/27] Run Ameba as a separate CI workflow --- .github/workflows/ameba.yml | 19 +++++++++++++++++++ .github/workflows/ci.yml | 5 ----- 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/ameba.yml diff --git a/.github/workflows/ameba.yml b/.github/workflows/ameba.yml new file mode 100644 index 000000000..e321d6a96 --- /dev/null +++ b/.github/workflows/ameba.yml @@ -0,0 +1,19 @@ +name: Ameba + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Download source + uses: actions/checkout@v6 + + - name: Run Ameba Linter + uses: crystal-ameba/github-action@master diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 847342f77..21f9d0b44 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,6 @@ on: jobs: build: - runs-on: ubuntu-latest name: "build - crystal: ${{ matrix.crystal }}, stable: ${{ matrix.stable }}" @@ -122,7 +121,6 @@ jobs: run: docker compose logs lint: - runs-on: ubuntu-latest continue-on-error: true @@ -159,6 +157,3 @@ jobs: git diff exit 1 fi - - - name: Run Ameba linter - run: bin/ameba From 068151a6648e7dea2adfe49bed51324e3eb65d7e Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:30:55 +0100 Subject: [PATCH 03/27] Remove redundant rule disable --- .ameba.yml | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 36d7c48fa..613ad5ec3 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -5,20 +5,20 @@ # Exclude assigns for ECR files Lint/UselessAssign: Excluded: - - src/invidious.cr - - src/invidious/helpers/errors.cr - - src/invidious/routes/**/*.cr + - src/invidious.cr + - src/invidious/helpers/errors.cr + - src/invidious/routes/**/*.cr # Ignore false negative (if !db.query_one?...) Lint/UnreachableCode: Excluded: - - src/invidious/database/base.cr + - src/invidious/database/base.cr # Ignore shadowed variable `key` (it works for now, and that's # a sensitive part of the code) Lint/ShadowingOuterLocalVar: Excluded: - - src/invidious/helpers/tokens.cr + - src/invidious/helpers/tokens.cr Lint/NotNil: Enabled: false @@ -27,7 +27,6 @@ Lint/SpecFilename: Excluded: - spec/parsers_helper.cr - # # Style # @@ -54,14 +53,6 @@ Naming/AccessorMethodName: Naming/BlockParameterName: Enabled: false -# Hides TODO comment warnings. -# -# Call `bin/ameba --only Documentation/DocumentationAdmonition` to -# list them -Documentation/DocumentationAdmonition: - Enabled: false - - # # Metrics # From 3d6f2668274307022c72ee103eb5aade7b6c5508 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:32:28 +0100 Subject: [PATCH 04/27] Fix `Lint/WhitespaceAroundMacroExpression` type of Ameba issues --- .../handlers/static_assets_handler_spec.cr | 2 +- src/invidious/channels/channels.cr | 2 +- src/invidious/config.cr | 18 +-- src/invidious/frontend/search_filters.cr | 44 +++---- src/invidious/helpers/errors.cr | 6 +- src/invidious/helpers/handlers.cr | 14 +- src/invidious/helpers/logger.cr | 6 +- src/invidious/helpers/macros.cr | 14 +- .../http_server/static_assets_handler.cr | 2 +- src/invidious/routing.cr | 122 +++++++++--------- src/invidious/videos.cr | 62 ++++----- src/invidious/yt_backend/extractors.cr | 34 ++--- 12 files changed, 163 insertions(+), 163 deletions(-) diff --git a/spec/http_server/handlers/static_assets_handler_spec.cr b/spec/http_server/handlers/static_assets_handler_spec.cr index 76dc7be77..268c4b2f4 100644 --- a/spec/http_server/handlers/static_assets_handler_spec.cr +++ b/spec/http_server/handlers/static_assets_handler_spec.cr @@ -59,7 +59,7 @@ end # Get relative file path to a file within the static_assets_handler folder macro get_file_path(basename) - "spec/http_server/handlers/static_assets_handler/#{ {{basename}} }" + "spec/http_server/handlers/static_assets_handler/#{ {{ basename }} }" end Spectator.describe StaticAssetsHandler do diff --git a/src/invidious/channels/channels.cr b/src/invidious/channels/channels.cr index 659823255..65a1aab72 100644 --- a/src/invidious/channels/channels.cr +++ b/src/invidious/channels/channels.cr @@ -93,7 +93,7 @@ struct ChannelVideo def to_tuple {% begin %} { - {{@type.instance_vars.map(&.name).splat}} + {{ @type.instance_vars.map(&.name).splat }} } {% end %} end diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 7853d9a3b..d24939923 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -58,7 +58,7 @@ struct ConfigPreferences def to_tuple {% begin %} { - {{(@type.instance_vars.map { |var| "#{var.name}: #{var.name}".id }).splat}} + {{ (@type.instance_vars.map { |var| "#{var.name}: #{var.name}".id }).splat }} } {% end %} end @@ -212,14 +212,14 @@ class Config {% for ivar in Config.instance_vars %} {% env_id = "INVIDIOUS_#{ivar.id.upcase}" %} - if ENV.has_key?({{env_id}}) - env_value = ENV.fetch({{env_id}}) + if ENV.has_key?({{ env_id }}) + env_value = ENV.fetch({{ env_id }}) success = false # Use YAML converter if specified {% ann = ivar.annotation(::YAML::Field) %} {% if ann && ann[:converter] %} - config.{{ivar.id}} = {{ann[:converter]}}.from_yaml(YAML::ParseContext.new, YAML::Nodes.parse(ENV.fetch({{env_id}})).nodes[0]) + config.{{ ivar.id }} = {{ ann[:converter] }}.from_yaml(YAML::ParseContext.new, YAML::Nodes.parse(ENV.fetch({{ env_id }})).nodes[0]) success = true # Use regular YAML parser otherwise @@ -227,10 +227,10 @@ class Config {% ivar_types = ivar.type.union? ? ivar.type.union_types : [ivar.type] %} # Sort types to avoid parsing nulls and numbers as strings {% ivar_types = ivar_types.sort_by { |ivar_type| ivar_type == Nil ? 0 : ivar_type == Int32 ? 1 : 2 } %} - {{ivar_types}}.each do |ivar_type| + {{ ivar_types }}.each do |ivar_type| if !success begin - config.{{ivar.id}} = ivar_type.from_yaml(env_value) + config.{{ ivar.id }} = ivar_type.from_yaml(env_value) success = true rescue # nop @@ -241,14 +241,14 @@ class Config # Exit on fail if !success - puts %(Config.{{ivar.id}} failed to parse #{env_value} as {{ivar.type}}) + puts %(Config.{{ ivar.id }} failed to parse #{env_value} as {{ ivar.type }}) exit(1) end end # Warn when any config attribute is set to "CHANGE_ME!!" - if config.{{ivar.id}} == "CHANGE_ME!!" - puts "Config: The value of '#{ {{ivar.stringify}} }' needs to be changed!!" + if config.{{ ivar.id }} == "CHANGE_ME!!" + puts "Config: The value of '#{ {{ ivar.stringify }} }' needs to be changed!!" exit(1) end {% end %} diff --git a/src/invidious/frontend/search_filters.cr b/src/invidious/frontend/search_filters.cr index 8ac0af2e9..2ad6c6395 100644 --- a/src/invidious/frontend/search_filters.cr +++ b/src/invidious/frontend/search_filters.cr @@ -41,11 +41,11 @@ module Invidious::Frontend::SearchFilters str << "\t\t\t\t
\n" str << "\t\t\t\t\t
" - str << translate(locale, "search_filters_{{name}}_label") + str << translate(locale, "search_filters_{{ name }}_label") str << "
\n" str << "\t\t\t\t\t
\n" - make_{{name}}_filter_options(str, filters.{{name}}, locale) + make_{{ name }}_filter_options(str, filters.{{ name }}, locale) str << "\t\t\t\t\t
" str << "\t\t\t\t
\n" @@ -57,12 +57,12 @@ module Invidious::Frontend::SearchFilters {% date = value.underscore %} str << "\t\t\t\t\t\t
" - str << "' - str << "
\n" {% end %} end @@ -73,12 +73,12 @@ module Invidious::Frontend::SearchFilters {% type = value.underscore %} str << "\t\t\t\t\t\t
" - str << "' - str << "
\n" {% end %} end @@ -89,12 +89,12 @@ module Invidious::Frontend::SearchFilters {% duration = value.underscore %} str << "\t\t\t\t\t\t
" - str << "' - str << "
\n" {% end %} end @@ -106,12 +106,12 @@ module Invidious::Frontend::SearchFilters {% feature = value.underscore %} str << "\t\t\t\t\t\t
" - str << "' - str << "
\n" {% end %} {% end %} @@ -123,12 +123,12 @@ module Invidious::Frontend::SearchFilters {% sort = value.underscore %} str << "\t\t\t\t\t\t
" - str << "' - str << "
\n" {% end %} end diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index e2c4b650a..fa198031e 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -3,7 +3,7 @@ # ------------------- macro error_template(*args) - error_template_helper(env, {{args.splat}}) + error_template_helper(env, {{ args.splat }}) end def github_details(summary : String, content : String) @@ -106,7 +106,7 @@ end # ------------------- macro error_atom(*args) - error_atom_helper(env, {{args.splat}}) + error_atom_helper(env, {{ args.splat }}) end def error_atom_helper(env : HTTP::Server::Context, status_code : Int32, exception : Exception) @@ -132,7 +132,7 @@ end # ------------------- macro error_json(*args) - error_json_helper(env, {{args.splat}}) + error_json_helper(env, {{ args.splat }}) end def error_json_helper( diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr index 7c5ef1185..ca0556568 100644 --- a/src/invidious/helpers/handlers.cr +++ b/src/invidious/helpers/handlers.cr @@ -2,10 +2,10 @@ module HTTP::Handler @@exclude_routes_tree = Radix::Tree(String).new macro exclude(paths, method = "GET") - class_name = {{@type.name}} - method_downcase = {{method.downcase}} + class_name = {{ @type.name }} + method_downcase = {{ method.downcase }} class_name_method = "#{class_name}/#{method_downcase}" - ({{paths}}).each do |path| + ({{ paths }}).each do |path| @@exclude_routes_tree.add class_name_method + path, '/' + method_downcase + path end end @@ -21,7 +21,7 @@ end class Kemal::RouteHandler {% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %} - exclude ["/api/v1/*"], {{method}} + exclude ["/api/v1/*"], {{ method }} {% end %} # Processes the route if it's a match. Otherwise renders 404. @@ -45,7 +45,7 @@ end class Kemal::ExceptionHandler {% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %} - exclude ["/api/v1/*"], {{method}} + exclude ["/api/v1/*"], {{ method }} {% end %} private def call_exception_with_status_code(context : HTTP::Server::Context, exception : Exception, status_code : Int32) @@ -73,7 +73,7 @@ end class AuthHandler < Kemal::Handler {% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %} - only ["/api/v1/auth/*"], {{method}} + only ["/api/v1/auth/*"], {{ method }} {% end %} def call(env) @@ -122,7 +122,7 @@ end class APIHandler < Kemal::Handler {% for method in %w(GET POST PUT HEAD DELETE PATCH OPTIONS) %} - only ["/api/v1/*"], {{method}} + only ["/api/v1/*"], {{ method }} {% end %} exclude ["/api/v1/auth/notifications"], "GET" exclude ["/api/v1/auth/notifications"], "POST" diff --git a/src/invidious/helpers/logger.cr b/src/invidious/helpers/logger.cr index 033495955..bce10bb3e 100644 --- a/src/invidious/helpers/logger.cr +++ b/src/invidious/helpers/logger.cr @@ -56,9 +56,9 @@ class Invidious::LogHandler < Kemal::BaseLogHandler end {% for level in %w(trace debug info warn error fatal) %} - def {{level.id}}(message : String) - if LogLevel::{{level.id.capitalize}} >= @level - puts("#{Time.utc} [{{level.id}}] #{message}".colorize(color(LogLevel::{{level.id.capitalize}}))) + def {{ level.id }}(message : String) + if LogLevel::{{ level.id.capitalize }} >= @level + puts("#{Time.utc} [{{ level.id }}] #{message}".colorize(color(LogLevel::{{ level.id.capitalize }}))) end end {% end %} diff --git a/src/invidious/helpers/macros.cr b/src/invidious/helpers/macros.cr index 848473218..4e2f4bb24 100644 --- a/src/invidious/helpers/macros.cr +++ b/src/invidious/helpers/macros.cr @@ -49,24 +49,24 @@ module JSON::Serializable end macro templated(_filename, template = "template", navbar_search = true) - navbar_search = {{navbar_search}} + navbar_search = {{ navbar_search }} {{ filename = "src/invidious/views/" + _filename + ".ecr" }} {{ layout = "src/invidious/views/" + template + ".ecr" }} - __content_filename__ = {{filename}} - render {{filename}}, {{layout}} + __content_filename__ = {{ filename }} + render {{ filename }}, {{ layout }} end macro rendered(filename) - render("src/invidious/views/#{{{filename}}}.ecr") + render("src/invidious/views/#{{{ filename }}}.ecr") end # Similar to Kemals halt method but works in a # method. macro haltf(env, status_code = 200, response = "") - {{env}}.response.status_code = {{status_code}} - {{env}}.response.print {{response}} - {{env}}.response.close + {{ env }}.response.status_code = {{ status_code }} + {{ env }}.response.print {{ response }} + {{ env }}.response.close return end diff --git a/src/invidious/http_server/static_assets_handler.cr b/src/invidious/http_server/static_assets_handler.cr index 7902c95bf..024b693dd 100644 --- a/src/invidious/http_server/static_assets_handler.cr +++ b/src/invidious/http_server/static_assets_handler.cr @@ -106,7 +106,7 @@ module Invidious::HttpServer # Can be removed once https://github.com/crystal-lang/crystal/issues/15817 is fixed. private def serve_file_range(context : HTTP::Server::Context, file : IO, range_header : String, file_info) # Paste in the body of inherited serve_file_range - {{@type.superclass.methods.select(&.name.==("serve_file_range"))[0].body}} + {{ @type.superclass.methods.select(&.name.==("serve_file_range"))[0].body }} end # Clear cached files. diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index 32e8554c3..684b578f8 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -3,12 +3,12 @@ module Invidious::Routing {% for http_method in {"get", "post", "delete", "options", "patch", "put"} %} - macro {{http_method.id}}(path, controller, method = :handle) + macro {{ http_method.id }}(path, controller, method = :handle) unless Kemal::Utils.path_starts_with_slash?(\{{path}}) - raise Kemal::Exceptions::InvalidPathStartException.new({{http_method}}, \{{path}}) + raise Kemal::Exceptions::InvalidPathStartException.new({{ http_method }}, \{{path}}) end - Kemal::RouteHandler::INSTANCE.add_route({{http_method.upcase}}, \{{path}}) do |env| + Kemal::RouteHandler::INSTANCE.add_route({{ http_method.upcase }}, \{{path}}) do |env| \{{ controller }}.\{{ method.id }}(env) end end @@ -238,91 +238,91 @@ module Invidious::Routing def register_api_v1_routes {% begin %} - {{namespace = Routes::API::V1}} + {{ namespace = Routes::API::V1 }} # Videos - get "/api/v1/videos/:id", {{namespace}}::Videos, :videos - get "/api/v1/storyboards/:id", {{namespace}}::Videos, :storyboards - get "/api/v1/captions/:id", {{namespace}}::Videos, :captions - get "/api/v1/annotations/:id", {{namespace}}::Videos, :annotations - get "/api/v1/comments/:id", {{namespace}}::Videos, :comments - get "/api/v1/clips/:id", {{namespace}}::Videos, :clips - get "/api/v1/transcripts/:id", {{namespace}}::Videos, :transcripts + get "/api/v1/videos/:id", {{ namespace }}::Videos, :videos + get "/api/v1/storyboards/:id", {{ namespace }}::Videos, :storyboards + get "/api/v1/captions/:id", {{ namespace }}::Videos, :captions + get "/api/v1/annotations/:id", {{ namespace }}::Videos, :annotations + get "/api/v1/comments/:id", {{ namespace }}::Videos, :comments + get "/api/v1/clips/:id", {{ namespace }}::Videos, :clips + get "/api/v1/transcripts/:id", {{ namespace }}::Videos, :transcripts # Feeds - get "/api/v1/trending", {{namespace}}::Feeds, :trending - get "/api/v1/popular", {{namespace}}::Feeds, :popular + get "/api/v1/trending", {{ namespace }}::Feeds, :trending + get "/api/v1/popular", {{ namespace }}::Feeds, :popular # Channels - get "/api/v1/channels/:ucid", {{namespace}}::Channels, :home - get "/api/v1/channels/:ucid/latest", {{namespace}}::Channels, :latest - get "/api/v1/channels/:ucid/videos", {{namespace}}::Channels, :videos - get "/api/v1/channels/:ucid/shorts", {{namespace}}::Channels, :shorts - get "/api/v1/channels/:ucid/streams", {{namespace}}::Channels, :streams - get "/api/v1/channels/:ucid/podcasts", {{namespace}}::Channels, :podcasts - get "/api/v1/channels/:ucid/releases", {{namespace}}::Channels, :releases - get "/api/v1/channels/:ucid/courses", {{namespace}}::Channels, :courses - get "/api/v1/channels/:ucid/playlists", {{namespace}}::Channels, :playlists - get "/api/v1/channels/:ucid/community", {{namespace}}::Channels, :community - get "/api/v1/channels/:ucid/posts", {{namespace}}::Channels, :community - get "/api/v1/channels/:ucid/channels", {{namespace}}::Channels, :channels - get "/api/v1/channels/:ucid/search", {{namespace}}::Channels, :search + get "/api/v1/channels/:ucid", {{ namespace }}::Channels, :home + get "/api/v1/channels/:ucid/latest", {{ namespace }}::Channels, :latest + get "/api/v1/channels/:ucid/videos", {{ namespace }}::Channels, :videos + get "/api/v1/channels/:ucid/shorts", {{ namespace }}::Channels, :shorts + get "/api/v1/channels/:ucid/streams", {{ namespace }}::Channels, :streams + get "/api/v1/channels/:ucid/podcasts", {{ namespace }}::Channels, :podcasts + get "/api/v1/channels/:ucid/releases", {{ namespace }}::Channels, :releases + get "/api/v1/channels/:ucid/courses", {{ namespace }}::Channels, :courses + get "/api/v1/channels/:ucid/playlists", {{ namespace }}::Channels, :playlists + get "/api/v1/channels/:ucid/community", {{ namespace }}::Channels, :community + get "/api/v1/channels/:ucid/posts", {{ namespace }}::Channels, :community + get "/api/v1/channels/:ucid/channels", {{ namespace }}::Channels, :channels + get "/api/v1/channels/:ucid/search", {{ namespace }}::Channels, :search # Posts - get "/api/v1/post/:id", {{namespace}}::Channels, :post - get "/api/v1/post/:id/comments", {{namespace}}::Channels, :post_comments + get "/api/v1/post/:id", {{ namespace }}::Channels, :post + get "/api/v1/post/:id/comments", {{ namespace }}::Channels, :post_comments # 301 redirects to new /api/v1/channels/community/:ucid and /:ucid/community - get "/api/v1/channels/comments/:ucid", {{namespace}}::Channels, :channel_comments_redirect - get "/api/v1/channels/:ucid/comments", {{namespace}}::Channels, :channel_comments_redirect + get "/api/v1/channels/comments/:ucid", {{ namespace }}::Channels, :channel_comments_redirect + get "/api/v1/channels/:ucid/comments", {{ namespace }}::Channels, :channel_comments_redirect # Search - get "/api/v1/search", {{namespace}}::Search, :search - get "/api/v1/search/suggestions", {{namespace}}::Search, :search_suggestions - get "/api/v1/hashtag/:hashtag", {{namespace}}::Search, :hashtag + get "/api/v1/search", {{ namespace }}::Search, :search + get "/api/v1/search/suggestions", {{ namespace }}::Search, :search_suggestions + get "/api/v1/hashtag/:hashtag", {{ namespace }}::Search, :hashtag # Authenticated - get "/api/v1/auth/preferences", {{namespace}}::Authenticated, :get_preferences - post "/api/v1/auth/preferences", {{namespace}}::Authenticated, :set_preferences + get "/api/v1/auth/preferences", {{ namespace }}::Authenticated, :get_preferences + post "/api/v1/auth/preferences", {{ namespace }}::Authenticated, :set_preferences - get "/api/v1/auth/export/invidious", {{namespace}}::Authenticated, :export_invidious - post "/api/v1/auth/import/invidious", {{namespace}}::Authenticated, :import_invidious + get "/api/v1/auth/export/invidious", {{ namespace }}::Authenticated, :export_invidious + post "/api/v1/auth/import/invidious", {{ namespace }}::Authenticated, :import_invidious - get "/api/v1/auth/history", {{namespace}}::Authenticated, :get_history - post "/api/v1/auth/history/:id", {{namespace}}::Authenticated, :mark_watched - delete "/api/v1/auth/history/:id", {{namespace}}::Authenticated, :mark_unwatched - delete "/api/v1/auth/history", {{namespace}}::Authenticated, :clear_history + get "/api/v1/auth/history", {{ namespace }}::Authenticated, :get_history + post "/api/v1/auth/history/:id", {{ namespace }}::Authenticated, :mark_watched + delete "/api/v1/auth/history/:id", {{ namespace }}::Authenticated, :mark_unwatched + delete "/api/v1/auth/history", {{ namespace }}::Authenticated, :clear_history - get "/api/v1/auth/feed", {{namespace}}::Authenticated, :feed + get "/api/v1/auth/feed", {{ namespace }}::Authenticated, :feed - get "/api/v1/auth/subscriptions", {{namespace}}::Authenticated, :get_subscriptions - post "/api/v1/auth/subscriptions/:ucid", {{namespace}}::Authenticated, :subscribe_channel - delete "/api/v1/auth/subscriptions/:ucid", {{namespace}}::Authenticated, :unsubscribe_channel + get "/api/v1/auth/subscriptions", {{ namespace }}::Authenticated, :get_subscriptions + post "/api/v1/auth/subscriptions/:ucid", {{ namespace }}::Authenticated, :subscribe_channel + delete "/api/v1/auth/subscriptions/:ucid", {{ namespace }}::Authenticated, :unsubscribe_channel - get "/api/v1/auth/playlists", {{namespace}}::Authenticated, :list_playlists - post "/api/v1/auth/playlists", {{namespace}}::Authenticated, :create_playlist - patch "/api/v1/auth/playlists/:plid",{{namespace}}:: Authenticated, :update_playlist_attribute - delete "/api/v1/auth/playlists/:plid", {{namespace}}::Authenticated, :delete_playlist - post "/api/v1/auth/playlists/:plid/videos", {{namespace}}::Authenticated, :insert_video_into_playlist - delete "/api/v1/auth/playlists/:plid/videos/:index", {{namespace}}::Authenticated, :delete_video_in_playlist + get "/api/v1/auth/playlists", {{ namespace }}::Authenticated, :list_playlists + post "/api/v1/auth/playlists", {{ namespace }}::Authenticated, :create_playlist + patch "/api/v1/auth/playlists/:plid",{{ namespace }}:: Authenticated, :update_playlist_attribute + delete "/api/v1/auth/playlists/:plid", {{ namespace }}::Authenticated, :delete_playlist + post "/api/v1/auth/playlists/:plid/videos", {{ namespace }}::Authenticated, :insert_video_into_playlist + delete "/api/v1/auth/playlists/:plid/videos/:index", {{ namespace }}::Authenticated, :delete_video_in_playlist - get "/api/v1/auth/tokens", {{namespace}}::Authenticated, :get_tokens - post "/api/v1/auth/tokens/register", {{namespace}}::Authenticated, :register_token - post "/api/v1/auth/tokens/unregister", {{namespace}}::Authenticated, :unregister_token + get "/api/v1/auth/tokens", {{ namespace }}::Authenticated, :get_tokens + post "/api/v1/auth/tokens/register", {{ namespace }}::Authenticated, :register_token + post "/api/v1/auth/tokens/unregister", {{ namespace }}::Authenticated, :unregister_token if CONFIG.enable_user_notifications - get "/api/v1/auth/notifications", {{namespace}}::Authenticated, :notifications - post "/api/v1/auth/notifications", {{namespace}}::Authenticated, :notifications + get "/api/v1/auth/notifications", {{ namespace }}::Authenticated, :notifications + post "/api/v1/auth/notifications", {{ namespace }}::Authenticated, :notifications end # Misc - get "/api/v1/stats", {{namespace}}::Misc, :stats - get "/api/v1/playlists/:plid", {{namespace}}::Misc, :get_playlist - get "/api/v1/auth/playlists/:plid", {{namespace}}::Misc, :get_playlist - get "/api/v1/mixes/:rdid", {{namespace}}::Misc, :mixes - get "/api/v1/resolveurl", {{namespace}}::Misc, :resolve_url + get "/api/v1/stats", {{ namespace }}::Misc, :stats + get "/api/v1/playlists/:plid", {{ namespace }}::Misc, :get_playlist + get "/api/v1/auth/playlists/:plid", {{ namespace }}::Misc, :get_playlist + get "/api/v1/mixes/:rdid", {{ namespace }}::Misc, :mixes + get "/api/v1/resolveurl", {{ namespace }}::Misc, :resolve_url {% end %} end end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 0446922fe..b9ddecb6b 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -195,37 +195,37 @@ struct Video # Macros defining getters/setters for various types of data private macro getset_string(name) - # Return {{name.stringify}} from `info` - def {{name.id.underscore}} : String - return info[{{name.stringify}}]?.try &.as_s || "" + # Return {{ name.stringify }} from `info` + def {{ name.id.underscore }} : String + return info[{{ name.stringify }}]?.try &.as_s || "" end - # Update {{name.stringify}} into `info` - def {{name.id.underscore}}=(value : String) - info[{{name.stringify}}] = JSON::Any.new(value) + # Update {{ name.stringify }} into `info` + def {{ name.id.underscore }}=(value : String) + info[{{ name.stringify }}] = JSON::Any.new(value) end - {% if flag?(:debug_macros) %} {{debug}} {% end %} + {% if flag?(:debug_macros) %} {{ debug }} {% end %} end private macro getset_string_array(name) - # Return {{name.stringify}} from `info` - def {{name.id.underscore}} : Array(String) - return info[{{name.stringify}}]?.try &.as_a.map &.as_s || [] of String + # Return {{ name.stringify }} from `info` + def {{ name.id.underscore }} : Array(String) + return info[{{ name.stringify }}]?.try &.as_a.map &.as_s || [] of String end - # Update {{name.stringify}} into `info` - def {{name.id.underscore}}=(value : Array(String)) - info[{{name.stringify}}] = JSON::Any.new(value) + # Update {{ name.stringify }} into `info` + def {{ name.id.underscore }}=(value : Array(String)) + info[{{ name.stringify }}] = JSON::Any.new(value) end - {% if flag?(:debug_macros) %} {{debug}} {% end %} + {% if flag?(:debug_macros) %} {{ debug }} {% end %} end {% for op, type in {i32: Int32, i64: Int64} %} - private macro getset_{{op}}(name) - def \{{name.id.underscore}} : {{type}} - return info[\{{name.stringify}}]?.try &.as_i64.to_{{op}} || 0_{{op}} + private macro getset_{{ op }}(name) + def \{{name.id.underscore}} : {{ type }} + return info[\{{name.stringify}}]?.try &.as_i64.to_{{ op }} || 0_{{ op }} end def \{{name.id.underscore}}=(value : Int) @@ -237,32 +237,32 @@ struct Video {% end %} private macro getset_bool(name) - # Return {{name.stringify}} from `info` - def {{name.id.underscore}} : Bool - return info[{{name.stringify}}]?.try &.as_bool || false + # Return {{ name.stringify }} from `info` + def {{ name.id.underscore }} : Bool + return info[{{ name.stringify }}]?.try &.as_bool || false end - # Update {{name.stringify}} into `info` - def {{name.id.underscore}}=(value : Bool) - info[{{name.stringify}}] = JSON::Any.new(value) + # Update {{ name.stringify }} into `info` + def {{ name.id.underscore }}=(value : Bool) + info[{{ name.stringify }}] = JSON::Any.new(value) end - {% if flag?(:debug_macros) %} {{debug}} {% end %} + {% if flag?(:debug_macros) %} {{ debug }} {% end %} end # Macro to generate ? and = accessor methods for attributes in `info` private macro predicate_bool(method_name, name) - # Return {{name.stringify}} from `info` - def {{method_name.id.underscore}}? : Bool - return info[{{name.stringify}}]?.try &.as_bool || false + # Return {{ name.stringify }} from `info` + def {{ method_name.id.underscore }}? : Bool + return info[{{ name.stringify }}]?.try &.as_bool || false end - # Update {{name.stringify}} into `info` - def {{method_name.id.underscore}}=(value : Bool) - info[{{name.stringify}}] = JSON::Any.new(value) + # Update {{ name.stringify }} into `info` + def {{ method_name.id.underscore }}=(value : Bool) + info[{{ name.stringify }}] = JSON::Any.new(value) end - {% if flag?(:debug_macros) %} {{debug}} {% end %} + {% if flag?(:debug_macros) %} {{ debug }} {% end %} end # Method definitions, using the macros above diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 04e00f202..759f1ed32 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -40,8 +40,8 @@ private module Parsers begin return parse_internal(*args) rescue ex - LOGGER.debug("#{{{@type.name}}}: Failed to render item.") - LOGGER.debug("#{{{@type.name}}}: Got exception: #{ex.message}") + LOGGER.debug("#{{{ @type.name }}}: Failed to render item.") + LOGGER.debug("#{{{ @type.name }}}: Got exception: #{ex.message}") ProblematicTimelineItem.new( parse_exception: ex ) @@ -173,7 +173,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -240,7 +240,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -289,7 +289,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -334,7 +334,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -395,7 +395,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -467,7 +467,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -496,7 +496,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -527,7 +527,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -626,7 +626,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -704,7 +704,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -762,7 +762,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end @@ -791,7 +791,7 @@ private module Parsers end def self.parser_name - return {{@type.name}} + return {{ @type.name }} end end end @@ -878,7 +878,7 @@ private module Extractors end def self.extractor_name - return {{@type.name}} + return {{ @type.name }} end end @@ -919,7 +919,7 @@ private module Extractors end def self.extractor_name - return {{@type.name}} + return {{ @type.name }} end end @@ -953,7 +953,7 @@ private module Extractors end def self.extractor_name - return {{@type.name}} + return {{ @type.name }} end end end From db8e73760d74cd680426df692145e36fb8e3debd Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:33:10 +0100 Subject: [PATCH 05/27] Fix `Style/VerboseNilType` type of Ameba issues --- src/invidious/channels/channels.cr | 2 +- src/invidious/helpers/errors.cr | 4 ++-- src/invidious/helpers/i18n.cr | 2 +- src/invidious/videos.cr | 2 +- src/invidious/yt_backend/youtube_api.cr | 22 +++++++++++----------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/invidious/channels/channels.cr b/src/invidious/channels/channels.cr index 65a1aab72..32116cbcd 100644 --- a/src/invidious/channels/channels.cr +++ b/src/invidious/channels/channels.cr @@ -107,7 +107,7 @@ class ChannelRedirect < Exception end def get_batch_channels(channels) - finished_channel = Channel(String | Nil).new + finished_channel = Channel(String?).new max_threads = 10 spawn do diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index fa198031e..7ee5d30dd 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -139,7 +139,7 @@ def error_json_helper( env : HTTP::Server::Context, status_code : Int32, exception : Exception, - additional_fields : Hash(String, Object) | Nil = nil, + additional_fields : Hash(String, Object)? = nil, ) if exception.is_a?(InfoException) return error_json_helper(env, status_code, exception.message || "", additional_fields) @@ -161,7 +161,7 @@ def error_json_helper( env : HTTP::Server::Context, status_code : Int32, message : String, - additional_fields : Hash(String, Object) | Nil = nil, + additional_fields : Hash(String, Object)? = nil, ) env.response.content_type = "application/json" env.response.status_code = status_code diff --git a/src/invidious/helpers/i18n.cr b/src/invidious/helpers/i18n.cr index bca2edda9..497501ce7 100644 --- a/src/invidious/helpers/i18n.cr +++ b/src/invidious/helpers/i18n.cr @@ -94,7 +94,7 @@ def load_all_locales return locales 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 # that key as the text, so this is more or less transparent to the user. if !LOCALES["en-US"].has_key?(key) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index b9ddecb6b..f23317b3f 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -48,7 +48,7 @@ struct Video end end - def to_json(json : JSON::Builder | Nil = nil) + def to_json(json : JSON::Builder? = nil) to_json(nil, json) end diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index dd709920a..6d6060ebf 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -207,7 +207,7 @@ module YoutubeAPI # Region to provide to youtube, e.g to alter search results # (this is passed as the `gl` parameter). - property region : String | Nil + property region : String? # Initialization function def initialize( @@ -283,7 +283,7 @@ module YoutubeAPI # Return, as a Hash, the "context" data required to request the # 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 client_config ||= DEFAULT_CLIENT_CONFIG @@ -353,7 +353,7 @@ module YoutubeAPI # # - 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 data = { "context" => self.make_context(client_config), @@ -368,7 +368,7 @@ module YoutubeAPI browse_id : String, *, # Force the following parameters to be passed by name params : String, - client_config : ClientConfig | Nil = nil, + client_config : ClientConfig? = nil, ) # JSON Request data, required by the API data = { @@ -421,7 +421,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 data = { "context" => self.make_context(client_config), @@ -432,7 +432,7 @@ module YoutubeAPI end # :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 data2 = data.merge({ "context" => self.make_context(client_config), @@ -442,7 +442,7 @@ module YoutubeAPI end # 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) end @@ -495,7 +495,7 @@ module YoutubeAPI # channel_b = YoutubeAPI.resolve_url("https://youtube.com/c/invalid") # ``` # - def resolve_url(url : String, client_config : ClientConfig | Nil = nil) + def resolve_url(url : String, client_config : ClientConfig? = nil) data = { "context" => self.make_context(nil), "url" => url, @@ -521,7 +521,7 @@ module YoutubeAPI def search( search_query : String, params : String, - client_config : ClientConfig | Nil = nil, + client_config : ClientConfig? = nil, ) # JSON Request data, required by the API data = { @@ -547,7 +547,7 @@ module YoutubeAPI def get_transcript( params : String, - client_config : ClientConfig | Nil = nil, + client_config : ClientConfig? = nil, ) : Hash(String, JSON::Any) data = { "context" => self.make_context(client_config), @@ -569,7 +569,7 @@ module YoutubeAPI def _post_json( endpoint : String, data : Hash, - client_config : ClientConfig | Nil, + client_config : ClientConfig?, ) : Hash(String, JSON::Any) # Use the default client config if nil is passed client_config ||= DEFAULT_CLIENT_CONFIG From d371829477c8b7093533cda4bc8511b878ba9c48 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:34:23 +0100 Subject: [PATCH 06/27] Fix `Style/RedundantSelf` type of Ameba issues --- src/invidious/channels/channels.cr | 44 +++---- src/invidious/frontend/comments_reddit.cr | 2 +- src/invidious/frontend/pagination.cr | 6 +- src/invidious/helpers/i18next.cr | 8 +- src/invidious/helpers/serialized_yt_data.cr | 132 ++++++++++---------- src/invidious/helpers/webvtt.cr | 2 +- src/invidious/jobs/instance_refresh_job.cr | 2 +- src/invidious/jsonify/api_v1/video_json.cr | 6 +- src/invidious/playlists.cr | 94 +++++++------- src/invidious/routes/api/v1/channels.cr | 2 +- src/invidious/routes/channels.cr | 22 ++-- src/invidious/routes/companion.cr | 6 +- src/invidious/routes/images.cr | 8 +- src/invidious/routing.cr | 10 +- src/invidious/search/query.cr | 6 +- src/invidious/videos.cr | 8 +- src/invidious/yt_backend/extractors.cr | 36 +++--- src/invidious/yt_backend/youtube_api.cr | 34 ++--- 18 files changed, 214 insertions(+), 214 deletions(-) diff --git a/src/invidious/channels/channels.cr b/src/invidious/channels/channels.cr index 32116cbcd..3c15d6359 100644 --- a/src/invidious/channels/channels.cr +++ b/src/invidious/channels/channels.cr @@ -26,21 +26,21 @@ struct ChannelVideo json.object do json.field "type", "shortVideo" - json.field "title", self.title - json.field "videoId", self.id + json.field "title", title + json.field "videoId", id json.field "videoThumbnails" do - Invidious::JSONify::APIv1.thumbnails(json, self.id) + Invidious::JSONify::APIv1.thumbnails(json, id) end - json.field "lengthSeconds", self.length_seconds + json.field "lengthSeconds", length_seconds - json.field "author", self.author - json.field "authorId", self.ucid - json.field "authorUrl", "/channel/#{self.ucid}" - json.field "published", self.published.to_unix - json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale)) + json.field "author", author + json.field "authorId", ucid + json.field "authorUrl", "/channel/#{ucid}" + json.field "published", published.to_unix + json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale)) - json.field "viewCount", self.views + json.field "viewCount", views end end @@ -51,34 +51,34 @@ struct ChannelVideo end def to_xml(locale, query_params, xml : XML::Builder) - query_params["v"] = self.id + query_params["v"] = id xml.element("entry") do - xml.element("id") { xml.text "yt:video:#{self.id}" } - xml.element("yt:videoId") { xml.text self.id } - xml.element("yt:channelId") { xml.text self.ucid } - xml.element("title") { xml.text self.title } + xml.element("id") { xml.text "yt:video:#{id}" } + xml.element("yt:videoId") { xml.text id } + xml.element("yt:channelId") { xml.text ucid } + xml.element("title") { xml.text title } xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}") xml.element("author") do - xml.element("name") { xml.text self.author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } + xml.element("name") { xml.text author } + xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } end xml.element("content", type: "xhtml") do xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do - xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg") + xml.element("img", src: "#{HOST_URL}/vi/#{id}/mqdefault.jpg") end end end - xml.element("published") { xml.text self.published.to_s("%Y-%m-%dT%H:%M:%S%:z") } - xml.element("updated") { xml.text self.updated.to_s("%Y-%m-%dT%H:%M:%S%:z") } + xml.element("published") { xml.text published.to_s("%Y-%m-%dT%H:%M:%S%:z") } + xml.element("updated") { xml.text updated.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("media:group") do - xml.element("media:title") { xml.text self.title } - xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg", + xml.element("media:title") { xml.text title } + xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{id}/mqdefault.jpg", width: "320", height: "180") end end diff --git a/src/invidious/frontend/comments_reddit.cr b/src/invidious/frontend/comments_reddit.cr index 4dda683ef..d46e93e7f 100644 --- a/src/invidious/frontend/comments_reddit.cr +++ b/src/invidious/frontend/comments_reddit.cr @@ -11,7 +11,7 @@ module Invidious::Frontend::Comments replies_html = "" if child.replies.is_a?(RedditThing) replies = child.replies.as(RedditThing) - replies_html = self.template_reddit(replies.data.as(RedditListing).children, locale) + replies_html = template_reddit(replies.data.as(RedditListing).children, locale) end if child.depth > 0 diff --git a/src/invidious/frontend/pagination.cr b/src/invidious/frontend/pagination.cr index a29f59366..d2bf0e7e6 100644 --- a/src/invidious/frontend/pagination.cr +++ b/src/invidious/frontend/pagination.cr @@ -70,7 +70,7 @@ module Invidious::Frontend::Pagination params_prev = URI::Params{"page" => (current_page - 1).to_s} url_prev = HttpServer::Utils.add_params_to_url(base_url, params_prev) - self.previous_page(str, locale, url_prev.to_s) + previous_page(str, locale, url_prev.to_s) end str << %(\n) @@ -80,7 +80,7 @@ module Invidious::Frontend::Pagination params_next = URI::Params{"page" => (current_page + 1).to_s} url_next = HttpServer::Utils.add_params_to_url(base_url, params_next) - self.next_page(str, locale, url_next.to_s) + next_page(str, locale, url_next.to_s) end str << %(\n) @@ -109,7 +109,7 @@ module Invidious::Frontend::Pagination params["continuation"] = ctoken url_next = HttpServer::Utils.add_params_to_url(base_url, params) - self.next_page(str, locale, url_next.to_s) + next_page(str, locale, url_next.to_s) end str << %(\n) diff --git a/src/invidious/helpers/i18next.cr b/src/invidious/helpers/i18next.cr index 684e6d145..520bb9e99 100644 --- a/src/invidious/helpers/i18next.cr +++ b/src/invidious/helpers/i18next.cr @@ -151,17 +151,17 @@ module I18next::Plurals @version = version.to_u8 end - self.init_rules + init_rules end def init_rules # Look into sets PLURAL_SETS.each do |form, langs| - langs.each { |lang| self.forms[lang] = form } + langs.each { |lang| forms[lang] = form } end # Add plurals from the "singles" set - self.forms.merge!(PLURAL_SINGLES) + forms.merge!(PLURAL_SINGLES) end def get_plural_form(locale : String) : PluralForms @@ -170,7 +170,7 @@ module I18next::Plurals locale = locale.split('-')[0] end - return self.forms[locale] if self.forms[locale]? + return forms[locale] if forms[locale]? # If nothing was found, then use the most common form, i.e # one singular and one plural, as in english. Not perfect, diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr index 2796a8dc6..a13db1fc8 100644 --- a/src/invidious/helpers/serialized_yt_data.cr +++ b/src/invidious/helpers/serialized_yt_data.cr @@ -28,19 +28,19 @@ struct SearchVideo property badges : VideoBadges def to_xml(auto_generated, query_params, xml : XML::Builder) - query_params["v"] = self.id + query_params["v"] = id xml.element("entry") do - xml.element("id") { xml.text "yt:video:#{self.id}" } - xml.element("yt:videoId") { xml.text self.id } - xml.element("yt:channelId") { xml.text self.ucid } - xml.element("title") { xml.text self.title } + xml.element("id") { xml.text "yt:video:#{id}" } + xml.element("yt:videoId") { xml.text id } + xml.element("yt:channelId") { xml.text ucid } + xml.element("title") { xml.text title } xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}") xml.element("author") do if auto_generated - xml.element("name") { xml.text self.author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } + xml.element("name") { xml.text author } + xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } else xml.element("name") { xml.text author } xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } @@ -50,24 +50,24 @@ struct SearchVideo xml.element("content", type: "xhtml") do xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do - xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg") + xml.element("img", src: "#{HOST_URL}/vi/#{id}/mqdefault.jpg") end - xml.element("p", style: "word-break:break-word;white-space:pre-wrap") { xml.text html_to_content(self.description_html) } + xml.element("p", style: "word-break:break-word;white-space:pre-wrap") { xml.text html_to_content(description_html) } end end - xml.element("published") { xml.text self.published.to_s("%Y-%m-%dT%H:%M:%S%:z") } + xml.element("published") { xml.text published.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("media:group") do - xml.element("media:title") { xml.text self.title } - xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg", + xml.element("media:title") { xml.text title } + xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{id}/mqdefault.jpg", width: "320", height: "180") - xml.element("media:description") { xml.text html_to_content(self.description_html) } + xml.element("media:description") { xml.text html_to_content(description_html) } end xml.element("media:community") do - xml.element("media:statistics", views: self.views) + xml.element("media:statistics", views: views) end end end @@ -81,13 +81,13 @@ struct SearchVideo def to_json(locale : String?, json : JSON::Builder) json.object do json.field "type", "video" - json.field "title", self.title - json.field "videoId", self.id + json.field "title", title + json.field "videoId", id - json.field "author", self.author - json.field "authorId", self.ucid - json.field "authorUrl", "/channel/#{self.ucid}" - json.field "authorVerified", self.author_verified + json.field "author", author + json.field "authorId", ucid + json.field "authorUrl", "/channel/#{ucid}" + json.field "authorVerified", author_verified author_thumbnail = self.author_thumbnail @@ -108,31 +108,31 @@ struct SearchVideo end json.field "videoThumbnails" do - Invidious::JSONify::APIv1.thumbnails(json, self.id) + Invidious::JSONify::APIv1.thumbnails(json, id) end - json.field "description", html_to_content(self.description_html) - json.field "descriptionHtml", self.description_html + json.field "description", html_to_content(description_html) + json.field "descriptionHtml", description_html - json.field "viewCount", self.views - json.field "viewCountText", translate_count(locale, "generic_views_count", self.views, NumberFormatting::Short) - json.field "published", self.published.to_unix - json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale)) - json.field "lengthSeconds", self.length_seconds - json.field "liveNow", self.badges.live_now? - json.field "premium", self.badges.premium? - json.field "isUpcoming", self.upcoming? + json.field "viewCount", views + json.field "viewCountText", translate_count(locale, "generic_views_count", views, NumberFormatting::Short) + json.field "published", published.to_unix + json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale)) + json.field "lengthSeconds", length_seconds + json.field "liveNow", badges.live_now? + json.field "premium", badges.premium? + json.field "isUpcoming", upcoming? - if self.premiere_timestamp - json.field "premiereTimestamp", self.premiere_timestamp.try &.to_unix + if premiere_timestamp + json.field "premiereTimestamp", premiere_timestamp.try &.to_unix end - json.field "isNew", self.badges.new? - json.field "is4k", self.badges.four_k? - json.field "is8k", self.badges.eight_k? - json.field "isVr180", self.badges.vr180? - json.field "isVr360", self.badges.vr360? - json.field "is3d", self.badges.three_d? - json.field "hasCaptions", self.badges.closed_captions? + json.field "isNew", badges.new? + json.field "is4k", badges.four_k? + json.field "is8k", badges.eight_k? + json.field "isVr180", badges.vr180? + json.field "isVr360", badges.vr360? + json.field "is3d", badges.three_d? + json.field "hasCaptions", badges.closed_captions? end end @@ -175,20 +175,20 @@ struct SearchPlaylist def to_json(locale : String?, json : JSON::Builder) json.object do json.field "type", "playlist" - json.field "title", self.title - json.field "playlistId", self.id - json.field "playlistThumbnail", self.thumbnail + json.field "title", title + json.field "playlistId", id + json.field "playlistThumbnail", thumbnail - json.field "author", self.author - json.field "authorId", self.ucid - json.field "authorUrl", "/channel/#{self.ucid}" + json.field "author", author + json.field "authorId", ucid + json.field "authorUrl", "/channel/#{ucid}" - json.field "authorVerified", self.author_verified + json.field "authorVerified", author_verified - json.field "videoCount", self.video_count + json.field "videoCount", video_count json.field "videos" do json.array do - self.videos.each do |video| + videos.each do |video| json.object do json.field "title", video.title json.field "videoId", video.id @@ -232,17 +232,17 @@ struct SearchChannel def to_json(locale : String?, json : JSON::Builder) json.object do json.field "type", "channel" - json.field "author", self.author - json.field "authorId", self.ucid - json.field "authorUrl", "/channel/#{self.ucid}" - json.field "authorVerified", self.author_verified + json.field "author", author + json.field "authorId", ucid + json.field "authorUrl", "/channel/#{ucid}" + json.field "authorVerified", author_verified json.field "authorThumbnails" do json.array do qualities = {32, 48, 76, 100, 176, 512} qualities.each do |quality| json.object do - json.field "url", self.author_thumbnail.gsub(/=s\d+/, "=s#{quality}") + json.field "url", author_thumbnail.gsub(/=s\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end @@ -250,13 +250,13 @@ struct SearchChannel end end - json.field "autoGenerated", self.auto_generated - json.field "subCount", self.subscriber_count - json.field "videoCount", self.video_count - json.field "channelHandle", self.channel_handle + json.field "autoGenerated", auto_generated + json.field "subCount", subscriber_count + json.field "videoCount", video_count + json.field "channelHandle", channel_handle - json.field "description", html_to_content(self.description_html) - json.field "descriptionHtml", self.description_html + json.field "description", html_to_content(description_html) + json.field "descriptionHtml", description_html end end @@ -283,10 +283,10 @@ struct SearchHashtag def to_json(locale : String?, json : JSON::Builder) json.object do json.field "type", "hashtag" - json.field "title", self.title - json.field "url", self.url - json.field "videoCount", self.video_count - json.field "channelCount", self.channel_count + json.field "title", title + json.field "url", url + json.field "videoCount", video_count + json.field "channelCount", channel_count end end end @@ -352,10 +352,10 @@ class Category def to_json(locale : String?, json : JSON::Builder) json.object do json.field "type", "category" - json.field "title", self.title + json.field "title", title json.field "contents" do json.array do - self.contents.each do |item| + contents.each do |item| item.to_json(locale, json) end end diff --git a/src/invidious/helpers/webvtt.cr b/src/invidious/helpers/webvtt.cr index 260d250fa..777f05bf1 100644 --- a/src/invidious/helpers/webvtt.cr +++ b/src/invidious/helpers/webvtt.cr @@ -20,7 +20,7 @@ module WebVTT # Writes an vtt cue with the specified time stamp and contents def cue(start_time : Time::Span, end_time : Time::Span, text : String) timestamp(start_time, end_time) - @io << self.escape(text) + @io << escape(text) @io << "\n\n" end diff --git a/src/invidious/jobs/instance_refresh_job.cr b/src/invidious/jobs/instance_refresh_job.cr index cb4280b96..6e90c9e68 100644 --- a/src/invidious/jobs/instance_refresh_job.cr +++ b/src/invidious/jobs/instance_refresh_job.cr @@ -25,7 +25,7 @@ class Invidious::Jobs::InstanceListRefreshJob < Invidious::Jobs::BaseJob # - Is it an instance with a good uptime? # - Is it an updated instance? private def refresh_instances - raw_instance_list = self.fetch_instances + raw_instance_list = fetch_instances filtered_instance_list = [] of Tuple(String, String) raw_instance_list.each do |instance_data| diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index ff9ea70ac..5867698ec 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -13,10 +13,10 @@ module Invidious::JSONify::APIv1 json.field "error", video.info["reason"] if video.info["reason"]? json.field "videoThumbnails" do - self.thumbnails(json, video.id) + thumbnails(json, video.id) end json.field "storyboards" do - self.storyboards(json, video.id, video.storyboards) + storyboards(json, video.id, video.storyboards) end json.field "description", video.description @@ -241,7 +241,7 @@ module Invidious::JSONify::APIv1 json.field "videoId", rv["id"] json.field "title", rv["title"] json.field "videoThumbnails" do - self.thumbnails(json, rv["id"]) + thumbnails(json, rv["id"]) end json.field "author", rv["author"] diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 7c584d153..9df0883e1 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -13,30 +13,30 @@ struct PlaylistVideo def to_xml(xml : XML::Builder) xml.element("entry") do - xml.element("id") { xml.text "yt:video:#{self.id}" } - xml.element("yt:videoId") { xml.text self.id } - xml.element("yt:channelId") { xml.text self.ucid } - xml.element("title") { xml.text self.title } - xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?v=#{self.id}") + xml.element("id") { xml.text "yt:video:#{id}" } + xml.element("yt:videoId") { xml.text id } + xml.element("yt:channelId") { xml.text ucid } + xml.element("title") { xml.text title } + xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?v=#{id}") xml.element("author") do - xml.element("name") { xml.text self.author } - xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } + xml.element("name") { xml.text author } + xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } end xml.element("content", type: "xhtml") do xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do - xml.element("a", href: "#{HOST_URL}/watch?v=#{self.id}") do - xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg") + xml.element("a", href: "#{HOST_URL}/watch?v=#{id}") do + xml.element("img", src: "#{HOST_URL}/vi/#{id}/mqdefault.jpg") end end end - xml.element("published") { xml.text self.published.to_s("%Y-%m-%dT%H:%M:%S%:z") } + xml.element("published") { xml.text published.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("media:group") do - xml.element("media:title") { xml.text self.title } - xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg", + xml.element("media:title") { xml.text title } + xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{id}/mqdefault.jpg", width: "320", height: "180") end end @@ -54,15 +54,15 @@ struct PlaylistVideo json.object do json.field "type", "video" - json.field "title", self.title - json.field "videoId", self.id + json.field "title", title + json.field "videoId", id - json.field "author", self.author - json.field "authorId", self.ucid - json.field "authorUrl", "/channel/#{self.ucid}" + json.field "author", author + json.field "authorId", ucid + json.field "authorUrl", "/channel/#{ucid}" json.field "videoThumbnails" do - Invidious::JSONify::APIv1.thumbnails(json, self.id) + Invidious::JSONify::APIv1.thumbnails(json, id) end if index @@ -72,8 +72,8 @@ struct PlaylistVideo json.field "index", self.index end - json.field "lengthSeconds", self.length_seconds - json.field "liveNow", self.live_now + json.field "lengthSeconds", length_seconds + json.field "liveNow", live_now end end @@ -101,14 +101,14 @@ struct Playlist def to_json(offset, json : JSON::Builder, video_id : String? = nil) json.object do json.field "type", "playlist" - json.field "title", self.title - json.field "playlistId", self.id - json.field "playlistThumbnail", self.thumbnail + json.field "title", title + json.field "playlistId", id + json.field "playlistThumbnail", thumbnail - json.field "author", self.author - json.field "authorId", self.ucid - json.field "authorUrl", "/channel/#{self.ucid}" - json.field "subtitle", self.subtitle + json.field "author", author + json.field "authorId", ucid + json.field "authorUrl", "/channel/#{ucid}" + json.field "subtitle", subtitle json.field "authorThumbnails" do json.array do @@ -116,7 +116,7 @@ struct Playlist qualities.each do |quality| json.object do - json.field "url", self.author_thumbnail.not_nil!.gsub(/=\d+/, "=s#{quality}") + json.field "url", author_thumbnail.not_nil!.gsub(/=\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end @@ -124,13 +124,13 @@ struct Playlist end end - json.field "description", self.description - json.field "descriptionHtml", self.description_html - json.field "videoCount", self.video_count + json.field "description", description + json.field "descriptionHtml", description_html + json.field "videoCount", video_count - json.field "viewCount", self.views - json.field "updated", self.updated.to_unix - json.field "isListed", self.privacy.public? + json.field "viewCount", views + json.field "updated", updated.to_unix + json.field "isListed", privacy.public? json.field "videos" do json.array do @@ -187,26 +187,26 @@ struct InvidiousPlaylist def to_json(offset, json : JSON::Builder, video_id : String? = nil) json.object do json.field "type", "invidiousPlaylist" - json.field "title", self.title - json.field "playlistId", self.id + json.field "title", title + json.field "playlistId", id - json.field "author", self.author - json.field "authorId", self.ucid + json.field "author", author + json.field "authorId", ucid json.field "authorUrl", nil json.field "authorThumbnails", [] of String - json.field "description", html_to_content(self.description_html) - json.field "descriptionHtml", self.description_html - json.field "videoCount", self.video_count + json.field "description", html_to_content(description_html) + json.field "descriptionHtml", description_html + json.field "videoCount", video_count - json.field "viewCount", self.views - json.field "updated", self.updated.to_unix - json.field "isListed", self.privacy.public? + json.field "viewCount", views + json.field "updated", updated.to_unix + json.field "isListed", privacy.public? json.field "videos" do json.array do if (!offset || offset == 0) && !video_id.nil? - index = Invidious::Database::PlaylistVideos.select_index(self.id, video_id) + index = Invidious::Database::PlaylistVideos.select_index(id, video_id) offset = self.index.index(index) || 0 end @@ -227,7 +227,7 @@ struct InvidiousPlaylist def thumbnail # TODO: Get playlist thumbnail from playlist data rather than first video - @thumbnail_id ||= Invidious::Database::PlaylistVideos.select_one_id(self.id, self.index) || "-----------" + @thumbnail_id ||= Invidious::Database::PlaylistVideos.select_one_id(id, index) || "-----------" "/vi/#{@thumbnail_id}/mqdefault.jpg" end @@ -244,7 +244,7 @@ struct InvidiousPlaylist end def description_html - HTML.escape(self.description) + HTML.escape(description) end end diff --git a/src/invidious/routes/api/v1/channels.cr b/src/invidious/routes/api/v1/channels.cr index 503b8c051..f7658126e 100644 --- a/src/invidious/routes/api/v1/channels.cr +++ b/src/invidious/routes/api/v1/channels.cr @@ -137,7 +137,7 @@ module Invidious::Routes::API::V1::Channels env.params.query.delete("sort_by") if env.params.query.has_key?("sort_by") env.params.query.delete("continuation") if env.params.query.has_key?("continuation") - return self.videos(env) + return videos(env) end def self.videos(env) diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr index f785de183..696132341 100644 --- a/src/invidious/routes/channels.cr +++ b/src/invidious/routes/channels.cr @@ -8,11 +8,11 @@ module Invidious::Routes::Channels end def self.home(env) - self.videos(env) + videos(env) end def self.videos(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -64,7 +64,7 @@ module Invidious::Routes::Channels end def self.shorts(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -99,7 +99,7 @@ module Invidious::Routes::Channels end def self.streams(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -134,7 +134,7 @@ module Invidious::Routes::Channels end def self.playlists(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -158,7 +158,7 @@ module Invidious::Routes::Channels end def self.podcasts(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -178,7 +178,7 @@ module Invidious::Routes::Channels end def self.releases(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -198,7 +198,7 @@ module Invidious::Routes::Channels end def self.courses(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -220,7 +220,7 @@ module Invidious::Routes::Channels def self.community(env) return env.redirect env.request.path.sub("posts", "community") if env.request.path.split("/").last == "posts" - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) if !data.is_a?(Tuple) return data end @@ -298,7 +298,7 @@ module Invidious::Routes::Channels end def self.channels(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) return data if !data.is_a?(Tuple) locale, user, subscriptions, continuation, ucid, channel = data @@ -318,7 +318,7 @@ module Invidious::Routes::Channels end def self.about(env) - data = self.fetch_basic_information(env) + data = fetch_basic_information(env) if !data.is_a?(Tuple) return data end diff --git a/src/invidious/routes/companion.cr b/src/invidious/routes/companion.cr index 811393aba..23235bd84 100644 --- a/src/invidious/routes/companion.cr +++ b/src/invidious/routes/companion.cr @@ -9,7 +9,7 @@ module Invidious::Routes::Companion begin COMPANION_POOL.client do |wrapper| wrapper.client.get(url, env.request.headers) do |resp| - return self.proxy_companion(env, resp) + return proxy_companion(env, resp) end end rescue ex @@ -26,7 +26,7 @@ module Invidious::Routes::Companion begin COMPANION_POOL.client do |wrapper| wrapper.client.post(url, env.request.headers, env.request.body) do |resp| - return self.proxy_companion(env, resp) + return proxy_companion(env, resp) end end rescue ex @@ -42,7 +42,7 @@ module Invidious::Routes::Companion begin COMPANION_POOL.client do |wrapper| wrapper.client.options(url, env.request.headers) do |resp| - return self.proxy_companion(env, resp) + return proxy_companion(env, resp) end end rescue ex diff --git a/src/invidious/routes/images.cr b/src/invidious/routes/images.cr index 51d85dfec..83df60432 100644 --- a/src/invidious/routes/images.cr +++ b/src/invidious/routes/images.cr @@ -13,7 +13,7 @@ module Invidious::Routes::Images begin GGPHT_POOL.client &.get(url, headers) do |resp| - return self.proxy_image(env, resp) + return proxy_image(env, resp) end rescue ex end @@ -44,7 +44,7 @@ module Invidious::Routes::Images begin get_ytimg_pool(authority).client &.get(url, headers) do |resp| env.response.headers["Connection"] = "close" - return self.proxy_image(env, resp) + return proxy_image(env, resp) end rescue ex end @@ -66,7 +66,7 @@ module Invidious::Routes::Images begin get_ytimg_pool("i9").client &.get(url, headers) do |resp| - return self.proxy_image(env, resp) + return proxy_image(env, resp) end rescue ex end @@ -128,7 +128,7 @@ module Invidious::Routes::Images begin get_ytimg_pool("i").client &.get(url, headers) do |resp| - return self.proxy_image(env, resp) + return proxy_image(env, resp) end rescue ex end diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index 684b578f8..b9967cf55 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -42,11 +42,11 @@ module Invidious::Routing end {% end %} - self.register_image_routes - self.register_api_v1_routes - self.register_api_manifest_routes - self.register_video_playback_routes - self.register_companion_routes + register_image_routes + register_api_v1_routes + register_api_manifest_routes + register_video_playback_routes + register_companion_routes end # ------------------- diff --git a/src/invidious/search/query.cr b/src/invidious/search/query.cr index 94a92e23d..fe3744f79 100644 --- a/src/invidious/search/query.cr +++ b/src/invidious/search/query.cr @@ -30,7 +30,7 @@ module Invidious::Search # Same as `empty_raw_query?`, but named for external use def empty? - return self.empty_raw_query? + return empty_raw_query? end # Getter for the query string. @@ -70,7 +70,7 @@ module Invidious::Search # Stop here if raw query is empty # NOTE: maybe raise in the future? - return if self.empty_raw_query? + return if empty_raw_query? # Specific handling case @type @@ -120,7 +120,7 @@ module Invidious::Search items = [] of SearchItem # Don't bother going further if search query is empty - return items if self.empty_raw_query? + return items if empty_raw_query? case @type when .regular?, .playlist? diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index f23317b3f..228dce334 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -73,7 +73,7 @@ struct Video end def live_now - return (self.video_type == VideoType::Livestream) + return (video_type == VideoType::Livestream) end def post_live_dvr @@ -124,11 +124,11 @@ struct Video def storyboards container = info.dig?("storyboards") || JSON::Any.new("{}") - return IV::Videos::Storyboard.from_yt_json(container, self.length_seconds) + return IV::Videos::Storyboard.from_yt_json(container, length_seconds) end def paid - return (self.reason || "").includes? "requires payment" + return (reason || "").includes? "requires payment" end def premium @@ -170,7 +170,7 @@ struct Video end def vr? : Bool? - return {"EQUIRECTANGULAR", "MESH"}.includes? self.projection_type + return {"EQUIRECTANGULAR", "MESH"}.includes? projection_type end def projection_type : String? diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 759f1ed32..056ba2c8b 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -64,7 +64,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = (item["videoRenderer"]? || item["gridVideoRenderer"]?) - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -192,7 +192,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = (item["channelRenderer"]? || item["gridChannelRenderer"]?) - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -255,7 +255,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["hashtagTileRenderer"]? - return self.parse(item_contents) + return parse(item_contents) end end @@ -308,7 +308,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["gridPlaylistRenderer"]? - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -352,7 +352,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["playlistRenderer"]? - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -415,7 +415,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["shelfRenderer"]? - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -484,7 +484,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item.dig?("itemSectionRenderer", "contents", 0) - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -513,7 +513,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item.dig?("richItemRenderer", "content") - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -546,7 +546,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["reelItemRenderer"]? - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -643,7 +643,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["lockupViewModel"]? - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -721,7 +721,7 @@ private module Parsers def process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["shortsLockupViewModel"]? - return self.parse(item_contents, author_fallback) + return parse(item_contents, author_fallback) end end @@ -778,7 +778,7 @@ private module Parsers module ContinuationItemRendererParser def self.process(item : JSON::Any, author_fallback : AuthorFallback) if item_contents = item["continuationItemRenderer"]? - return self.parse(item_contents) + return parse(item_contents) end end @@ -831,7 +831,7 @@ private module Extractors module YouTubeTabs def self.process(initial_data : InitialData) if target = initial_data["twoColumnBrowseResultsRenderer"]? - self.extract(target) + extract(target) end end @@ -853,7 +853,7 @@ private module Extractors contents.as_a.each do |item| if item_section_content = item.dig?("itemSectionRenderer", "contents") - raw_items += self.unpack_item_section(item_section_content) + raw_items += unpack_item_section(item_section_content) else raw_items << item end @@ -902,7 +902,7 @@ private module Extractors module SearchResults def self.process(initial_data : InitialData) if target = initial_data["twoColumnSearchResultsRenderer"]? - self.extract(target) + extract(target) end end @@ -936,11 +936,11 @@ private module Extractors module ContinuationContent def self.process(initial_data : InitialData) if target = initial_data["continuationContents"]? - self.extract(target) + extract(target) elsif target = initial_data["appendContinuationItemsAction"]? - self.extract(target) + extract(target) elsif target = initial_data["reloadContinuationItemsCommand"]? - self.extract(target) + extract(target) end end diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 6d6060ebf..5fd08b274 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -268,7 +268,7 @@ module YoutubeAPI # Convert to string, for logging purposes def to_s return { - client_type: self.name, + client_type: name, region: @region, }.to_s end @@ -356,11 +356,11 @@ module YoutubeAPI def browse(continuation : String, client_config : ClientConfig? = nil) # JSON Request data, required by the API data = { - "context" => self.make_context(client_config), + "context" => make_context(client_config), "continuation" => continuation, } - return self._post_json("/youtubei/v1/browse", data, client_config) + return _post_json("/youtubei/v1/browse", data, client_config) end # :ditto: @@ -373,7 +373,7 @@ module YoutubeAPI # JSON Request data, required by the API data = { "browseId" => browse_id, - "context" => self.make_context(client_config), + "context" => make_context(client_config), } # Append the additional parameters if those were provided @@ -382,7 +382,7 @@ module YoutubeAPI data["params"] = params end - return self._post_json("/youtubei/v1/browse", data, client_config) + return _post_json("/youtubei/v1/browse", data, client_config) end #################################################################### @@ -424,21 +424,21 @@ module YoutubeAPI def next(continuation : String, *, client_config : ClientConfig? = nil) # JSON Request data, required by the API data = { - "context" => self.make_context(client_config), + "context" => make_context(client_config), "continuation" => continuation, } - return self._post_json("/youtubei/v1/next", data, client_config) + return _post_json("/youtubei/v1/next", data, client_config) end # :ditto: def next(data : Hash, *, client_config : ClientConfig? = nil) # JSON Request data, required by the API data2 = data.merge({ - "context" => self.make_context(client_config), + "context" => make_context(client_config), }) - return self._post_json("/youtubei/v1/next", data2, client_config) + return _post_json("/youtubei/v1/next", data2, client_config) end # Allow a NamedTuple to be passed, too. @@ -461,7 +461,7 @@ module YoutubeAPI } if CONFIG.invidious_companion.present? - return self._post_invidious_companion("/youtubei/v1/player", data) + return _post_invidious_companion("/youtubei/v1/player", data) else return nil end @@ -497,11 +497,11 @@ module YoutubeAPI # def resolve_url(url : String, client_config : ClientConfig? = nil) data = { - "context" => self.make_context(nil), + "context" => make_context(nil), "url" => url, } - return self._post_json("/youtubei/v1/navigation/resolve_url", data, client_config) + return _post_json("/youtubei/v1/navigation/resolve_url", data, client_config) end #################################################################### @@ -526,11 +526,11 @@ module YoutubeAPI # JSON Request data, required by the API data = { "query" => search_query, - "context" => self.make_context(client_config), + "context" => make_context(client_config), "params" => params, } - return self._post_json("/youtubei/v1/search", data, client_config) + return _post_json("/youtubei/v1/search", data, client_config) end #################################################################### @@ -550,11 +550,11 @@ module YoutubeAPI client_config : ClientConfig? = nil, ) : Hash(String, JSON::Any) data = { - "context" => self.make_context(client_config), + "context" => make_context(client_config), "params" => params, } - return self._post_json("/youtubei/v1/get_transcript", data, client_config) + return _post_json("/youtubei/v1/get_transcript", data, client_config) end #################################################################### @@ -602,7 +602,7 @@ module YoutubeAPI status code #{response.status_code}. See \ https://docs.invidious.io/youtube-errors-explained/ for troubleshooting.") end - self._decompress(response.body_io, response.headers["Content-Encoding"]?) + _decompress(response.body_io, response.headers["Content-Encoding"]?) end end From 3a68d5aeb207538b9f815e3537489817ec9948fe Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:35:01 +0100 Subject: [PATCH 07/27] Fix `Style/RedundantNilInControlExpression` type of Ameba issues --- src/invidious/videos.cr | 2 +- src/invidious/videos/parser.cr | 6 +++--- src/invidious/yt_backend/extractors_utils.cr | 2 +- src/invidious/yt_backend/url_sanitizer.cr | 2 +- src/invidious/yt_backend/youtube_api.cr | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 228dce334..4f07f4bbd 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -149,7 +149,7 @@ struct Video def dash_manifest_url : String? 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 # See https://github.com/iv-org/invidious/issues/4186 diff --git a/src/invidious/videos/parser.cr b/src/invidious/videos/parser.cr index 8114ad684..87974e686 100644 --- a/src/invidious/videos/parser.cr +++ b/src/invidious/videos/parser.cr @@ -7,7 +7,7 @@ require "json" # TODO: "compactRadioRenderer" (Mix) and # TODO: Use a proper struct/class instead of a hacky JSON object 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 # screen rendered has a full text version ("42:40") @@ -57,7 +57,7 @@ def extract_video_info(video_id : String) player_response = YoutubeAPI.player(video_id: video_id) if player_response.nil? - return nil + return end playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s @@ -147,7 +147,7 @@ def try_fetch_streaming_data(id : String, client_config : YoutubeAPI::ClientConf elsif playability_status == "OK" return response else - return nil + return end end diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index c83a2de5a..21c958ace 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -17,7 +17,7 @@ # another nil will be returned. def extract_text(item : JSON::Any?) : String? if item.nil? - return nil + return end if text_container = item["simpleText"]? diff --git a/src/invidious/yt_backend/url_sanitizer.cr b/src/invidious/yt_backend/url_sanitizer.cr index d539dadbb..856a18d68 100644 --- a/src/invidious/yt_backend/url_sanitizer.cr +++ b/src/invidious/yt_backend/url_sanitizer.cr @@ -46,7 +46,7 @@ module UrlSanitizer when "results", "search" return :search else # hashtag, post, trending, brand URLs, etc.. - return nil + return end end diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 5fd08b274..fcee06040 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -463,7 +463,7 @@ module YoutubeAPI if CONFIG.invidious_companion.present? return _post_invidious_companion("/youtubei/v1/player", data) else - return nil + return end end From 456b50a5e22497de8c83433091076609f0ad4646 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:35:43 +0100 Subject: [PATCH 08/27] Fix `Layout/TrailingWhitespace` type of Ameba issues --- src/invidious/views/components/player.ecr | 2 +- src/invidious/views/template.ecr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index 26ba65f74..fbd472e0e 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -25,7 +25,7 @@ audio_streams.each_with_index do |fmt, i| src_url = "/latest_version?id=#{video.id}&itag=#{fmt["itag"]}" src_url += "&local=true" if params.local - src_url = invidious_companion.public_url.to_s + src_url + + src_url = invidious_companion.public_url.to_s + src_url + "&check=#{invidious_companion_check_id}" if (invidious_companion) bitrate = fmt["bitrate"] diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 0e0f2e16f..40f5544fe 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -159,7 +159,7 @@ <% end %> @ <%= CURRENT_BRANCH %> <% if CURRENT_TAG != "" %> - ( + ( <% if CONFIG.modified_source_code_url %> <%= CURRENT_TAG %> <% else %> From dd185c9379de7c7b46d186118bd8ef4eb53fbde5 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:36:07 +0100 Subject: [PATCH 09/27] Fix `Layout/TrailingBlankLines` type of Ameba issues --- src/invidious/views/components/video-context-buttons.ecr | 2 +- src/invidious/views/post.ecr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/views/components/video-context-buttons.ecr b/src/invidious/views/components/video-context-buttons.ecr index 22458a030..d8aacdca7 100644 --- a/src/invidious/views/components/video-context-buttons.ecr +++ b/src/invidious/views/components/video-context-buttons.ecr @@ -18,4 +18,4 @@ <% end %> - \ No newline at end of file + diff --git a/src/invidious/views/post.ecr b/src/invidious/views/post.ecr index f644d634c..a27f44611 100644 --- a/src/invidious/views/post.ecr +++ b/src/invidious/views/post.ecr @@ -45,4 +45,4 @@ %> - \ No newline at end of file + From b5b187ad8865ee78668a112012e594d6e0ebc20c Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:36:58 +0100 Subject: [PATCH 10/27] Fix `Style/PercentLiteralDelimiters` type of Ameba issues --- src/invidious/helpers/handlers.cr | 8 ++++---- src/invidious/helpers/logger.cr | 2 +- src/invidious/helpers/tokens.cr | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/invidious/helpers/handlers.cr b/src/invidious/helpers/handlers.cr index ca0556568..2d349993c 100644 --- a/src/invidious/helpers/handlers.cr +++ b/src/invidious/helpers/handlers.cr @@ -20,7 +20,7 @@ module HTTP::Handler end 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 }} {% end %} @@ -44,7 +44,7 @@ class Kemal::RouteHandler end 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 }} {% end %} @@ -72,7 +72,7 @@ class FilteredCompressHandler < HTTP::CompressHandler end 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 }} {% end %} @@ -121,7 +121,7 @@ class AuthHandler < Kemal::Handler end 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 }} {% end %} exclude ["/api/v1/auth/notifications"], "GET" diff --git a/src/invidious/helpers/logger.cr b/src/invidious/helpers/logger.cr index bce10bb3e..5b06612ea 100644 --- a/src/invidious/helpers/logger.cr +++ b/src/invidious/helpers/logger.cr @@ -55,7 +55,7 @@ class Invidious::LogHandler < Kemal::BaseLogHandler 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) if LogLevel::{{ level.id.capitalize }} >= @level puts("#{Time.utc} [{{ level.id }}] #{message}".colorize(color(LogLevel::{{ level.id.capitalize }}))) diff --git a/src/invidious/helpers/tokens.cr b/src/invidious/helpers/tokens.cr index a44988cd3..926863323 100644 --- a/src/invidious/helpers/tokens.cr +++ b/src/invidious/helpers/tokens.cr @@ -116,7 +116,7 @@ def scope_includes_scope(scope, subset) subset_endpoint = subset_endpoint.downcase if methods.empty? - methods = %w(GET POST PUT HEAD DELETE PATCH OPTIONS) + methods = %w[GET POST PUT HEAD DELETE PATCH OPTIONS] end if methods & subset_methods != subset_methods From e5a1131665c1f29bd1076a07c42989a5b1b5599f Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:37:34 +0100 Subject: [PATCH 11/27] Fix `Performance/ChainedCallWithNoBang` type of Ameba issues --- src/invidious/routes/api/v1/authenticated.cr | 2 +- src/invidious/yt_backend/youtube_api.cr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index a35d2f2b2..d56befa3a 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -482,7 +482,7 @@ module Invidious::Routes::API::V1::Authenticated env.response.content_type = "text/event-stream" raw_topics = env.params.body["topics"]? || env.params.query["topics"]? - topics = raw_topics.try &.split(",").uniq.first(1000) + topics = raw_topics.try &.split(",").uniq!.first(1000) topics ||= [] of String create_notification_stream(env, topics, CONNECTION_CHANNEL) diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index fcee06040..cc2bf0998 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -685,7 +685,7 @@ module YoutubeAPI # Multiple encodings can be combined, and are listed in the order # in which they were applied. E.g: "deflate, gzip" means that the # content must be first "gunzipped", then "defated". - encodings.split(',').reverse.each do |enc| + encodings.split(',').reverse!.each do |enc| case enc.strip(' ') when "gzip" body_io = Compress::Gzip::Reader.new(body_io, sync_close: true) From 2112ee674e625f6e1e1ba88a54f94659a8924e0b Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:49:54 +0100 Subject: [PATCH 12/27] Fix `Style/HeredocIndent` type of Ameba issues --- spec/invidious/user/imports_spec.cr | 30 ++-- src/invidious/database/annotations.cr | 4 +- src/invidious/database/channels.cr | 22 +-- .../migrations/0001_create_channels_table.cr | 34 ++--- .../migrations/0002_create_videos_table.cr | 30 ++-- .../0003_create_channel_videos_table.cr | 44 +++--- .../migrations/0004_create_users_table.cr | 42 +++--- .../0005_create_session_ids_table.cr | 30 ++-- .../migrations/0006_create_nonces_table.cr | 28 ++-- .../0007_create_annotations_table.cr | 18 +-- .../migrations/0008_create_playlists_table.cr | 46 +++--- .../0009_create_playlist_videos_table.cr | 32 ++--- .../migrations/0010_make_videos_unlogged.cr | 4 +- src/invidious/database/migrator.cr | 2 +- src/invidious/database/nonces.cr | 8 +- src/invidious/database/playlists.cr | 42 +++--- src/invidious/database/sessions.cr | 12 +- src/invidious/database/statistics.cr | 8 +- src/invidious/database/users.cr | 40 +++--- src/invidious/database/videos.cr | 10 +- src/invidious/frontend/comments_reddit.cr | 44 +++--- src/invidious/frontend/comments_youtube.cr | 132 +++++++++--------- src/invidious/helpers/errors.cr | 14 +- src/invidious/mixes.cr | 26 ++-- src/invidious/playlists.cr | 26 ++-- src/invidious/user/captcha.cr | 40 +++--- 26 files changed, 384 insertions(+), 384 deletions(-) diff --git a/spec/invidious/user/imports_spec.cr b/spec/invidious/user/imports_spec.cr index 762ce0d89..58b5d4aab 100644 --- a/spec/invidious/user/imports_spec.cr +++ b/spec/invidious/user/imports_spec.cr @@ -8,21 +8,21 @@ end def csv_sample return <<-CSV - Kanal-ID,Kanal-URL,Kanaltitel - UC0hHW5Y08ggq-9kbrGgWj0A,http://www.youtube.com/channel/UC0hHW5Y08ggq-9kbrGgWj0A,Matias Marolla - UC0vBXGSyV14uvJ4hECDOl0Q,http://www.youtube.com/channel/UC0vBXGSyV14uvJ4hECDOl0Q,Techquickie - UC1sELGmy5jp5fQUugmuYlXQ,http://www.youtube.com/channel/UC1sELGmy5jp5fQUugmuYlXQ,Minecraft - UC9kFnwdCRrX7oTjqKd6-tiQ,http://www.youtube.com/channel/UC9kFnwdCRrX7oTjqKd6-tiQ,LUMOX - Topic - UCBa659QWEk1AI4Tg--mrJ2A,http://www.youtube.com/channel/UCBa659QWEk1AI4Tg--mrJ2A,Tom Scott - UCGu6_XQ64rXPR6nuitMQE_A,http://www.youtube.com/channel/UCGu6_XQ64rXPR6nuitMQE_A,Callcenter Fun - UCGwu0nbY2wSkW8N-cghnLpA,http://www.youtube.com/channel/UCGwu0nbY2wSkW8N-cghnLpA,Jaiden Animations - UCQ0OvZ54pCFZwsKxbltg_tg,http://www.youtube.com/channel/UCQ0OvZ54pCFZwsKxbltg_tg,Methos - UCRE6itj4Jte4manQEu3Y7OA,http://www.youtube.com/channel/UCRE6itj4Jte4manQEu3Y7OA,Chipflake - UCRLc6zsv_d0OEBO8OOkz-DA,http://www.youtube.com/channel/UCRLc6zsv_d0OEBO8OOkz-DA,Kegy - UCSl5Uxu2LyaoAoMMGp6oTJA,http://www.youtube.com/channel/UCSl5Uxu2LyaoAoMMGp6oTJA,Atomic Shrimp - UCXuqSBlHAE6Xw-yeJA0Tunw,http://www.youtube.com/channel/UCXuqSBlHAE6Xw-yeJA0Tunw,Linus Tech Tips - UCZ5XnGb-3t7jCkXdawN2tkA,http://www.youtube.com/channel/UCZ5XnGb-3t7jCkXdawN2tkA,Discord - CSV + Kanal-ID,Kanal-URL,Kanaltitel + UC0hHW5Y08ggq-9kbrGgWj0A,http://www.youtube.com/channel/UC0hHW5Y08ggq-9kbrGgWj0A,Matias Marolla + UC0vBXGSyV14uvJ4hECDOl0Q,http://www.youtube.com/channel/UC0vBXGSyV14uvJ4hECDOl0Q,Techquickie + UC1sELGmy5jp5fQUugmuYlXQ,http://www.youtube.com/channel/UC1sELGmy5jp5fQUugmuYlXQ,Minecraft + UC9kFnwdCRrX7oTjqKd6-tiQ,http://www.youtube.com/channel/UC9kFnwdCRrX7oTjqKd6-tiQ,LUMOX - Topic + UCBa659QWEk1AI4Tg--mrJ2A,http://www.youtube.com/channel/UCBa659QWEk1AI4Tg--mrJ2A,Tom Scott + UCGu6_XQ64rXPR6nuitMQE_A,http://www.youtube.com/channel/UCGu6_XQ64rXPR6nuitMQE_A,Callcenter Fun + UCGwu0nbY2wSkW8N-cghnLpA,http://www.youtube.com/channel/UCGwu0nbY2wSkW8N-cghnLpA,Jaiden Animations + UCQ0OvZ54pCFZwsKxbltg_tg,http://www.youtube.com/channel/UCQ0OvZ54pCFZwsKxbltg_tg,Methos + UCRE6itj4Jte4manQEu3Y7OA,http://www.youtube.com/channel/UCRE6itj4Jte4manQEu3Y7OA,Chipflake + UCRLc6zsv_d0OEBO8OOkz-DA,http://www.youtube.com/channel/UCRLc6zsv_d0OEBO8OOkz-DA,Kegy + UCSl5Uxu2LyaoAoMMGp6oTJA,http://www.youtube.com/channel/UCSl5Uxu2LyaoAoMMGp6oTJA,Atomic Shrimp + UCXuqSBlHAE6Xw-yeJA0Tunw,http://www.youtube.com/channel/UCXuqSBlHAE6Xw-yeJA0Tunw,Linus Tech Tips + UCZ5XnGb-3t7jCkXdawN2tkA,http://www.youtube.com/channel/UCZ5XnGb-3t7jCkXdawN2tkA,Discord + CSV end Spectator.describe Invidious::User::Import do diff --git a/src/invidious/database/annotations.cr b/src/invidious/database/annotations.cr index 037494730..f1659509a 100644 --- a/src/invidious/database/annotations.cr +++ b/src/invidious/database/annotations.cr @@ -8,7 +8,7 @@ module Invidious::Database::Annotations INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING - SQL + SQL PG_DB.exec(request, id, annotations) end @@ -17,7 +17,7 @@ module Invidious::Database::Annotations request = <<-SQL SELECT * FROM annotations WHERE id = $1 - SQL + SQL return PG_DB.query_one?(request, id, as: Annotation) end diff --git a/src/invidious/database/channels.cr b/src/invidious/database/channels.cr index df44e485d..3e7f480ce 100644 --- a/src/invidious/database/channels.cr +++ b/src/invidious/database/channels.cr @@ -16,13 +16,13 @@ module Invidious::Database::Channels request = <<-SQL INSERT INTO channels VALUES (#{arg_array(channel_array)}) - SQL + SQL if update_on_conflict request += <<-SQL ON CONFLICT (id) DO UPDATE SET author = $2, updated = $3 - SQL + SQL end PG_DB.exec(request, args: channel_array) @@ -37,7 +37,7 @@ module Invidious::Database::Channels UPDATE channels SET updated = now(), author = $1, deleted = false WHERE id = $2 - SQL + SQL PG_DB.exec(request, author, id) end @@ -47,7 +47,7 @@ module Invidious::Database::Channels UPDATE channels SET subscribed = now() WHERE id = $1 - SQL + SQL PG_DB.exec(request, id) end @@ -57,7 +57,7 @@ module Invidious::Database::Channels UPDATE channels SET updated = now(), deleted = true WHERE id = $1 - SQL + SQL PG_DB.exec(request, id) end @@ -70,7 +70,7 @@ module Invidious::Database::Channels request = <<-SQL SELECT * FROM channels WHERE id = $1 - SQL + SQL return PG_DB.query_one?(request, id, as: InvidiousChannel) end @@ -81,7 +81,7 @@ module Invidious::Database::Channels request = <<-SQL SELECT * FROM channels WHERE id = ANY($1) - SQL + SQL return PG_DB.query_all(request, ids, as: InvidiousChannel) end @@ -112,7 +112,7 @@ module Invidious::Database::ChannelVideos SET title = $2, published = $3, updated = $4, ucid = $5, author = $6, length_seconds = $7, live_now = $8, #{last_items} RETURNING (xmax=0) AS was_insert - SQL + SQL return PG_DB.query_one(request, *video.to_tuple, as: Bool) end @@ -128,7 +128,7 @@ module Invidious::Database::ChannelVideos SELECT * FROM channel_videos WHERE id = ANY($1) ORDER BY published DESC - SQL + SQL return PG_DB.query_all(request, ids, as: ChannelVideo) end @@ -139,7 +139,7 @@ module Invidious::Database::ChannelVideos WHERE ucid = $1 AND published > $2 ORDER BY published DESC LIMIT 15 - SQL + SQL return PG_DB.query_all(request, ucid, since, as: ChannelVideo) end @@ -151,7 +151,7 @@ module Invidious::Database::ChannelVideos WHERE ucid IN (SELECT channel FROM (SELECT UNNEST(subscriptions) AS channel FROM users) AS d GROUP BY channel ORDER BY COUNT(channel) DESC LIMIT 40) ORDER BY ucid, published DESC - SQL + SQL PG_DB.query_all(request, as: ChannelVideo) end diff --git a/src/invidious/database/migrations/0001_create_channels_table.cr b/src/invidious/database/migrations/0001_create_channels_table.cr index a1362bcf8..df7e31a12 100644 --- a/src/invidious/database/migrations/0001_create_channels_table.cr +++ b/src/invidious/database/migrations/0001_create_channels_table.cr @@ -4,27 +4,27 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.channels - ( - id text NOT NULL, - author text, - updated timestamp with time zone, - deleted boolean, - subscribed timestamp with time zone, - CONSTRAINT channels_id_key UNIQUE (id) - ); - SQL + CREATE TABLE IF NOT EXISTS public.channels + ( + id text NOT NULL, + author text, + updated timestamp with time zone, + deleted boolean, + subscribed timestamp with time zone, + CONSTRAINT channels_id_key UNIQUE (id) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.channels TO current_user; - SQL + GRANT ALL ON TABLE public.channels TO current_user; + SQL conn.exec <<-SQL - CREATE INDEX IF NOT EXISTS channels_id_idx - ON public.channels - USING btree - (id COLLATE pg_catalog."default"); - SQL + CREATE INDEX IF NOT EXISTS channels_id_idx + ON public.channels + USING btree + (id COLLATE pg_catalog."default"); + SQL end end end diff --git a/src/invidious/database/migrations/0002_create_videos_table.cr b/src/invidious/database/migrations/0002_create_videos_table.cr index c2ac84f8f..1d0f5afb6 100644 --- a/src/invidious/database/migrations/0002_create_videos_table.cr +++ b/src/invidious/database/migrations/0002_create_videos_table.cr @@ -4,25 +4,25 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE UNLOGGED TABLE IF NOT EXISTS public.videos - ( - id text NOT NULL, - info text, - updated timestamp with time zone, - CONSTRAINT videos_pkey PRIMARY KEY (id) - ); - SQL + CREATE UNLOGGED TABLE IF NOT EXISTS public.videos + ( + id text NOT NULL, + info text, + updated timestamp with time zone, + CONSTRAINT videos_pkey PRIMARY KEY (id) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.videos TO current_user; - SQL + GRANT ALL ON TABLE public.videos TO current_user; + SQL conn.exec <<-SQL - CREATE UNIQUE INDEX IF NOT EXISTS id_idx - ON public.videos - USING btree - (id COLLATE pg_catalog."default"); - SQL + CREATE UNIQUE INDEX IF NOT EXISTS id_idx + ON public.videos + USING btree + (id COLLATE pg_catalog."default"); + SQL end end end diff --git a/src/invidious/database/migrations/0003_create_channel_videos_table.cr b/src/invidious/database/migrations/0003_create_channel_videos_table.cr index c9b62e4c6..e4023fefe 100644 --- a/src/invidious/database/migrations/0003_create_channel_videos_table.cr +++ b/src/invidious/database/migrations/0003_create_channel_videos_table.cr @@ -4,32 +4,32 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.channel_videos - ( - id text NOT NULL, - title text, - published timestamp with time zone, - updated timestamp with time zone, - ucid text, - author text, - length_seconds integer, - live_now boolean, - premiere_timestamp timestamp with time zone, - views bigint, - CONSTRAINT channel_videos_id_key UNIQUE (id) - ); - SQL + CREATE TABLE IF NOT EXISTS public.channel_videos + ( + id text NOT NULL, + title text, + published timestamp with time zone, + updated timestamp with time zone, + ucid text, + author text, + length_seconds integer, + live_now boolean, + premiere_timestamp timestamp with time zone, + views bigint, + CONSTRAINT channel_videos_id_key UNIQUE (id) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.channel_videos TO current_user; - SQL + GRANT ALL ON TABLE public.channel_videos TO current_user; + SQL conn.exec <<-SQL - CREATE INDEX IF NOT EXISTS channel_videos_ucid_idx - ON public.channel_videos - USING btree - (ucid COLLATE pg_catalog."default"); - SQL + CREATE INDEX IF NOT EXISTS channel_videos_ucid_idx + ON public.channel_videos + USING btree + (ucid COLLATE pg_catalog."default"); + SQL end end end diff --git a/src/invidious/database/migrations/0004_create_users_table.cr b/src/invidious/database/migrations/0004_create_users_table.cr index a13ba15f0..3e561bc04 100644 --- a/src/invidious/database/migrations/0004_create_users_table.cr +++ b/src/invidious/database/migrations/0004_create_users_table.cr @@ -4,31 +4,31 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.users - ( - updated timestamp with time zone, - notifications text[], - subscriptions text[], - email text NOT NULL, - preferences text, - password text, - token text, - watched text[], - feed_needs_update boolean, - CONSTRAINT users_email_key UNIQUE (email) - ); - SQL + CREATE TABLE IF NOT EXISTS public.users + ( + updated timestamp with time zone, + notifications text[], + subscriptions text[], + email text NOT NULL, + preferences text, + password text, + token text, + watched text[], + feed_needs_update boolean, + CONSTRAINT users_email_key UNIQUE (email) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.users TO current_user; - SQL + GRANT ALL ON TABLE public.users TO current_user; + SQL conn.exec <<-SQL - CREATE UNIQUE INDEX IF NOT EXISTS email_unique_idx - ON public.users - USING btree - (lower(email) COLLATE pg_catalog."default"); - SQL + CREATE UNIQUE INDEX IF NOT EXISTS email_unique_idx + ON public.users + USING btree + (lower(email) COLLATE pg_catalog."default"); + SQL end end end diff --git a/src/invidious/database/migrations/0005_create_session_ids_table.cr b/src/invidious/database/migrations/0005_create_session_ids_table.cr index 13c2228d1..e760ad166 100644 --- a/src/invidious/database/migrations/0005_create_session_ids_table.cr +++ b/src/invidious/database/migrations/0005_create_session_ids_table.cr @@ -4,25 +4,25 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.session_ids - ( - id text NOT NULL, - email text, - issued timestamp with time zone, - CONSTRAINT session_ids_pkey PRIMARY KEY (id) - ); - SQL + CREATE TABLE IF NOT EXISTS public.session_ids + ( + id text NOT NULL, + email text, + issued timestamp with time zone, + CONSTRAINT session_ids_pkey PRIMARY KEY (id) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.session_ids TO current_user; - SQL + GRANT ALL ON TABLE public.session_ids TO current_user; + SQL conn.exec <<-SQL - CREATE INDEX IF NOT EXISTS session_ids_id_idx - ON public.session_ids - USING btree - (id COLLATE pg_catalog."default"); - SQL + CREATE INDEX IF NOT EXISTS session_ids_id_idx + ON public.session_ids + USING btree + (id COLLATE pg_catalog."default"); + SQL end end end diff --git a/src/invidious/database/migrations/0006_create_nonces_table.cr b/src/invidious/database/migrations/0006_create_nonces_table.cr index cf1229e16..c2ae7a873 100644 --- a/src/invidious/database/migrations/0006_create_nonces_table.cr +++ b/src/invidious/database/migrations/0006_create_nonces_table.cr @@ -4,24 +4,24 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.nonces - ( - nonce text, - expire timestamp with time zone, - CONSTRAINT nonces_id_key UNIQUE (nonce) - ); - SQL + CREATE TABLE IF NOT EXISTS public.nonces + ( + nonce text, + expire timestamp with time zone, + CONSTRAINT nonces_id_key UNIQUE (nonce) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.nonces TO current_user; - SQL + GRANT ALL ON TABLE public.nonces TO current_user; + SQL conn.exec <<-SQL - CREATE INDEX IF NOT EXISTS nonces_nonce_idx - ON public.nonces - USING btree - (nonce COLLATE pg_catalog."default"); - SQL + CREATE INDEX IF NOT EXISTS nonces_nonce_idx + ON public.nonces + USING btree + (nonce COLLATE pg_catalog."default"); + SQL end end end diff --git a/src/invidious/database/migrations/0007_create_annotations_table.cr b/src/invidious/database/migrations/0007_create_annotations_table.cr index dcecbc3b8..518e28860 100644 --- a/src/invidious/database/migrations/0007_create_annotations_table.cr +++ b/src/invidious/database/migrations/0007_create_annotations_table.cr @@ -4,17 +4,17 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.annotations - ( - id text NOT NULL, - annotations xml, - CONSTRAINT annotations_id_key UNIQUE (id) - ); - SQL + CREATE TABLE IF NOT EXISTS public.annotations + ( + id text NOT NULL, + annotations xml, + CONSTRAINT annotations_id_key UNIQUE (id) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.annotations TO current_user; - SQL + GRANT ALL ON TABLE public.annotations TO current_user; + SQL end end end diff --git a/src/invidious/database/migrations/0008_create_playlists_table.cr b/src/invidious/database/migrations/0008_create_playlists_table.cr index 6aa16e1a9..63901f61d 100644 --- a/src/invidious/database/migrations/0008_create_playlists_table.cr +++ b/src/invidious/database/migrations/0008_create_playlists_table.cr @@ -5,33 +5,33 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) if !privacy_type_exists?(conn) conn.exec <<-SQL - CREATE TYPE public.privacy AS ENUM - ( - 'Public', - 'Unlisted', - 'Private' - ); - SQL + CREATE TYPE public.privacy AS ENUM + ( + 'Public', + 'Unlisted', + 'Private' + ); + SQL end conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.playlists - ( - title text, - id text primary key, - author text, - description text, - video_count integer, - created timestamptz, - updated timestamptz, - privacy privacy, - index int8[] - ); - SQL + CREATE TABLE IF NOT EXISTS public.playlists + ( + title text, + id text primary key, + author text, + description text, + video_count integer, + created timestamptz, + updated timestamptz, + privacy privacy, + index int8[] + ); + SQL conn.exec <<-SQL - GRANT ALL ON public.playlists TO current_user; - SQL + GRANT ALL ON public.playlists TO current_user; + SQL end private def privacy_type_exists?(conn : DB::Connection) : Bool @@ -42,7 +42,7 @@ module Invidious::Database::Migrations WHERE pg_namespace.nspname = 'public' AND pg_type.typname = 'privacy' LIMIT 1; - SQL + SQL !conn.query_one?(request, as: Int32).nil? end diff --git a/src/invidious/database/migrations/0009_create_playlist_videos_table.cr b/src/invidious/database/migrations/0009_create_playlist_videos_table.cr index 84938b9ba..82699b34b 100644 --- a/src/invidious/database/migrations/0009_create_playlist_videos_table.cr +++ b/src/invidious/database/migrations/0009_create_playlist_videos_table.cr @@ -4,24 +4,24 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - CREATE TABLE IF NOT EXISTS public.playlist_videos - ( - title text, - id text, - author text, - ucid text, - length_seconds integer, - published timestamptz, - plid text references playlists(id), - index int8, - live_now boolean, - PRIMARY KEY (index,plid) - ); - SQL + CREATE TABLE IF NOT EXISTS public.playlist_videos + ( + title text, + id text, + author text, + ucid text, + length_seconds integer, + published timestamptz, + plid text references playlists(id), + index int8, + live_now boolean, + PRIMARY KEY (index,plid) + ); + SQL conn.exec <<-SQL - GRANT ALL ON TABLE public.playlist_videos TO current_user; - SQL + GRANT ALL ON TABLE public.playlist_videos TO current_user; + SQL end end end diff --git a/src/invidious/database/migrations/0010_make_videos_unlogged.cr b/src/invidious/database/migrations/0010_make_videos_unlogged.cr index f5d196834..37f1da234 100644 --- a/src/invidious/database/migrations/0010_make_videos_unlogged.cr +++ b/src/invidious/database/migrations/0010_make_videos_unlogged.cr @@ -4,8 +4,8 @@ module Invidious::Database::Migrations def up(conn : DB::Connection) conn.exec <<-SQL - ALTER TABLE public.videos SET UNLOGGED; - SQL + ALTER TABLE public.videos SET UNLOGGED; + SQL end end end diff --git a/src/invidious/database/migrator.cr b/src/invidious/database/migrator.cr index 660c32034..200cf421b 100644 --- a/src/invidious/database/migrator.cr +++ b/src/invidious/database/migrator.cr @@ -44,6 +44,6 @@ class Invidious::Database::Migrator id bigserial PRIMARY KEY, version bigint NOT NULL ) - SQL + SQL end end diff --git a/src/invidious/database/nonces.cr b/src/invidious/database/nonces.cr index b87c81ecb..55c8d8560 100644 --- a/src/invidious/database/nonces.cr +++ b/src/invidious/database/nonces.cr @@ -12,7 +12,7 @@ module Invidious::Database::Nonces INSERT INTO nonces VALUES ($1, $2) ON CONFLICT DO NOTHING - SQL + SQL PG_DB.exec(request, nonce, expire) end @@ -21,7 +21,7 @@ module Invidious::Database::Nonces request = <<-SQL DELETE FROM nonces * WHERE expire < now() - SQL + SQL PG_DB.exec(request) end @@ -35,7 +35,7 @@ module Invidious::Database::Nonces UPDATE nonces SET expire = $1 WHERE nonce = $2 - SQL + SQL PG_DB.exec(request, Time.utc(1990, 1, 1), nonce) end @@ -48,7 +48,7 @@ module Invidious::Database::Nonces request = <<-SQL SELECT * FROM nonces WHERE nonce = $1 - SQL + SQL return PG_DB.query_one?(request, nonce, as: {String, Time}) end diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index 6dbcaa051..ba1e5b0a8 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -16,7 +16,7 @@ module Invidious::Database::Playlists request = <<-SQL INSERT INTO playlists VALUES (#{arg_array(playlist_array)}) - SQL + SQL PG_DB.exec(request, args: playlist_array) end @@ -27,7 +27,7 @@ module Invidious::Database::Playlists request = <<-SQL DELETE FROM playlists * WHERE id = $1 - SQL + SQL PG_DB.exec(request, id) end @@ -41,7 +41,7 @@ module Invidious::Database::Playlists UPDATE playlists SET title = $1, privacy = $2, description = $3, updated = $4 WHERE id = $5 - SQL + SQL PG_DB.exec(request, title, privacy, description, updated, id) end @@ -51,7 +51,7 @@ module Invidious::Database::Playlists UPDATE playlists SET description = $1 WHERE id = $2 - SQL + SQL PG_DB.exec(request, description, id) end @@ -61,7 +61,7 @@ module Invidious::Database::Playlists UPDATE playlists SET subscribed = now() WHERE id = $1 - SQL + SQL PG_DB.exec(request, id) end @@ -73,7 +73,7 @@ module Invidious::Database::Playlists video_count = cardinality(index) + 1, updated = now() WHERE id = $2 - SQL + SQL PG_DB.exec(request, index, id) end @@ -85,7 +85,7 @@ module Invidious::Database::Playlists video_count = cardinality(index) - 1, updated = now() WHERE id = $2 - SQL + SQL PG_DB.exec(request, index, id) end @@ -98,7 +98,7 @@ module Invidious::Database::Playlists request = <<-SQL SELECT * FROM playlists WHERE id = $1 - SQL + SQL return PG_DB.query_one?(request, id, as: InvidiousPlaylist) end @@ -107,7 +107,7 @@ module Invidious::Database::Playlists request = <<-SQL SELECT * FROM playlists WHERE author = $1 - SQL + SQL return PG_DB.query_all(request, author, as: InvidiousPlaylist) end @@ -121,7 +121,7 @@ module Invidious::Database::Playlists SELECT * FROM playlists WHERE author = $1 AND id LIKE 'IV%' ORDER BY created - SQL + SQL PG_DB.query_all(request, email, as: InvidiousPlaylist) end @@ -131,7 +131,7 @@ module Invidious::Database::Playlists SELECT * FROM playlists WHERE author = $1 AND id NOT LIKE 'IV%' ORDER BY created - SQL + SQL PG_DB.query_all(request, email, as: InvidiousPlaylist) end @@ -141,7 +141,7 @@ module Invidious::Database::Playlists SELECT id,title FROM playlists WHERE author = $1 AND id LIKE 'IV%' ORDER BY title - SQL + SQL PG_DB.query_all(request, email, as: {String, String}) end @@ -155,7 +155,7 @@ module Invidious::Database::Playlists request = <<-SQL SELECT id FROM playlists WHERE id = $1 - SQL + SQL return PG_DB.query_one?(request, id, as: String).nil? end @@ -165,7 +165,7 @@ module Invidious::Database::Playlists request = <<-SQL SELECT count(*) FROM playlists WHERE author = $1 - SQL + SQL return PG_DB.query_one?(request, author, as: Int64) || 0_i64 end @@ -189,7 +189,7 @@ module Invidious::Database::PlaylistVideos request = <<-SQL INSERT INTO playlist_videos VALUES (#{arg_array(video_array)}) - SQL + SQL PG_DB.exec(request, args: video_array) end @@ -198,7 +198,7 @@ module Invidious::Database::PlaylistVideos request = <<-SQL DELETE FROM playlist_videos * WHERE index = $1 - SQL + SQL PG_DB.exec(request, index) end @@ -207,7 +207,7 @@ module Invidious::Database::PlaylistVideos request = <<-SQL DELETE FROM playlist_videos * WHERE plid = $1 - SQL + SQL PG_DB.exec(request, plid) end @@ -223,7 +223,7 @@ module Invidious::Database::PlaylistVideos ORDER BY array_position($2, index) LIMIT $3 OFFSET $4 - SQL + SQL return PG_DB.query_all(request, plid, index, limit, offset, as: PlaylistVideo) end @@ -233,7 +233,7 @@ module Invidious::Database::PlaylistVideos SELECT index FROM playlist_videos WHERE plid = $1 AND id = $2 LIMIT 1 - SQL + SQL return PG_DB.query_one?(request, plid, vid, as: Int64) end @@ -244,7 +244,7 @@ module Invidious::Database::PlaylistVideos WHERE plid = $1 ORDER BY array_position($2, index) LIMIT 1 - SQL + SQL return PG_DB.query_one?(request, plid, index, as: String) end @@ -255,7 +255,7 @@ module Invidious::Database::PlaylistVideos WHERE plid = $1 ORDER BY array_position($2, index) LIMIT $3 - SQL + SQL return PG_DB.query_all(request, plid, index, limit, as: String) end diff --git a/src/invidious/database/sessions.cr b/src/invidious/database/sessions.cr index 965870829..5537f087f 100644 --- a/src/invidious/database/sessions.cr +++ b/src/invidious/database/sessions.cr @@ -11,7 +11,7 @@ module Invidious::Database::SessionIDs request = <<-SQL INSERT INTO session_ids VALUES ($1, $2, now()) - SQL + SQL request += " ON CONFLICT (id) DO NOTHING" if handle_conflicts @@ -26,7 +26,7 @@ module Invidious::Database::SessionIDs request = <<-SQL DELETE FROM session_ids * WHERE id = $1 - SQL + SQL PG_DB.exec(request, sid) end @@ -35,7 +35,7 @@ module Invidious::Database::SessionIDs request = <<-SQL DELETE FROM session_ids * WHERE email = $1 - SQL + SQL PG_DB.exec(request, email) end @@ -44,7 +44,7 @@ module Invidious::Database::SessionIDs request = <<-SQL DELETE FROM session_ids * WHERE id = $1 AND email = $2 - SQL + SQL PG_DB.exec(request, sid, email) end @@ -57,7 +57,7 @@ module Invidious::Database::SessionIDs request = <<-SQL SELECT email FROM session_ids WHERE id = $1 - SQL + SQL PG_DB.query_one?(request, sid, as: String) end @@ -67,7 +67,7 @@ module Invidious::Database::SessionIDs SELECT id, issued FROM session_ids WHERE email = $1 ORDER BY issued DESC - SQL + SQL PG_DB.query_all(request, email, as: {session: String, issued: Time}) end diff --git a/src/invidious/database/statistics.cr b/src/invidious/database/statistics.cr index 9e4963fde..cf2a138e6 100644 --- a/src/invidious/database/statistics.cr +++ b/src/invidious/database/statistics.cr @@ -10,7 +10,7 @@ module Invidious::Database::Statistics def count_users_total : Int64 request = <<-SQL SELECT count(*) FROM users - SQL + SQL PG_DB.query_one(request, as: Int64) end @@ -19,7 +19,7 @@ module Invidious::Database::Statistics request = <<-SQL SELECT count(*) FROM users WHERE CURRENT_TIMESTAMP - updated < '6 months' - SQL + SQL PG_DB.query_one(request, as: Int64) end @@ -28,7 +28,7 @@ module Invidious::Database::Statistics request = <<-SQL SELECT count(*) FROM users WHERE CURRENT_TIMESTAMP - updated < '1 month' - SQL + SQL PG_DB.query_one(request, as: Int64) end @@ -42,7 +42,7 @@ module Invidious::Database::Statistics SELECT updated FROM channels ORDER BY updated DESC LIMIT 1 - SQL + SQL PG_DB.query_one?(request, as: Time) end diff --git a/src/invidious/database/users.cr b/src/invidious/database/users.cr index 4a3056ea5..9b297930f 100644 --- a/src/invidious/database/users.cr +++ b/src/invidious/database/users.cr @@ -14,13 +14,13 @@ module Invidious::Database::Users request = <<-SQL INSERT INTO users VALUES (#{arg_array(user_array)}) - SQL + SQL if update_on_conflict request += <<-SQL ON CONFLICT (email) DO UPDATE SET updated = $1, subscriptions = $3 - SQL + SQL end PG_DB.exec(request, args: user_array) @@ -30,7 +30,7 @@ module Invidious::Database::Users request = <<-SQL DELETE FROM users * WHERE email = $1 - SQL + SQL PG_DB.exec(request, user.email) end @@ -44,7 +44,7 @@ module Invidious::Database::Users UPDATE users SET watched = $1 WHERE email = $2 - SQL + SQL PG_DB.exec(request, user.watched, user.email) end @@ -54,7 +54,7 @@ module Invidious::Database::Users UPDATE users SET watched = array_append(array_remove(watched, $1), $1) WHERE email = $2 - SQL + SQL PG_DB.exec(request, vid, user.email) end @@ -64,7 +64,7 @@ module Invidious::Database::Users UPDATE users SET watched = array_remove(watched, $1) WHERE email = $2 - SQL + SQL PG_DB.exec(request, vid, user.email) end @@ -74,7 +74,7 @@ module Invidious::Database::Users UPDATE users SET watched = '{}' WHERE email = $1 - SQL + SQL PG_DB.exec(request, user.email) end @@ -88,7 +88,7 @@ module Invidious::Database::Users UPDATE users SET feed_needs_update = true, subscriptions = $1 WHERE email = $2 - SQL + SQL PG_DB.exec(request, user.subscriptions, user.email) end @@ -99,7 +99,7 @@ module Invidious::Database::Users SET feed_needs_update = true, subscriptions = array_append(subscriptions,$1) WHERE email = $2 - SQL + SQL PG_DB.exec(request, ucid, user.email) end @@ -110,7 +110,7 @@ module Invidious::Database::Users SET feed_needs_update = true, subscriptions = array_remove(subscriptions, $1) WHERE email = $2 - SQL + SQL PG_DB.exec(request, ucid, user.email) end @@ -125,7 +125,7 @@ module Invidious::Database::Users SET notifications = array_cat(notifications, $1), feed_needs_update = true WHERE $2 = ANY(subscriptions) - SQL + SQL PG_DB.exec(request, video_ids, channel_id) end @@ -135,7 +135,7 @@ module Invidious::Database::Users UPDATE users SET notifications = array_remove(notifications, $1) WHERE email = $2 - SQL + SQL PG_DB.exec(request, vid, user.email) end @@ -145,7 +145,7 @@ module Invidious::Database::Users UPDATE users SET notifications = '{}', updated = now() WHERE email = $1 - SQL + SQL PG_DB.exec(request, user.email) end @@ -159,7 +159,7 @@ module Invidious::Database::Users UPDATE users SET feed_needs_update = true WHERE $1 = ANY(subscriptions) - SQL + SQL PG_DB.exec(request, channel_id) end @@ -169,7 +169,7 @@ module Invidious::Database::Users UPDATE users SET preferences = $1 WHERE email = $2 - SQL + SQL PG_DB.exec(request, user.preferences.to_json, user.email) end @@ -179,7 +179,7 @@ module Invidious::Database::Users UPDATE users SET password = $1 WHERE email = $2 - SQL + SQL PG_DB.exec(request, pass, user.email) end @@ -192,7 +192,7 @@ module Invidious::Database::Users request = <<-SQL SELECT * FROM users WHERE email = $1 - SQL + SQL return PG_DB.query_one?(request, email, as: User) end @@ -202,7 +202,7 @@ module Invidious::Database::Users request = <<-SQL SELECT * FROM users WHERE email = $1 - SQL + SQL return PG_DB.query_one(request, email, as: User) end @@ -211,7 +211,7 @@ module Invidious::Database::Users request = <<-SQL SELECT * FROM users WHERE token = $1 - SQL + SQL return PG_DB.query_one?(request, token, as: User) end @@ -221,7 +221,7 @@ module Invidious::Database::Users SELECT notifications FROM users WHERE email = $1 - SQL + SQL return PG_DB.query_one(request, user.email, as: Array(String)) end diff --git a/src/invidious/database/videos.cr b/src/invidious/database/videos.cr index 695f5b335..40bafaf1d 100644 --- a/src/invidious/database/videos.cr +++ b/src/invidious/database/videos.cr @@ -8,7 +8,7 @@ module Invidious::Database::Videos INSERT INTO videos VALUES ($1, $2, $3) ON CONFLICT (id) DO NOTHING - SQL + SQL PG_DB.exec(request, video.id, video.info.to_json, video.updated) end @@ -17,7 +17,7 @@ module Invidious::Database::Videos request = <<-SQL DELETE FROM videos * WHERE id = $1 - SQL + SQL PG_DB.exec(request, id) end @@ -26,7 +26,7 @@ module Invidious::Database::Videos request = <<-SQL DELETE FROM videos * WHERE updated < (now() - interval '6 hours') - SQL + SQL PG_DB.exec(request) end @@ -36,7 +36,7 @@ module Invidious::Database::Videos UPDATE videos SET (id, info, updated) = ($1, $2, $3) WHERE id = $1 - SQL + SQL PG_DB.exec(request, video.id, video.info.to_json, video.updated) end @@ -45,7 +45,7 @@ module Invidious::Database::Videos request = <<-SQL SELECT * FROM videos WHERE id = $1 - SQL + SQL return PG_DB.query_one?(request, id, as: Video) end diff --git a/src/invidious/frontend/comments_reddit.cr b/src/invidious/frontend/comments_reddit.cr index d46e93e7f..08ce2f344 100644 --- a/src/invidious/frontend/comments_reddit.cr +++ b/src/invidious/frontend/comments_reddit.cr @@ -16,33 +16,33 @@ module Invidious::Frontend::Comments if child.depth > 0 html << <<-END_HTML -
-
-
-
- END_HTML +
+
+
+
+ END_HTML else html << <<-END_HTML -
-
- END_HTML +
+
+ END_HTML end html << <<-END_HTML -

- [ − ] - #{child.author} - #{translate_count(locale, "comments_points_count", child.score, NumberFormatting::Separator)} - #{translate(locale, "`x` ago", recode_date(child.created_utc, locale))} - #{translate(locale, "permalink")} -

-
- #{body_html} - #{replies_html} -
-
-
- END_HTML +

+ [ − ] + #{child.author} + #{translate_count(locale, "comments_points_count", child.score, NumberFormatting::Separator)} + #{translate(locale, "`x` ago", recode_date(child.created_utc, locale))} + #{translate(locale, "permalink")} +

+
+ #{body_html} + #{replies_html} +
+
+
+ END_HTML end end end diff --git a/src/invidious/frontend/comments_youtube.cr b/src/invidious/frontend/comments_youtube.cr index a0e1d783d..4e3ea7203 100644 --- a/src/invidious/frontend/comments_youtube.cr +++ b/src/invidious/frontend/comments_youtube.cr @@ -13,16 +13,16 @@ module Invidious::Frontend::Comments ) replies_html = <<-END_HTML -
-
- - END_HTML + END_HTML elsif comments["authorId"]? && !comments["singlePost"]? # for posts we should display a link to the post replies_count_text = translate_count(locale, @@ -32,15 +32,15 @@ module Invidious::Frontend::Comments ) replies_html = <<-END_HTML -
-
- - END_HTML + END_HTML end if !thin_mode @@ -66,18 +66,18 @@ module Invidious::Frontend::Comments end end html << <<-END_HTML -
-
- -
-
-

- - #{author_name} - - #{sponsor_icon} -

#{child["contentHtml"]}

- END_HTML +
+
+ +
+
+

+ + #{author_name} + + #{sponsor_icon} +

#{child["contentHtml"]}

+ END_HTML if child["attachment"]? attachment = child["attachment"] @@ -87,25 +87,25 @@ module Invidious::Frontend::Comments attachment = attachment["imageThumbnails"][1] html << <<-END_HTML -
-
- +
+
+ +
-
- END_HTML + END_HTML when "video" if attachment["error"]? html << <<-END_HTML -
-

#{attachment["error"]}

-
- END_HTML +
+

#{attachment["error"]}

+
+ END_HTML else html << <<-END_HTML -
- -
- END_HTML +
+ +
+ END_HTML end when "multiImage" html << <<-END_HTML @@ -133,35 +133,35 @@ module Invidious::Frontend::Comments END_HTML end html << <<-END_HTML -
-
- - END_HTML +
+
+ + END_HTML else nil # Ignore end end html << <<-END_HTML -

- #{translate(locale, "`x` ago", recode_date(Time.unix(child["published"].as_i64), locale))} #{child["isEdited"] == true ? translate(locale, "(edited)") : ""} - | - END_HTML +

+ #{translate(locale, "`x` ago", recode_date(Time.unix(child["published"].as_i64), locale))} #{child["isEdited"] == true ? translate(locale, "(edited)") : ""} + | + END_HTML if comments["videoId"]? html << <<-END_HTML [YT] | - END_HTML + END_HTML elsif comments["authorId"]? html << <<-END_HTML [YT] | - END_HTML + END_HTML end html << <<-END_HTML #{number_with_separator(child["likeCount"])} - END_HTML + END_HTML if child["creatorHeart"]? if !thin_mode @@ -180,28 +180,28 @@ module Invidious::Frontend::Comments - END_HTML + END_HTML end html << <<-END_HTML -

- #{replies_html} +

+ #{replies_html} +
-
- END_HTML + END_HTML end if comments["continuation"]? html << <<-END_HTML -
- - END_HTML + END_HTML end end end diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index 7ee5d30dd..0add31bcd 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -22,12 +22,12 @@ def get_issue_template(env : HTTP::Server::Context, exception : Exception) : Tup issue_title = "#{exception.message} (#{exception.class})" issue_template = <<-TEXT - Title: `#{HTML.escape(issue_title)}` - Date: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}` - Route: `#{HTML.escape(env.request.resource)}` - Version: `#{SOFTWARE["version"]} @ #{SOFTWARE["branch"]}` + Title: `#{HTML.escape(issue_title)}` + Date: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}` + Route: `#{HTML.escape(env.request.resource)}` + Version: `#{SOFTWARE["version"]} @ #{SOFTWARE["branch"]}` - TEXT + TEXT issue_template += github_details("Backtrace", exception.inspect_with_backtrace) @@ -80,7 +80,7 @@ def error_template_helper(env : HTTP::Server::Context, status_code : Int32, exce
#{issue_template}
- END_HTML + END_HTML # Don't show the usual "next steps" widget. The same options are # proposed above the error message, just worded differently. @@ -204,7 +204,7 @@ def error_redirect_helper(env : HTTP::Server::Context) #{go_to_youtube} - END_HTML + END_HTML else return "" end diff --git a/src/invidious/mixes.cr b/src/invidious/mixes.cr index 28ff0ff6e..b522c78cb 100644 --- a/src/invidious/mixes.cr +++ b/src/invidious/mixes.cr @@ -83,14 +83,14 @@ end def template_mix(mix, listen) html = <<-END_HTML -

- - #{mix["title"]} - -

-
-
    - END_HTML +

    + + #{mix["title"]} + +

    +
    +
      + END_HTML mix["videos"].as_a.each do |video| html += <<-END_HTML @@ -106,14 +106,14 @@ def template_mix(mix, listen)

      - END_HTML + END_HTML end html += <<-END_HTML -
    -
    -
    - END_HTML +
+
+
+ END_HTML html end diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 9df0883e1..ff77533d0 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -509,14 +509,14 @@ end def template_playlist(playlist, listen) html = <<-END_HTML -

- - #{playlist["title"]} - -

-
-
    - END_HTML +

    + + #{playlist["title"]} + +

    +
    +
      + END_HTML playlist["videos"].as_a.each do |video| html += <<-END_HTML @@ -532,14 +532,14 @@ def template_playlist(playlist, listen)

      - END_HTML + END_HTML end html += <<-END_HTML -
    -
    -
    - END_HTML +
+
+
+ END_HTML html end diff --git a/src/invidious/user/captcha.cr b/src/invidious/user/captcha.cr index b175c3b92..e46105e03 100644 --- a/src/invidious/user/captcha.cr +++ b/src/invidious/user/captcha.cr @@ -20,28 +20,28 @@ struct Invidious::User end clock_svg = <<-END_SVG - - + + - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 - - - - - - END_SVG + + + + + + END_SVG image = "data:image/png;base64," image += Process.run(%(rsvg-convert -w 400 -h 400 -b none -f png), shell: true, From a6ade5675610a564c00ed03187ccd6e37a2ed6e1 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:53:10 +0100 Subject: [PATCH 13/27] Fix `Lint/ElseNil` type of Ameba issues --- src/invidious/frontend/comments_youtube.cr | 1 - src/invidious/helpers/utils.cr | 1 - src/invidious/routes/embed.cr | 1 - src/invidious/routes/feeds.cr | 1 - src/invidious/routes/preferences.cr | 1 - src/invidious/users.cr | 2 -- src/invidious/yt_backend/extractors.cr | 1 - src/invidious/yt_backend/extractors_utils.cr | 2 -- 8 files changed, 10 deletions(-) diff --git a/src/invidious/frontend/comments_youtube.cr b/src/invidious/frontend/comments_youtube.cr index 4e3ea7203..4638395a9 100644 --- a/src/invidious/frontend/comments_youtube.cr +++ b/src/invidious/frontend/comments_youtube.cr @@ -137,7 +137,6 @@ module Invidious::Frontend::Comments
END_HTML - else nil # Ignore end end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 5637e5338..97bce2634 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -108,7 +108,6 @@ def decode_date(string : String) return Time.utc when "yesterday" return Time.utc - 1.day - else nil # Continue end # String matches format "20 hours ago", "4 months ago", "20s ago", "15min ago"... diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index d0a3b5c15..c63316f4f 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -119,7 +119,6 @@ module Invidious::Routes::Embed end return env.redirect url - else nil # Continue end params = process_video_params(env.params.query, preferences) diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr index ce173760a..1a2fa716b 100644 --- a/src/invidious/routes/feeds.cr +++ b/src/invidious/routes/feeds.cr @@ -322,7 +322,6 @@ module Invidious::Routes::Feeds request_target = URI.parse(node[attribute.name]).request_target query_string_opt = request_target.starts_with?("/watch?v=") ? "&#{params}" : "" node[attribute.name] = "#{HOST_URL}#{request_target}#{query_string_opt}" - else nil # Skip end end end diff --git a/src/invidious/routes/preferences.cr b/src/invidious/routes/preferences.cr index d9fad1b18..f8cc06756 100644 --- a/src/invidious/routes/preferences.cr +++ b/src/invidious/routes/preferences.cr @@ -347,7 +347,6 @@ module Invidious::Routes::PreferencesRoute response: error_template(415, "Uploaded file is too large") ) end - else nil # Ignore end end end diff --git a/src/invidious/users.cr b/src/invidious/users.cr index 65566d207..5158fc222 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -45,7 +45,6 @@ def get_subscription_feed(user, max_results = 40, page = 1) notifications.sort_by!(&.author) when "channel name - reverse" notifications.sort_by!(&.author).reverse! - else nil # Ignore end else if user.preferences.latest_only @@ -94,7 +93,6 @@ def get_subscription_feed(user, max_results = 40, page = 1) videos.sort_by!(&.author) when "channel name - reverse" videos.sort_by!(&.author).reverse! - else nil # Ignore end notifications = Invidious::Database::Users.select_notifications(user) diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 056ba2c8b..d9f810166 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -152,7 +152,6 @@ private module Parsers when "Premium" # TODO: Potentially available as item_contents["topStandaloneBadge"]["metadataBadgeRenderer"] badges |= VideoBadges::Premium - else nil # Ignore end end diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index 21c958ace..3ee849d0b 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -24,8 +24,6 @@ def extract_text(item : JSON::Any?) : String? return text_container.as_s elsif text_container = item["runs"]? return text_container.as_a.map(&.["text"].as_s).join("") - else - nil end end From 31d218c03edca9f9cad683b01dcc31ac324dd48e Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:55:45 +0100 Subject: [PATCH 14/27] Fix `Style/MultilineCurlyBlock` type of Ameba issues --- src/invidious/routes/embed.cr | 8 ++++---- src/invidious/routes/watch.cr | 8 ++++---- src/invidious/videos.cr | 4 ++-- src/invidious/yt_backend/extractors.cr | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr index c63316f4f..26c9ba7f1 100644 --- a/src/invidious/routes/embed.cr +++ b/src/invidious/routes/embed.cr @@ -181,14 +181,14 @@ module Invidious::Routes::Embed 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.language_code.split("-")[0]) - } - preferred_captions.sort_by! { |caption| + end + preferred_captions.sort_by! do |caption| (params.preferred_captions.index(caption.name) || params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil! - } + end captions = captions - preferred_captions aspect_ratio = nil diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.cr index 4c1815038..4575dae28 100644 --- a/src/invidious/routes/watch.cr +++ b/src/invidious/routes/watch.cr @@ -145,14 +145,14 @@ module Invidious::Routes::Watch 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.language_code.split("-")[0]) - } - preferred_captions.sort_by! { |caption| + end + preferred_captions.sort_by! do |caption| (params.preferred_captions.index(caption.name) || params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil! - } + end captions = captions - preferred_captions aspect_ratio = "16:9" diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 4f07f4bbd..7081a7dd3 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -182,14 +182,14 @@ struct Video end def music : Array(VideoMusic) - info["music"].as_a.map { |music_json| + info["music"].as_a.map do |music_json| VideoMusic.new( music_json["song"].as_s, music_json["album"].as_s, music_json["artist"].as_s, music_json["license"].as_s ) - } + end end # Macros defining getters/setters for various types of data diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index d9f810166..22c184eee 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -673,9 +673,9 @@ private module Parsers video_count = thumbnail_view_model.dig("overlays").as_a .compact_map(&.dig?("thumbnailOverlayBadgeViewModel", "thumbnailBadges").try &.as_a) .flatten - .find(nil, &.dig?("thumbnailBadgeViewModel", "text").try { |node| + .find(nil, &.dig?("thumbnailBadgeViewModel", "text").try do |node| {"episodes", "videos"}.any? { |str| node.as_s.ends_with?(str) } - }) + end) .try &.dig("thumbnailBadgeViewModel", "text").as_s.to_i(strict: false) metadata = item_contents.dig("metadata", "lockupMetadataViewModel") From ee85274b8db60a888a9b8a8f403d95292bc91d7d Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 22:58:37 +0100 Subject: [PATCH 15/27] Fix `Lint/RequireParentheses` type of Ameba issues --- src/invidious/jsonify/api_v1/video_json.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr index 5867698ec..569c4a827 100644 --- a/src/invidious/jsonify/api_v1/video_json.cr +++ b/src/invidious/jsonify/api_v1/video_json.cr @@ -138,7 +138,7 @@ module Invidious::JSONify::APIv1 if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) 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 # Livestream chunk infos @@ -199,7 +199,7 @@ module Invidious::JSONify::APIv1 if fmt_info = Invidious::Videos::Formats.itag_to_metadata?(fmt["itag"]) 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 From 6b2afb23dbb12fbab300433e31d33a5b4383a9ac Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:00:31 +0100 Subject: [PATCH 16/27] Fix `Style/MultilineStringLiteral` type of Ameba issues --- src/invidious/search/processors.cr | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/invidious/search/processors.cr b/src/invidious/search/processors.cr index 25edb9362..7d86a6066 100644 --- a/src/invidious/search/processors.cr +++ b/src/invidious/search/processors.cr @@ -39,7 +39,7 @@ module Invidious::Search def subscriptions(query : Query, user : Invidious::User) : Array(ChannelVideo) view_name = "subscriptions_#{sha256(user.email)}" - return PG_DB.query_all(" + return PG_DB.query_all(<<-SQL, query.text, (query.page - 1) * 20, as: ChannelVideo) SELECT id,title,published,updated,ucid,author,length_seconds FROM ( SELECT *, @@ -47,10 +47,8 @@ module Invidious::Search to_tsvector(#{view_name}.author) as document FROM #{view_name} - ) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2;", - query.text, (query.page - 1) * 20, - as: ChannelVideo - ) + ) v_search WHERE v_search.document @@ plainto_tsquery($1) LIMIT 20 OFFSET $2; + SQL end end end From 3591a4f840a884a798f3b7718fd1333778d39999 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:03:19 +0100 Subject: [PATCH 17/27] Ignore ECR files in `Lint/UnusedArgument` and `Lint/UselessAssign` rules --- .ameba.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.ameba.yml b/.ameba.yml index 613ad5ec3..05229d109 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -2,9 +2,14 @@ # Lint # +Lint/UnusedArgument: + Excluded: + - "**/*.ecr" + # Exclude assigns for ECR files Lint/UselessAssign: Excluded: + - "**/*.ecr" - src/invidious.cr - src/invidious/helpers/errors.cr - src/invidious/routes/**/*.cr From b0049e168083ae1256ee7230b8999a6ba40bd126 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:04:53 +0100 Subject: [PATCH 18/27] Remove redundant assignment --- src/invidious/views/user/login.ecr | 1 - 1 file changed, 1 deletion(-) diff --git a/src/invidious/views/user/login.ecr b/src/invidious/views/user/login.ecr index 7ac96bc6f..3e0b192c1 100644 --- a/src/invidious/views/user/login.ecr +++ b/src/invidious/views/user/login.ecr @@ -25,7 +25,6 @@ <% end %> <% if captcha %> - <% captcha = captcha.not_nil! %> <% captcha[:tokens].each_with_index do |token, i| %> From 7d90748e78097f11c2e0dc171adc1e383828a1ba Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:13:19 +0100 Subject: [PATCH 19/27] Use common heredoc markers --- src/invidious/frontend/comments_reddit.cr | 12 ++-- src/invidious/frontend/comments_youtube.cr | 72 +++++++++++----------- src/invidious/helpers/errors.cr | 8 +-- src/invidious/mixes.cr | 12 ++-- src/invidious/playlists.cr | 12 ++-- src/invidious/user/captcha.cr | 4 +- 6 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/invidious/frontend/comments_reddit.cr b/src/invidious/frontend/comments_reddit.cr index 08ce2f344..7ee357adc 100644 --- a/src/invidious/frontend/comments_reddit.cr +++ b/src/invidious/frontend/comments_reddit.cr @@ -15,20 +15,20 @@ module Invidious::Frontend::Comments end if child.depth > 0 - html << <<-END_HTML + html << <<-HTML
- END_HTML + HTML else - html << <<-END_HTML + html << <<-HTML
- END_HTML + HTML end - html << <<-END_HTML + html << <<-HTML

[ − ] #{child.author} @@ -42,7 +42,7 @@ module Invidious::Frontend::Comments

- END_HTML + HTML end end end diff --git a/src/invidious/frontend/comments_youtube.cr b/src/invidious/frontend/comments_youtube.cr index 4638395a9..46012adf4 100644 --- a/src/invidious/frontend/comments_youtube.cr +++ b/src/invidious/frontend/comments_youtube.cr @@ -12,7 +12,7 @@ module Invidious::Frontend::Comments NumberFormatting::Separator ) - replies_html = <<-END_HTML + replies_html = <<-HTML
@@ -22,7 +22,7 @@ module Invidious::Frontend::Comments

- END_HTML + HTML elsif comments["authorId"]? && !comments["singlePost"]? # for posts we should display a link to the post replies_count_text = translate_count(locale, @@ -31,7 +31,7 @@ module Invidious::Frontend::Comments NumberFormatting::Separator ) - replies_html = <<-END_HTML + replies_html = <<-HTML
@@ -40,7 +40,7 @@ module Invidious::Frontend::Comments

- END_HTML + HTML end if !thin_mode @@ -65,7 +65,7 @@ module Invidious::Frontend::Comments str << %(width="16" height="16" />) end end - html << <<-END_HTML + html << <<-HTML
@@ -77,7 +77,7 @@ module Invidious::Frontend::Comments #{sponsor_icon}

#{child["contentHtml"]}

- END_HTML + HTML if child["attachment"]? attachment = child["attachment"] @@ -86,81 +86,81 @@ module Invidious::Frontend::Comments when "image" attachment = attachment["imageThumbnails"][1] - html << <<-END_HTML + html << <<-HTML
- END_HTML + HTML when "video" if attachment["error"]? - html << <<-END_HTML + html << <<-HTML

#{attachment["error"]}

- END_HTML + HTML else - html << <<-END_HTML + html << <<-HTML
- END_HTML + HTML end when "multiImage" - html << <<-END_HTML + html << <<-HTML - END_HTML + HTML end end - html << <<-END_HTML + html << <<-HTML

#{translate(locale, "`x` ago", recode_date(Time.unix(child["published"].as_i64), locale))} #{child["isEdited"] == true ? translate(locale, "(edited)") : ""} | - END_HTML + HTML if comments["videoId"]? - html << <<-END_HTML + html << <<-HTML [YT] | - END_HTML + HTML elsif comments["authorId"]? - html << <<-END_HTML + html << <<-HTML [YT] | - END_HTML + HTML end - html << <<-END_HTML + html << <<-HTML #{number_with_separator(child["likeCount"])} - END_HTML + HTML if child["creatorHeart"]? if !thin_mode @@ -169,7 +169,7 @@ module Invidious::Frontend::Comments creator_thumbnail = "" end - html << <<-END_HTML + html << <<-HTML   @@ -179,19 +179,19 @@ module Invidious::Frontend::Comments - END_HTML + HTML end - html << <<-END_HTML + html << <<-HTML

#{replies_html}
- END_HTML + HTML end if comments["continuation"]? - html << <<-END_HTML + html << <<-HTML

@@ -200,7 +200,7 @@ module Invidious::Frontend::Comments

- END_HTML + HTML end end end diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index 0add31bcd..70b591265 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -61,7 +61,7 @@ def error_template_helper(env : HTTP::Server::Context, status_code : Int32, exce url_new_issue += "?labels=bug&template=bug_report.md&title=" url_new_issue += URI.encode_www_form("[Bug] " + issue_title) - error_message = <<-END_HTML + error_message = <<-HTML

#{translate(locale, "crash_page_you_found_a_bug")}



@@ -80,7 +80,7 @@ def error_template_helper(env : HTTP::Server::Context, status_code : Int32, exce
#{issue_template}
- END_HTML + HTML # Don't show the usual "next steps" widget. The same options are # proposed above the error message, just worded differently. @@ -191,7 +191,7 @@ def error_redirect_helper(env : HTTP::Server::Context) go_to_youtube = translate(locale, "next_steps_error_message_go_to_youtube") switch_instance = translate(locale, "Switch Invidious Instance") - return <<-END_HTML + return <<-HTML

#{next_steps_text}

  • @@ -204,7 +204,7 @@ def error_redirect_helper(env : HTTP::Server::Context) #{go_to_youtube}
- END_HTML + HTML else return "" end diff --git a/src/invidious/mixes.cr b/src/invidious/mixes.cr index b522c78cb..31f53e8dd 100644 --- a/src/invidious/mixes.cr +++ b/src/invidious/mixes.cr @@ -82,7 +82,7 @@ def fetch_mix(rdid, video_id, cookies = nil, locale = nil) end def template_mix(mix, listen) - html = <<-END_HTML + html = <<-HTML

#{mix["title"]} @@ -90,10 +90,10 @@ def template_mix(mix, listen)


- END_HTML + HTML html end diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index ff77533d0..4f1f09d01 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -508,7 +508,7 @@ def extract_playlist_videos(initial_data : Hash(String, JSON::Any)) end def template_playlist(playlist, listen) - html = <<-END_HTML + html = <<-HTML

#{playlist["title"]} @@ -516,10 +516,10 @@ def template_playlist(playlist, listen)


- END_HTML + HTML html end diff --git a/src/invidious/user/captcha.cr b/src/invidious/user/captcha.cr index e46105e03..79cfcbfab 100644 --- a/src/invidious/user/captcha.cr +++ b/src/invidious/user/captcha.cr @@ -19,7 +19,7 @@ struct Invidious::User hour = 12 end - clock_svg = <<-END_SVG + clock_svg = <<-SVG @@ -41,7 +41,7 @@ struct Invidious::User - END_SVG + SVG image = "data:image/png;base64," image += Process.run(%(rsvg-convert -w 400 -h 400 -b none -f png), shell: true, From 5f1c9849bf7044aa25f55a64b248b65d6aad2160 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:14:50 +0100 Subject: [PATCH 20/27] Use inline disable pragma --- .ameba.yml | 5 ----- src/invidious/database/base.cr | 1 + 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 05229d109..8a792e179 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -14,11 +14,6 @@ Lint/UselessAssign: - src/invidious/helpers/errors.cr - src/invidious/routes/**/*.cr -# Ignore false negative (if !db.query_one?...) -Lint/UnreachableCode: - Excluded: - - src/invidious/database/base.cr - # Ignore shadowed variable `key` (it works for now, and that's # a sensitive part of the code) Lint/ShadowingOuterLocalVar: diff --git a/src/invidious/database/base.cr b/src/invidious/database/base.cr index 0fb1b6af0..85ff620b7 100644 --- a/src/invidious/database/base.cr +++ b/src/invidious/database/base.cr @@ -32,6 +32,7 @@ module Invidious::Database def check_enum(enum_name, struct_type = nil) return # TODO + # ameba:disable Lint/UnreachableCode if !PG_DB.query_one?("SELECT true FROM pg_type WHERE typname = $1", enum_name, as: Bool) LOGGER.info("check_enum: CREATE TYPE #{enum_name}") From 9f96682783ff5e99f34610787f8e17f92f0801fe Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:17:05 +0100 Subject: [PATCH 21/27] Fix `Style/RedundantBegin` type of Ameba issues --- .ameba.yml | 3 --- src/invidious/user/preferences.cr | 24 +++++++++++------------- src/invidious/user/user.cr | 8 +++----- src/invidious/yt_backend/extractors.cr | 16 +++++++--------- 4 files changed, 21 insertions(+), 30 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 8a792e179..96d910be5 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -31,9 +31,6 @@ Lint/SpecFilename: # Style # -Style/RedundantBegin: - Enabled: false - Style/RedundantReturn: Enabled: false diff --git a/src/invidious/user/preferences.cr b/src/invidious/user/preferences.cr index df195dd69..18d7e3167 100644 --- a/src/invidious/user/preferences.cr +++ b/src/invidious/user/preferences.cr @@ -64,20 +64,18 @@ struct Preferences end def self.from_json(value : JSON::PullParser) : String - begin - result = value.read_string + result = value.read_string - if result.empty? - CONFIG.default_user_preferences.dark_mode - else - result - end - rescue ex - if value.read_bool - "dark" - else - "light" - end + if result.empty? + CONFIG.default_user_preferences.dark_mode + else + result + end + rescue ex + if value.read_bool + "dark" + else + "light" end end diff --git a/src/invidious/user/user.cr b/src/invidious/user/user.cr index a6d05fd19..fc0a58583 100644 --- a/src/invidious/user/user.cr +++ b/src/invidious/user/user.cr @@ -17,11 +17,9 @@ struct Invidious::User module PreferencesConverter def self.from_rs(rs) - begin - Preferences.from_json(rs.read(String)) - rescue ex - Preferences.from_json("{}") - end + Preferences.from_json(rs.read(String)) + rescue ex + Preferences.from_json("{}") end end end diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr index 22c184eee..fcb1b83af 100644 --- a/src/invidious/yt_backend/extractors.cr +++ b/src/invidious/yt_backend/extractors.cr @@ -37,15 +37,13 @@ record AuthorFallback, name : String, id : String private module Parsers module BaseParser def parse(*args) - begin - return parse_internal(*args) - rescue ex - LOGGER.debug("#{{{ @type.name }}}: Failed to render item.") - LOGGER.debug("#{{{ @type.name }}}: Got exception: #{ex.message}") - ProblematicTimelineItem.new( - parse_exception: ex - ) - end + return parse_internal(*args) + rescue ex + LOGGER.debug("#{{{ @type.name }}}: Failed to render item.") + LOGGER.debug("#{{{ @type.name }}}: Got exception: #{ex.message}") + ProblematicTimelineItem.new( + parse_exception: ex + ) end end From 9aec15745323d7444f964bb723f45b86533fdb4f Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 11 Jan 2026 23:17:53 +0100 Subject: [PATCH 22/27] Fix `Style/RedundantReturn` type of Ameba issues --- .ameba.yml | 3 - .../handlers/static_assets_handler_spec.cr | 4 +- spec/invidious/user/imports_spec.cr | 2 +- spec/parsers_helper.cr | 2 +- src/invidious/channels/channels.cr | 6 +- src/invidious/channels/community.cr | 10 +- src/invidious/channels/playlists.cr | 8 +- src/invidious/channels/videos.cr | 26 ++-- src/invidious/comments/content.cr | 4 +- src/invidious/comments/links_util.cr | 4 +- src/invidious/comments/youtube.cr | 8 +- src/invidious/config.cr | 10 +- src/invidious/database/annotations.cr | 2 +- src/invidious/database/base.cr | 2 +- src/invidious/database/channels.cr | 10 +- src/invidious/database/nonces.cr | 2 +- src/invidious/database/playlists.cr | 16 +-- src/invidious/database/users.cr | 8 +- src/invidious/database/videos.cr | 2 +- src/invidious/exceptions.cr | 2 +- src/invidious/frontend/channel_page.cr | 2 +- src/invidious/frontend/misc.cr | 4 +- src/invidious/frontend/pagination.cr | 4 +- src/invidious/frontend/search_filters.cr | 2 +- src/invidious/frontend/watch_page.cr | 2 +- src/invidious/hashtag.cr | 4 +- src/invidious/helpers/errors.cr | 18 +-- src/invidious/helpers/helpers.cr | 6 +- src/invidious/helpers/i18n.cr | 12 +- src/invidious/helpers/i18next.cr | 132 +++++++++--------- src/invidious/helpers/serialized_yt_data.cr | 2 +- src/invidious/helpers/tokens.cr | 10 +- src/invidious/helpers/utils.cr | 50 +++---- src/invidious/helpers/webvtt.cr | 2 +- .../http_server/static_assets_handler.cr | 4 +- src/invidious/http_server/utils.cr | 6 +- src/invidious/jobs/instance_refresh_job.cr | 6 +- src/invidious/mixes.cr | 2 +- src/invidious/playlists.cr | 18 +-- src/invidious/routes/account.cr | 4 +- src/invidious/routes/api/manifest.cr | 2 +- src/invidious/routes/api/v1/authenticated.cr | 6 +- src/invidious/routes/api/v1/channels.cr | 14 +- src/invidious/routes/api/v1/misc.cr | 4 +- src/invidious/routes/api/v1/search.cr | 2 +- src/invidious/routes/api/v1/videos.cr | 10 +- src/invidious/routes/channels.cr | 6 +- src/invidious/routes/companion.cr | 2 +- src/invidious/routes/images.cr | 2 +- src/invidious/routes/video_playback.cr | 4 +- src/invidious/routes/watch.cr | 12 +- src/invidious/search/ctoken.cr | 2 +- src/invidious/search/filters.cr | 14 +- src/invidious/search/processors.cr | 6 +- src/invidious/search/query.cr | 12 +- src/invidious/user/captcha.cr | 2 +- src/invidious/user/cookies.cr | 4 +- src/invidious/user/exports.cr | 2 +- src/invidious/user/imports.cr | 20 +-- src/invidious/user/preferences.cr | 4 +- src/invidious/videos.cr | 46 +++--- src/invidious/videos/caption.cr | 4 +- src/invidious/videos/description.cr | 4 +- src/invidious/videos/formats.cr | 2 +- src/invidious/videos/parser.cr | 12 +- src/invidious/videos/storyboard.cr | 2 +- src/invidious/videos/transcript.cr | 6 +- src/invidious/videos/video_preferences.cr | 2 +- src/invidious/yt_backend/connection_pool.cr | 8 +- src/invidious/yt_backend/extractors.cr | 66 ++++----- src/invidious/yt_backend/extractors_utils.cr | 10 +- src/invidious/yt_backend/url_sanitizer.cr | 14 +- src/invidious/yt_backend/youtube_api.cr | 28 ++-- 73 files changed, 376 insertions(+), 379 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 96d910be5..6b177fa5f 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -31,9 +31,6 @@ Lint/SpecFilename: # Style # -Style/RedundantReturn: - Enabled: false - Style/RedundantNext: Enabled: false diff --git a/spec/http_server/handlers/static_assets_handler_spec.cr b/spec/http_server/handlers/static_assets_handler_spec.cr index 268c4b2f4..8619380eb 100644 --- a/spec/http_server/handlers/static_assets_handler_spec.cr +++ b/spec/http_server/handlers/static_assets_handler_spec.cr @@ -14,7 +14,7 @@ require "spectator" require "../../../src/invidious/http_server/static_assets_handler.cr" private def get_static_assets_handler - return Invidious::HttpServer::StaticAssetsHandler.new "spec/http_server/handlers/static_assets_handler", directory_listing: false + Invidious::HttpServer::StaticAssetsHandler.new "spec/http_server/handlers/static_assets_handler", directory_listing: false end # Slightly modified version of `handle` function from @@ -125,7 +125,7 @@ Spectator.describe StaticAssetsHandler do gzip.gets_to_end end - return expect(decompressed) + expect(decompressed) end it "For full file requests" do diff --git a/spec/invidious/user/imports_spec.cr b/spec/invidious/user/imports_spec.cr index 58b5d4aab..2dffa1a9f 100644 --- a/spec/invidious/user/imports_spec.cr +++ b/spec/invidious/user/imports_spec.cr @@ -7,7 +7,7 @@ Spectator.configure do |config| end def csv_sample - return <<-CSV + <<-CSV Kanal-ID,Kanal-URL,Kanaltitel UC0hHW5Y08ggq-9kbrGgWj0A,http://www.youtube.com/channel/UC0hHW5Y08ggq-9kbrGgWj0A,Matias Marolla UC0vBXGSyV14uvJ4hECDOl0Q,http://www.youtube.com/channel/UC0vBXGSyV14uvJ4hECDOl0Q,Techquickie diff --git a/spec/parsers_helper.cr b/spec/parsers_helper.cr index 6589acad8..79e256d2d 100644 --- a/spec/parsers_helper.cr +++ b/spec/parsers_helper.cr @@ -26,7 +26,7 @@ def load_mock(file) : Hash(String, JSON::Any) file = File.join(__DIR__, "..", "mocks", file + ".json") content = File.read(file) - return JSON.parse(content).as_h + JSON.parse(content).as_h end Spectator.configure do |config| diff --git a/src/invidious/channels/channels.cr b/src/invidious/channels/channels.cr index 3c15d6359..400483bac 100644 --- a/src/invidious/channels/channels.cr +++ b/src/invidious/channels/channels.cr @@ -141,7 +141,7 @@ def get_batch_channels(channels) end end - return final + final end def get_channel(id) : InvidiousChannel @@ -152,7 +152,7 @@ def get_channel(id) : InvidiousChannel Invidious::Database::Channels.insert(channel, update_on_conflict: true) end - return channel + channel end def fetch_channel(ucid, pull_all_videos : Bool) @@ -292,5 +292,5 @@ def fetch_channel(ucid, pull_all_videos : Bool) end channel.updated = Time.utc - return channel + channel end diff --git a/src/invidious/channels/community.cr b/src/invidious/channels/community.cr index 4256230cb..48d089690 100644 --- a/src/invidious/channels/community.cr +++ b/src/invidious/channels/community.cr @@ -21,7 +21,7 @@ def fetch_channel_community(ucid, cursor, locale, format, thin_mode) items = container.as_a end - return extract_channel_community(items, ucid: ucid, locale: locale, format: format, thin_mode: thin_mode) + extract_channel_community(items, ucid: ucid, locale: locale, format: format, thin_mode: thin_mode) end def decode_ucid_from_post_protobuf(params) @@ -30,7 +30,7 @@ def decode_ucid_from_post_protobuf(params) .try { |i| IO::Memory.new(i) } .try { |i| Protodec::Any.parse(i) } - return decoded_protobuf.try(&.["56:0:embedded"]["2:0:string"].as_s) + decoded_protobuf.try(&.["56:0:embedded"]["2:0:string"].as_s) end def fetch_channel_community_post(ucid, post_id, locale, format, thin_mode) @@ -53,7 +53,7 @@ def fetch_channel_community_post(ucid, post_id, locale, format, thin_mode) items << item end - return extract_channel_community(items, ucid: ucid, locale: locale, format: format, thin_mode: thin_mode, is_single_post: true) + extract_channel_community(items, ucid: ucid, locale: locale, format: format, thin_mode: thin_mode, is_single_post: true) end def extract_channel_community(items, *, ucid, locale, format, thin_mode, is_single_post : Bool = false) @@ -294,7 +294,7 @@ def extract_channel_community(items, *, ucid, locale, format, thin_mode, is_sing end end - return response + response end def produce_channel_community_continuation(ucid, cursor) @@ -310,7 +310,7 @@ def produce_channel_community_continuation(ucid, cursor) .try { |i| Base64.urlsafe_encode(i) } .try { |i| URI.encode_www_form(i) } - return continuation + continuation end def extract_channel_community_cursor(continuation) diff --git a/src/invidious/channels/playlists.cr b/src/invidious/channels/playlists.cr index cba1abd9c..0f0089eab 100644 --- a/src/invidious/channels/playlists.cr +++ b/src/invidious/channels/playlists.cr @@ -24,7 +24,7 @@ def fetch_channel_playlists(ucid, author, continuation, sort_by) initial_data = YoutubeAPI.browse(ucid, params: params || "") end - return extract_items(initial_data, author, ucid) + extract_items(initial_data, author, ucid) end def fetch_channel_podcasts(ucid, author, continuation) @@ -33,7 +33,7 @@ def fetch_channel_podcasts(ucid, author, continuation) else initial_data = YoutubeAPI.browse(ucid, params: "Eghwb2RjYXN0c_IGBQoDugEA") end - return extract_items(initial_data, author, ucid) + extract_items(initial_data, author, ucid) end def fetch_channel_releases(ucid, author, continuation) @@ -42,7 +42,7 @@ def fetch_channel_releases(ucid, author, continuation) else initial_data = YoutubeAPI.browse(ucid, params: "EghyZWxlYXNlc_IGBQoDsgEA") end - return extract_items(initial_data, author, ucid) + extract_items(initial_data, author, ucid) end def fetch_channel_courses(ucid, author, continuation) @@ -51,5 +51,5 @@ def fetch_channel_courses(ucid, author, continuation) else initial_data = YoutubeAPI.browse(ucid, params: "Egdjb3Vyc2Vz8gYFCgPCAQA%3D") end - return extract_items(initial_data, author, ucid) + extract_items(initial_data, author, ucid) end diff --git a/src/invidious/channels/videos.cr b/src/invidious/channels/videos.cr index 96400f471..c5c66a513 100644 --- a/src/invidious/channels/videos.cr +++ b/src/invidious/channels/videos.cr @@ -9,7 +9,7 @@ module Invidious::Channel::Tabs # an author name and ucid directly (e.g in RSS feeds). # TODO: figure out how to get rid of that def get_videos(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest") - return get_videos( + get_videos( channel.author, channel.ucid, continuation: continuation, sort_by: sort_by ) @@ -19,7 +19,7 @@ module Invidious::Channel::Tabs # an author name and ucid directly (e.g in RSS feeds). # TODO: figure out how to get rid of that def get_videos(channel : InvidiousChannel, *, continuation : String? = nil, sort_by = "newest") - return get_videos( + get_videos( channel.author, channel.id, continuation: continuation, sort_by: sort_by ) @@ -29,7 +29,7 @@ module Invidious::Channel::Tabs continuation ||= make_initial_videos_ctoken(ucid, sort_by) initial_data = YoutubeAPI.browse(continuation: continuation) - return extract_items(initial_data, author, ucid) + extract_items(initial_data, author, ucid) end def get_60_videos(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest") @@ -59,7 +59,7 @@ module Invidious::Channel::Tabs continuation ||= make_initial_shorts_ctoken(channel.ucid, sort_by) initial_data = YoutubeAPI.browse(continuation: continuation) - return extract_items(initial_data, channel.author, channel.ucid) + extract_items(initial_data, channel.author, channel.ucid) end # ------------------- @@ -70,7 +70,7 @@ module Invidious::Channel::Tabs continuation ||= make_initial_livestreams_ctoken(channel.ucid, sort_by) initial_data = YoutubeAPI.browse(continuation: continuation) - return extract_items(initial_data, channel.author, channel.ucid) + extract_items(initial_data, channel.author, channel.ucid) end def get_60_livestreams(channel : AboutChannel, *, continuation : String? = nil, sort_by = "newest") @@ -98,10 +98,10 @@ module Invidious::Channel::Tabs private def sort_options_videos_short(sort_by : String) case sort_by - when "newest" then return 4_i64 - when "popular" then return 2_i64 - when "oldest" then return 5_i64 - else return 4_i64 # Fallback to "newest" + when "newest" then 4_i64 + when "popular" then 2_i64 + when "oldest" then 5_i64 + else 4_i64 # Fallback to "newest" end end @@ -118,7 +118,7 @@ module Invidious::Channel::Tabs }, } - return channel_ctoken_wrap(ucid, object) + channel_ctoken_wrap(ucid, object) end # Generate the initial "continuation token" to get the first page of the @@ -134,7 +134,7 @@ module Invidious::Channel::Tabs }, } - return channel_ctoken_wrap(ucid, object) + channel_ctoken_wrap(ucid, object) end # Generate the initial "continuation token" to get the first page of the @@ -158,7 +158,7 @@ module Invidious::Channel::Tabs }, } - return channel_ctoken_wrap(ucid, object) + channel_ctoken_wrap(ucid, object) end # The protobuf structure common between videos/shorts/livestreams @@ -187,6 +187,6 @@ module Invidious::Channel::Tabs .try { |i| Base64.urlsafe_encode(i) } .try { |i| URI.encode_www_form(i) } - return continuation + continuation end end diff --git a/src/invidious/comments/content.cr b/src/invidious/comments/content.cr index 1f55bfe65..bd29b229a 100644 --- a/src/invidious/comments/content.cr +++ b/src/invidious/comments/content.cr @@ -37,7 +37,7 @@ def text_to_parsed_content(text : String) : JSON::Any nodes << (node) end end - return JSON.parse({"runs" => nodes}.to_json) + JSON.parse({"runs" => nodes}.to_json) end def parse_content(content : JSON::Any, video_id : String? = "") : String @@ -85,5 +85,5 @@ def content_to_comment_html(content, video_id : String? = "") text end - return html_array.join("").delete('\ufeff') + html_array.join("").delete('\ufeff') end diff --git a/src/invidious/comments/links_util.cr b/src/invidious/comments/links_util.cr index f89b86d32..c82345191 100644 --- a/src/invidious/comments/links_util.cr +++ b/src/invidious/comments/links_util.cr @@ -45,7 +45,7 @@ module Invidious::Comments html = node end - return html.to_xml(options: XML::SaveOptions::NO_DECL) + html.to_xml(options: XML::SaveOptions::NO_DECL) end def fill_links(html, scheme, host) @@ -71,6 +71,6 @@ module Invidious::Comments html = html.xpath_node(%q(//body/p)).not_nil! end - return html.to_xml(options: XML::SaveOptions::NO_DECL) + html.to_xml(options: XML::SaveOptions::NO_DECL) end end diff --git a/src/invidious/comments/youtube.cr b/src/invidious/comments/youtube.cr index e923b2f8d..c74342699 100644 --- a/src/invidious/comments/youtube.cr +++ b/src/invidious/comments/youtube.cr @@ -13,7 +13,7 @@ module Invidious::Comments client_config = YoutubeAPI::ClientConfig.new(region: region) response = YoutubeAPI.next(continuation: ctoken, client_config: client_config) - return parse_youtube(id, response, format, locale, thin_mode, sort_by) + parse_youtube(id, response, format, locale, thin_mode, sort_by) end def fetch_community_post_comments(ucid, post_id, sort_by = "top") @@ -58,7 +58,7 @@ module Invidious::Comments .try { |i| URI.encode_www_form(i) } initial_data = YoutubeAPI.browse(continuation: continuation) - return initial_data + initial_data end def parse_youtube(id, response, format, locale, thin_mode, sort_by = "top", is_post = false) @@ -320,7 +320,7 @@ module Invidious::Comments end end - return response + response end def produce_continuation(video_id, cursor = "", sort_by = "top") @@ -364,6 +364,6 @@ module Invidious::Comments .try { |i| Base64.urlsafe_encode(i) } .try { |i| URI.encode_www_form(i) } - return continuation + continuation end end diff --git a/src/invidious/config.cr b/src/invidious/config.cr index d24939923..e439b0645 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -183,15 +183,15 @@ class Config def disabled?(option) case disabled = CONFIG.disable_proxy when Bool - return disabled + disabled when Array if disabled.includes? option - return true + true else - return false + false end else - return false + false end end @@ -318,6 +318,6 @@ class Config end end - return config + config end end diff --git a/src/invidious/database/annotations.cr b/src/invidious/database/annotations.cr index f1659509a..4bd3a2cf7 100644 --- a/src/invidious/database/annotations.cr +++ b/src/invidious/database/annotations.cr @@ -19,6 +19,6 @@ module Invidious::Database::Annotations WHERE id = $1 SQL - return PG_DB.query_one?(request, id, as: Annotation) + PG_DB.query_one?(request, id, as: Annotation) end end diff --git a/src/invidious/database/base.cr b/src/invidious/database/base.cr index 85ff620b7..a70516f2d 100644 --- a/src/invidious/database/base.cr +++ b/src/invidious/database/base.cr @@ -132,6 +132,6 @@ module Invidious::Database end end - return column_array + column_array end end diff --git a/src/invidious/database/channels.cr b/src/invidious/database/channels.cr index 3e7f480ce..e967332c5 100644 --- a/src/invidious/database/channels.cr +++ b/src/invidious/database/channels.cr @@ -72,7 +72,7 @@ module Invidious::Database::Channels WHERE id = $1 SQL - return PG_DB.query_one?(request, id, as: InvidiousChannel) + PG_DB.query_one?(request, id, as: InvidiousChannel) end def select(ids : Array(String)) : Array(InvidiousChannel)? @@ -83,7 +83,7 @@ module Invidious::Database::Channels WHERE id = ANY($1) SQL - return PG_DB.query_all(request, ids, as: InvidiousChannel) + PG_DB.query_all(request, ids, as: InvidiousChannel) end end @@ -114,7 +114,7 @@ module Invidious::Database::ChannelVideos RETURNING (xmax=0) AS was_insert SQL - return PG_DB.query_one(request, *video.to_tuple, as: Bool) + PG_DB.query_one(request, *video.to_tuple, as: Bool) end # ------------------- @@ -130,7 +130,7 @@ module Invidious::Database::ChannelVideos ORDER BY published DESC SQL - return PG_DB.query_all(request, ids, as: ChannelVideo) + PG_DB.query_all(request, ids, as: ChannelVideo) end def select_notfications(ucid : String, since : Time) : Array(ChannelVideo) @@ -141,7 +141,7 @@ module Invidious::Database::ChannelVideos LIMIT 15 SQL - return PG_DB.query_all(request, ucid, since, as: ChannelVideo) + PG_DB.query_all(request, ucid, since, as: ChannelVideo) end def select_popular_videos : Array(ChannelVideo) diff --git a/src/invidious/database/nonces.cr b/src/invidious/database/nonces.cr index 55c8d8560..38b8d44d1 100644 --- a/src/invidious/database/nonces.cr +++ b/src/invidious/database/nonces.cr @@ -50,6 +50,6 @@ module Invidious::Database::Nonces WHERE nonce = $1 SQL - return PG_DB.query_one?(request, nonce, as: {String, Time}) + PG_DB.query_one?(request, nonce, as: {String, Time}) end end diff --git a/src/invidious/database/playlists.cr b/src/invidious/database/playlists.cr index ba1e5b0a8..fe06c52cc 100644 --- a/src/invidious/database/playlists.cr +++ b/src/invidious/database/playlists.cr @@ -100,7 +100,7 @@ module Invidious::Database::Playlists WHERE id = $1 SQL - return PG_DB.query_one?(request, id, as: InvidiousPlaylist) + PG_DB.query_one?(request, id, as: InvidiousPlaylist) end def select_all(*, author : String) : Array(InvidiousPlaylist) @@ -109,7 +109,7 @@ module Invidious::Database::Playlists WHERE author = $1 SQL - return PG_DB.query_all(request, author, as: InvidiousPlaylist) + PG_DB.query_all(request, author, as: InvidiousPlaylist) end # ------------------- @@ -157,7 +157,7 @@ module Invidious::Database::Playlists WHERE id = $1 SQL - return PG_DB.query_one?(request, id, as: String).nil? + PG_DB.query_one?(request, id, as: String).nil? end # Count how many playlist a user has created. @@ -167,7 +167,7 @@ module Invidious::Database::Playlists WHERE author = $1 SQL - return PG_DB.query_one?(request, author, as: Int64) || 0_i64 + PG_DB.query_one?(request, author, as: Int64) || 0_i64 end end @@ -225,7 +225,7 @@ module Invidious::Database::PlaylistVideos OFFSET $4 SQL - return PG_DB.query_all(request, plid, index, limit, offset, as: PlaylistVideo) + PG_DB.query_all(request, plid, index, limit, offset, as: PlaylistVideo) end def select_index(plid : String, vid : String) : Int64? @@ -235,7 +235,7 @@ module Invidious::Database::PlaylistVideos LIMIT 1 SQL - return PG_DB.query_one?(request, plid, vid, as: Int64) + PG_DB.query_one?(request, plid, vid, as: Int64) end def select_one_id(plid : String, index : VideoIndex) : String? @@ -246,7 +246,7 @@ module Invidious::Database::PlaylistVideos LIMIT 1 SQL - return PG_DB.query_one?(request, plid, index, as: String) + PG_DB.query_one?(request, plid, index, as: String) end def select_ids(plid : String, index : VideoIndex, limit = 500) : Array(String) @@ -257,6 +257,6 @@ module Invidious::Database::PlaylistVideos LIMIT $3 SQL - return PG_DB.query_all(request, plid, index, limit, as: String) + PG_DB.query_all(request, plid, index, limit, as: String) end end diff --git a/src/invidious/database/users.cr b/src/invidious/database/users.cr index 9b297930f..15149cae3 100644 --- a/src/invidious/database/users.cr +++ b/src/invidious/database/users.cr @@ -194,7 +194,7 @@ module Invidious::Database::Users WHERE email = $1 SQL - return PG_DB.query_one?(request, email, as: User) + PG_DB.query_one?(request, email, as: User) end # Same as select, but can raise an exception @@ -204,7 +204,7 @@ module Invidious::Database::Users WHERE email = $1 SQL - return PG_DB.query_one(request, email, as: User) + PG_DB.query_one(request, email, as: User) end def select(*, token : String) : User? @@ -213,7 +213,7 @@ module Invidious::Database::Users WHERE token = $1 SQL - return PG_DB.query_one?(request, token, as: User) + PG_DB.query_one?(request, token, as: User) end def select_notifications(user : User) : Array(String) @@ -223,6 +223,6 @@ module Invidious::Database::Users WHERE email = $1 SQL - return PG_DB.query_one(request, user.email, as: Array(String)) + PG_DB.query_one(request, user.email, as: Array(String)) end end diff --git a/src/invidious/database/videos.cr b/src/invidious/database/videos.cr index 40bafaf1d..28ac8850a 100644 --- a/src/invidious/database/videos.cr +++ b/src/invidious/database/videos.cr @@ -47,6 +47,6 @@ module Invidious::Database::Videos WHERE id = $1 SQL - return PG_DB.query_one?(request, id, as: Video) + PG_DB.query_one?(request, id, as: Video) end end diff --git a/src/invidious/exceptions.cr b/src/invidious/exceptions.cr index 690db9077..b8416811a 100644 --- a/src/invidious/exceptions.cr +++ b/src/invidious/exceptions.cr @@ -23,7 +23,7 @@ class BrokenTubeException < Exception end def message - return "Missing JSON element \"#{@element}\"" + "Missing JSON element \"#{@element}\"" end end diff --git a/src/invidious/frontend/channel_page.cr b/src/invidious/frontend/channel_page.cr index 4fe21b964..afcb69fc6 100644 --- a/src/invidious/frontend/channel_page.cr +++ b/src/invidious/frontend/channel_page.cr @@ -14,7 +14,7 @@ module Invidious::Frontend::ChannelPage end def generate_tabs_links(locale : String, channel : AboutChannel, selected_tab : TabsAvailable) - return String.build(1500) do |str| + String.build(1500) do |str| base_url = "/channel/#{channel.ucid}" TabsAvailable.each do |tab| diff --git a/src/invidious/frontend/misc.cr b/src/invidious/frontend/misc.cr index 9c30724a5..961ec2de4 100644 --- a/src/invidious/frontend/misc.cr +++ b/src/invidious/frontend/misc.cr @@ -6,9 +6,9 @@ module Invidious::Frontend::Misc if preferences.automatic_instance_redirect current_page = env.get?("current_page").as(String) - return "/redirect?referer=#{current_page}" + "/redirect?referer=#{current_page}" else - return "https://redirect.invidious.io#{env.request.resource}" + "https://redirect.invidious.io#{env.request.resource}" end end end diff --git a/src/invidious/frontend/pagination.cr b/src/invidious/frontend/pagination.cr index d2bf0e7e6..e3ab7b3ea 100644 --- a/src/invidious/frontend/pagination.cr +++ b/src/invidious/frontend/pagination.cr @@ -60,7 +60,7 @@ module Invidious::Frontend::Pagination end def nav_numeric(locale : String?, *, base_url : String | URI, current_page : Int, show_next : Bool = true) - return String.build do |str| + String.build do |str| str << %(
\n) str << %(