Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ameba: Fix Naming/VariableNames #4790

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/invidious/comments/content.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ def text_to_parsed_content(text : String) : JSON::Any
# In first case line is just a simple node before
# check patterns inside line
# { 'text': line }
currentNodes = [] of JSON::Any
initialNode = {"text" => line}
currentNodes << (JSON.parse(initialNode.to_json))
current_nodes = [] of JSON::Any
initial_node = {"text" => line}
current_nodes << (JSON.parse(initial_node.to_json))

# For each match with url pattern, get last node and preserve
# last node before create new node with url information
# { 'text': match, 'navigationEndpoint': { 'urlEndpoint' : 'url': match } }
line.scan(/https?:\/\/[^ ]*/).each do |urlMatch|
line.scan(/https?:\/\/[^ ]*/).each do |url_match|
# Retrieve last node and update node without match
lastNode = currentNodes[currentNodes.size - 1].as_h
splittedLastNode = lastNode["text"].as_s.split(urlMatch[0])
lastNode["text"] = JSON.parse(splittedLastNode[0].to_json)
currentNodes[currentNodes.size - 1] = JSON.parse(lastNode.to_json)
last_node = current_nodes[current_nodes.size - 1].as_h
syeopite marked this conversation as resolved.
Show resolved Hide resolved
splitted_last_node = last_node["text"].as_s.split(url_match[0])
last_node["text"] = JSON.parse(splitted_last_node[0].to_json)
current_nodes[current_nodes.size - 1] = JSON.parse(last_node.to_json)
# Create new node with match and navigation infos
currentNode = {"text" => urlMatch[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => urlMatch[0]}}}
currentNodes << (JSON.parse(currentNode.to_json))
current_node = {"text" => url_match[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => url_match[0]}}}
current_nodes << (JSON.parse(current_node.to_json))
# If text remain after match create new simple node with text after match
afterNode = {"text" => splittedLastNode.size > 1 ? splittedLastNode[1] : ""}
currentNodes << (JSON.parse(afterNode.to_json))
after_node = {"text" => splitted_last_node.size > 1 ? splitted_last_node[1] : ""}
current_nodes << (JSON.parse(after_node.to_json))
end

# After processing of matches inside line
# Add \n at end of last node for preserve carriage return
lastNode = currentNodes[currentNodes.size - 1].as_h
lastNode["text"] = JSON.parse("#{currentNodes[currentNodes.size - 1]["text"]}\n".to_json)
currentNodes[currentNodes.size - 1] = JSON.parse(lastNode.to_json)
last_node = current_nodes[current_nodes.size - 1].as_h
last_node["text"] = JSON.parse("#{current_nodes[current_nodes.size - 1]["text"]}\n".to_json)
current_nodes[current_nodes.size - 1] = JSON.parse(last_node.to_json)
syeopite marked this conversation as resolved.
Show resolved Hide resolved

# Finally add final nodes to nodes returned
currentNodes.each do |node|
current_nodes.each do |node|
nodes << (node)
end
end
Expand All @@ -53,8 +53,8 @@ def content_to_comment_html(content, video_id : String? = "")

text = HTML.escape(run["text"].as_s)

if navigationEndpoint = run.dig?("navigationEndpoint")
text = parse_link_endpoint(navigationEndpoint, text, video_id)
if navigation_endpoint = run.dig?("navigationEndpoint")
text = parse_link_endpoint(navigation_endpoint, text, video_id)
end

text = "<b>#{text}</b>" if run["bold"]?
Expand Down
6 changes: 3 additions & 3 deletions src/invidious/helpers/utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def recode_length_seconds(time)
end

def decode_interval(string : String) : Time::Span
rawMinutes = string.try &.to_i32?
raw_minutes = string.try &.to_i32?

if !rawMinutes
if !raw_minutes
hours = /(?<hours>\d+)h/.match(string).try &.["hours"].try &.to_i32
hours ||= 0

Expand All @@ -63,7 +63,7 @@ def decode_interval(string : String) : Time::Span

time = Time::Span.new(hours: hours, minutes: minutes)
else
time = Time::Span.new(minutes: rawMinutes)
time = Time::Span.new(minutes: raw_minutes)
end

return time
Expand Down
6 changes: 3 additions & 3 deletions src/invidious/routes/api/v1/misc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ module Invidious::Routes::API::V1::Misc
begin
resolved_url = YoutubeAPI.resolve_url(url.as(String))
endpoint = resolved_url["endpoint"]
pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
if pageType == "WEB_PAGE_TYPE_UNKNOWN"
page_type = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
if page_type == "WEB_PAGE_TYPE_UNKNOWN"
return error_json(400, "Unknown url")
end

Expand All @@ -194,7 +194,7 @@ module Invidious::Routes::API::V1::Misc
json.field "playlistId", sub_endpoint["playlistId"].as_s if sub_endpoint["playlistId"]?
json.field "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_i if sub_endpoint["startTimeSeconds"]?
json.field "params", params.try &.as_s
json.field "pageType", pageType
json.field "pageType", page_type
end
end
end
Expand Down
Loading