From 8258062ec512f9adf9523e259fbb0d33552329e9 Mon Sep 17 00:00:00 2001 From: syeopite Date: Mon, 15 Jul 2024 17:36:00 -0700 Subject: [PATCH 1/2] Ameba: Fix Lint/NotNilAfterNoBang --- src/invidious/helpers/signatures.cr | 16 ++++++++-------- src/invidious/routes/api/v1/videos.cr | 4 ++-- src/invidious/user/imports.cr | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/invidious/helpers/signatures.cr b/src/invidious/helpers/signatures.cr index ee09415b..38ded969 100644 --- a/src/invidious/helpers/signatures.cr +++ b/src/invidious/helpers/signatures.cr @@ -13,20 +13,20 @@ struct DecryptFunction private def fetch_decrypt_function(id = "CvFH_6DNRCY") document = YT_POOL.client &.get("/watch?v=#{id}&gl=US&hl=en").body - url = document.match(/src="(?\/s\/player\/[^\/]+\/player_ias[^\/]+\/en_US\/base.js)"/).not_nil!["url"] + url = document.match!(/src="(?\/s\/player\/[^\/]+\/player_ias[^\/]+\/en_US\/base.js)"/)["url"] player = YT_POOL.client &.get(url).body - function_name = player.match(/^(?[^=]+)=function\(\w\){\w=\w\.split\(""\);[^\. ]+\.[^( ]+/m).not_nil!["name"] - function_body = player.match(/^#{Regex.escape(function_name)}=function\(\w\){(?[^}]+)}/m).not_nil!["body"] + function_name = player.match!(/^(?[^=]+)=function\(\w\){\w=\w\.split\(""\);[^\. ]+\.[^( ]+/m)["name"] + function_body = player.match!(/^#{Regex.escape(function_name)}=function\(\w\){(?[^}]+)}/m)["body"] function_body = function_body.split(";")[1..-2] var_name = function_body[0][0, 2] - var_body = player.delete("\n").match(/var #{Regex.escape(var_name)}={(?(.*?))};/).not_nil!["body"] + var_body = player.delete("\n").match!(/var #{Regex.escape(var_name)}={(?(.*?))};/)["body"] operations = {} of String => SigProc var_body.split("},").each do |operation| - op_name = operation.match(/^[^:]+/).not_nil![0] - op_body = operation.match(/\{[^}]+/).not_nil![0] + op_name = operation.match!(/^[^:]+/)[0] + op_body = operation.match!(/\{[^}]+/)[0] case op_body when "{a.reverse()" @@ -42,8 +42,8 @@ struct DecryptFunction function_body.each do |function| function = function.lchop(var_name).delete("[].") - op_name = function.match(/[^\(]+/).not_nil![0] - value = function.match(/\(\w,(?[\d]+)\)/).not_nil!["value"].to_i + op_name = function.match!(/[^\(]+/)[0] + value = function.match!(/\(\w,(?[\d]+)\)/)["value"].to_i decrypt_function << {operations[op_name], value} end diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index faff2f59..4fc6a205 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -215,7 +215,7 @@ module Invidious::Routes::API::V1::Videos storyboard[:storyboard_count].times do |i| url = storyboard[:url] - authority = /(i\d?).ytimg.com/.match(url).not_nil![1]? + authority = /(i\d?).ytimg.com/.match!(url)[1]? url = url.gsub("$M", i).gsub(%r(https://i\d?.ytimg.com/sb/), "") url = "#{HOST_URL}/sb/#{authority}/#{url}" @@ -250,7 +250,7 @@ module Invidious::Routes::API::V1::Videos if CONFIG.cache_annotations && (cached_annotation = Invidious::Database::Annotations.select(id)) annotations = cached_annotation.annotations else - index = CHARS_SAFE.index(id[0]).not_nil!.to_s.rjust(2, '0') + index = CHARS_SAFE.index!(id[0]).to_s.rjust(2, '0') # IA doesn't handle leading hyphens, # so we use https://archive.org/details/youtubeannotations_64 diff --git a/src/invidious/user/imports.cr b/src/invidious/user/imports.cr index 108f2ccc..29b59293 100644 --- a/src/invidious/user/imports.cr +++ b/src/invidious/user/imports.cr @@ -182,7 +182,7 @@ struct Invidious::User if is_opml?(type, extension) subscriptions = XML.parse(body) user.subscriptions += subscriptions.xpath_nodes(%q(//outline[@type="rss"])).map do |channel| - channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0] + channel["xmlUrl"].match!(/UC[a-zA-Z0-9_-]{22}/)[0] end elsif extension == "json" || type == "application/json" subscriptions = JSON.parse(body) From 3415507e4a9545addc21e4a985a6c0097ba9cf8b Mon Sep 17 00:00:00 2001 From: syeopite Date: Wed, 24 Jul 2024 19:48:34 -0700 Subject: [PATCH 2/2] Ameba: undo Lint/NotNilAfterNoBang in signatures.cr File is set to be removed with #4772 --- src/invidious/helpers/signatures.cr | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/invidious/helpers/signatures.cr b/src/invidious/helpers/signatures.cr index 38ded969..ee09415b 100644 --- a/src/invidious/helpers/signatures.cr +++ b/src/invidious/helpers/signatures.cr @@ -13,20 +13,20 @@ struct DecryptFunction private def fetch_decrypt_function(id = "CvFH_6DNRCY") document = YT_POOL.client &.get("/watch?v=#{id}&gl=US&hl=en").body - url = document.match!(/src="(?\/s\/player\/[^\/]+\/player_ias[^\/]+\/en_US\/base.js)"/)["url"] + url = document.match(/src="(?\/s\/player\/[^\/]+\/player_ias[^\/]+\/en_US\/base.js)"/).not_nil!["url"] player = YT_POOL.client &.get(url).body - function_name = player.match!(/^(?[^=]+)=function\(\w\){\w=\w\.split\(""\);[^\. ]+\.[^( ]+/m)["name"] - function_body = player.match!(/^#{Regex.escape(function_name)}=function\(\w\){(?[^}]+)}/m)["body"] + function_name = player.match(/^(?[^=]+)=function\(\w\){\w=\w\.split\(""\);[^\. ]+\.[^( ]+/m).not_nil!["name"] + function_body = player.match(/^#{Regex.escape(function_name)}=function\(\w\){(?[^}]+)}/m).not_nil!["body"] function_body = function_body.split(";")[1..-2] var_name = function_body[0][0, 2] - var_body = player.delete("\n").match!(/var #{Regex.escape(var_name)}={(?(.*?))};/)["body"] + var_body = player.delete("\n").match(/var #{Regex.escape(var_name)}={(?(.*?))};/).not_nil!["body"] operations = {} of String => SigProc var_body.split("},").each do |operation| - op_name = operation.match!(/^[^:]+/)[0] - op_body = operation.match!(/\{[^}]+/)[0] + op_name = operation.match(/^[^:]+/).not_nil![0] + op_body = operation.match(/\{[^}]+/).not_nil![0] case op_body when "{a.reverse()" @@ -42,8 +42,8 @@ struct DecryptFunction function_body.each do |function| function = function.lchop(var_name).delete("[].") - op_name = function.match!(/[^\(]+/)[0] - value = function.match!(/\(\w,(?[\d]+)\)/)["value"].to_i + op_name = function.match(/[^\(]+/).not_nil![0] + value = function.match(/\(\w,(?[\d]+)\)/).not_nil!["value"].to_i decrypt_function << {operations[op_name], value} end