Invidious is an alternative front-end to YouTube
Fix more 'Lint/ShadowingOuterLocalVar' warnings reported by ameba
Samantaz Fox12b818a83ce1
diff --git a/src/invidious/channels/about.cr b/src/invidious/channels/about.crindex 8cae7ae2..0f3928f5 100644--- a/src/invidious/channels/about.cr+++ b/src/invidious/channels/about.cr@@ -96,7 +96,7 @@ def get_about_info(ucid, locale) : AboutChanneltotal_views = channel_about_meta["viewCountText"]?.try &.["simpleText"]?.try &.as_s.gsub(/\D/, "").to_i64? || 0_i64# The joined text is split to several sub strings. The reduce joins those strings before parsing the date.- joined = channel_about_meta["joinedDateText"]?.try &.["runs"]?.try &.as_a.reduce("") { |acc, node| acc + node["text"].as_s }+ joined = channel_about_meta["joinedDateText"]?.try &.["runs"]?.try &.as_a.reduce("") { |acc, nd| acc + nd["text"].as_s }.try { |text| Time.parse(text, "Joined %b %-d, %Y", Time::Location.local) } || Time.unix(0)# Normal Auto-generated channels@@ -136,7 +136,8 @@ def fetch_related_channels(about_channel : AboutChannel) : Array(AboutRelatedChachannels = YoutubeAPI.browse(browse_id: about_channel.ucid, params: "EghjaGFubmVscw%3D%3D")tabs = channels.dig?("contents", "twoColumnBrowseResultsRenderer", "tabs").try(&.as_a?) || [] of JSON::Any- tab = tabs.find { |tab| tab.dig?("tabRenderer", "title").try(&.as_s?) == "Channels" }+ tab = tabs.find(&.dig?("tabRenderer", "title").try(&.as_s?).try(&.== "Channels"))+return [] of AboutRelatedChannel if tab.nil?items = tab.dig?("tabRenderer", "content", "sectionListRenderer", "contents", 0, "itemSectionRenderer", "contents", 0, "gridRenderer", "items").try(&.as_a?) || [] of JSON::Anydiff --git a/src/invidious/helpers/i18n.cr b/src/invidious/helpers/i18n.crindex e88e4491..3cf9ad1c 100644--- a/src/invidious/helpers/i18n.cr+++ b/src/invidious/helpers/i18n.cr@@ -94,8 +94,8 @@ def translate(locale : String?, key : String, text : String | Nil = nil) : Strintranslation = ""match_length = 0- raw_data.as_h.each do |key, value|- if md = text.try &.match(/#{key}/)+ raw_data.as_h.each do |hash_key, value|+ if md = text.try &.match(/#{hash_key}/)if md[0].size >= match_lengthtranslation = value.as_smatch_length = md[0].sizediff --git a/src/invidious/helpers/json_filter.cr b/src/invidious/helpers/json_filter.crindex e4b57cea..b8e8f96d 100644--- a/src/invidious/helpers/json_filter.cr+++ b/src/invidious/helpers/json_filter.cr@@ -98,9 +98,9 @@ module JSONFilterendend- group_name.split('/').each do |group_name|+ group_name.split('/').each do |name|nest_stack.push({- group_name: group_name,+ group_name: name,closing_bracket_index: closing_bracket_index,})enddiff --git a/src/invidious/helpers/static_file_handler.cr b/src/invidious/helpers/static_file_handler.crindex 630c2fd2..6b3cd22e 100644--- a/src/invidious/helpers/static_file_handler.cr+++ b/src/invidious/helpers/static_file_handler.cr@@ -175,9 +175,9 @@ module Kemalif @cached_files.sum(&.[1][:data].bytesize) + (size = File.size(file_path)) < CACHE_LIMITdata = Bytes.new(size)- File.open(file_path) do |file|- file.read(data)- end++ File.open(file_path) { |f| f.read(data) }+filestat = File.info(file_path)@cached_files[file_path] = {data: data, filestat: filestat}diff --git a/src/invidious/helpers/tokens.cr b/src/invidious/helpers/tokens.crindex 8b076e39..9b664646 100644--- a/src/invidious/helpers/tokens.cr+++ b/src/invidious/helpers/tokens.cr@@ -42,6 +42,9 @@ enddef sign_token(key, hash)string_to_sign = [] of String+ # TODO: figure out which "key" variable is used+ # Ameba reports a warning for "Lint/ShadowingOuterLocalVar" on this+ # variable, but its preferrable to not touch that (works fine atm).hash.each do |key, value|next if key == "signature"diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.crindex 09181c10..3ab9a0fc 100644--- a/src/invidious/helpers/utils.cr+++ b/src/invidious/helpers/utils.cr@@ -292,8 +292,8 @@ def parse_range(range)endranges = range.lchop("bytes=").split(',')- ranges.each do |range|- start_range, end_range = range.split('-')+ ranges.each do |r|+ start_range, end_range = r.split('-')start_range = start_range.to_i64? || 0_i64end_range = end_range.to_i64?diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.crindex afbc8624..177cee0f 100644--- a/src/invidious/playlists.cr+++ b/src/invidious/playlists.cr@@ -202,8 +202,8 @@ struct InvidiousPlaylistendvideos = get_playlist_videos(self, offset: offset, video_id: video_id)- videos.each_with_index do |video, index|- video.to_json(json, offset + index)+ videos.each_with_index do |video, idx|+ video.to_json(json, offset + idx)endendenddiff --git a/src/invidious/routes/api/manifest.cr b/src/invidious/routes/api/manifest.crindex b6183001..ca429df5 100644--- a/src/invidious/routes/api/manifest.cr+++ b/src/invidious/routes/api/manifest.cr@@ -98,7 +98,7 @@ module Invidious::Routes::API::Manifestheight = fmt["height"].as_i# Resolutions reported by YouTube player (may not accurately reflect source)- height = potential_heights.min_by { |i| (height - i).abs }+ height = potential_heights.min_by { |x| (height - x).abs }next if unique_res && heights.includes? heightheights << heightdiff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.crindex 64da3e4e..f4859e6f 100644--- a/src/invidious/routes/login.cr+++ b/src/invidious/routes/login.cr@@ -425,9 +425,9 @@ module Invidious::Routes::Loginfound_valid_captcha = falseerror_exception = Exception.new- tokens.each do |token|+ tokens.each do |tok|begin- validate_request(token, answer, env.request, HMAC_KEY, locale)+ validate_request(tok, answer, env.request, HMAC_KEY, locale)found_valid_captcha = truerescue exerror_exception = exdiff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex 499ed94d..5cec1175 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -661,8 +661,8 @@ struct Videourl = URI.parse(storyboards.shift)params = HTTP::Params.parse(url.query || "")- storyboards.each_with_index do |storyboard, i|- width, height, count, storyboard_width, storyboard_height, interval, _, sigh = storyboard.split("#")+ storyboards.each_with_index do |sb, i|+ width, height, count, storyboard_width, storyboard_height, interval, _, sigh = sb.split("#")params["sigh"] = sighurl.query = params.to_s