Invidious is an alternative front-end to YouTube
Fix some 'Lint/ShadowingOuterLocalVar' warnings reported by ameba
Samantaz Fox1c91110464e7
diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.crindex 5d2b4c1c..5da6143b 100644--- a/src/invidious/routes/api/v1/authenticated.cr+++ b/src/invidious/routes/api/v1/authenticated.cr@@ -138,7 +138,7 @@ module Invidious::Routes::API::V1::Authenticatedreturn error_json(400, "Invalid title.")end- privacy = env.params.json["privacy"]?.try { |privacy| PlaylistPrivacy.parse(privacy.as(String).downcase) }+ privacy = env.params.json["privacy"]?.try { |p| PlaylistPrivacy.parse(p.as(String).downcase) }if !privacyreturn error_json(400, "Invalid privacy setting.")end@@ -175,7 +175,7 @@ module Invidious::Routes::API::V1::Authenticatedendtitle = env.params.json["title"].try &.as(String).delete("<>").byte_slice(0, 150) || playlist.title- privacy = env.params.json["privacy"]?.try { |privacy| PlaylistPrivacy.parse(privacy.as(String).downcase) } || playlist.privacy+ privacy = env.params.json["privacy"]?.try { |p| PlaylistPrivacy.parse(p.as(String).downcase) } || playlist.privacydescription = env.params.json["description"]?.try &.as(String).delete("\r") || playlist.descriptionif title != playlist.title ||diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.crindex be0f699b..86eb26ee 100644--- a/src/invidious/routes/api/v1/videos.cr+++ b/src/invidious/routes/api/v1/videos.cr@@ -71,9 +71,9 @@ module Invidious::Routes::API::V1::Videosenv.response.content_type = "text/vtt; charset=UTF-8"if lang- caption = captions.select { |caption| caption.language_code == lang }+ caption = captions.select(&.language_code.== lang)else- caption = captions.select { |caption| caption.name == label }+ caption = captions.select(&.name.== label)endif caption.empty?@@ -179,7 +179,7 @@ module Invidious::Routes::API::V1::Videosenv.response.content_type = "text/vtt"- storyboard = storyboards.select { |storyboard| width == "#{storyboard[:width]}" || height == "#{storyboard[:height]}" }+ storyboard = storyboards.select { |sb| width == "#{sb[:width]}" || height == "#{sb[:height]}" }if storyboard.empty?haltf env, 404diff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.crindex 8a58b034..f6340c57 100644--- a/src/invidious/routes/video_playback.cr+++ b/src/invidious/routes/video_playback.cr@@ -75,8 +75,8 @@ module Invidious::Routes::VideoPlaybackendbegin- client.get(url, headers) do |response|- response.headers.each do |key, value|+ client.get(url, headers) do |resp|+ resp.headers.each do |key, value|if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)env.response.headers[key] = valueend@@ -84,7 +84,7 @@ module Invidious::Routes::VideoPlaybackenv.response.headers["Access-Control-Allow-Origin"] = "*"- if location = response.headers["Location"]?+ if location = resp.headers["Location"]?location = URI.parse(location)location = "#{location.request_target}&host=#{location.host}"@@ -95,7 +95,7 @@ module Invidious::Routes::VideoPlaybackreturn env.redirect locationend- IO.copy(response.body_io, env.response)+ IO.copy(resp.body_io, env.response)endrescue exend@@ -132,15 +132,15 @@ module Invidious::Routes::VideoPlaybackheaders["Range"] = "bytes=#{chunk_start}-#{chunk_end}"begin- client.get(url, headers) do |response|+ client.get(url, headers) do |resp|if first_chunk- if !env.request.headers["Range"]? && response.status_code == 206+ if !env.request.headers["Range"]? && resp.status_code == 206env.response.status_code = 200else- env.response.status_code = response.status_code+ env.response.status_code = resp.status_codeend- response.headers.each do |key, value|+ resp.headers.each do |key, value|if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) && key.downcase != "content-range"env.response.headers[key] = valueend@@ -148,7 +148,7 @@ module Invidious::Routes::VideoPlaybackenv.response.headers["Access-Control-Allow-Origin"] = "*"- if location = response.headers["Location"]?+ if location = resp.headers["Location"]?location = URI.parse(location)location = "#{location.request_target}&host=#{location.host}#{region ? "®ion=#{region}" : ""}"@@ -161,8 +161,8 @@ module Invidious::Routes::VideoPlaybackenv.response.headers["Content-Disposition"] = "attachment; filename=\"#{URI.encode_www_form(title)}\"; filename*=UTF-8''#{URI.encode_www_form(title)}"end- if !response.headers.includes_word?("Transfer-Encoding", "chunked")- content_length = response.headers["Content-Range"].split("/")[-1].to_i64+ if !resp.headers.includes_word?("Transfer-Encoding", "chunked")+ content_length = resp.headers["Content-Range"].split("/")[-1].to_i64if env.request.headers["Range"]?env.response.headers["Content-Range"] = "bytes #{range_start}-#{range_end || (content_length - 1)}/#{content_length}"env.response.content_length = ((range_end.try &.+ 1) || content_length) - range_start@@ -172,7 +172,7 @@ module Invidious::Routes::VideoPlaybackendend- proxy_file(response, env)+ proxy_file(resp, env)endrescue exif ex.message != "Error reading socket: Connection reset by peer"