mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-23 00:29:53 +05:30
Ameba: Fix Naming/VariableNames
Fix Naming/VariableNames in comment renderer Fix Naming/VariableNames in helpers/utils Fix Naming/VariableNames in api/v1/misc.cr
This commit is contained in:
parent
bad92093bf
commit
8a90add310
@ -5,35 +5,35 @@ def text_to_parsed_content(text : String) : JSON::Any
|
|||||||
# In first case line is just a simple node before
|
# In first case line is just a simple node before
|
||||||
# check patterns inside line
|
# check patterns inside line
|
||||||
# { 'text': line }
|
# { 'text': line }
|
||||||
currentNodes = [] of JSON::Any
|
current_nodes = [] of JSON::Any
|
||||||
initialNode = {"text" => line}
|
initial_node = {"text" => line}
|
||||||
currentNodes << (JSON.parse(initialNode.to_json))
|
current_nodes << (JSON.parse(initial_node.to_json))
|
||||||
|
|
||||||
# For each match with url pattern, get last node and preserve
|
# For each match with url pattern, get last node and preserve
|
||||||
# last node before create new node with url information
|
# last node before create new node with url information
|
||||||
# { 'text': match, 'navigationEndpoint': { 'urlEndpoint' : 'url': match } }
|
# { '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
|
# Retrieve last node and update node without match
|
||||||
lastNode = currentNodes[currentNodes.size - 1].as_h
|
last_node = current_nodes[current_nodes.size - 1].as_h
|
||||||
splittedLastNode = lastNode["text"].as_s.split(urlMatch[0])
|
splitted_last_node = last_node["text"].as_s.split(url_match[0])
|
||||||
lastNode["text"] = JSON.parse(splittedLastNode[0].to_json)
|
last_node["text"] = JSON.parse(splitted_last_node[0].to_json)
|
||||||
currentNodes[currentNodes.size - 1] = JSON.parse(lastNode.to_json)
|
current_nodes[current_nodes.size - 1] = JSON.parse(last_node.to_json)
|
||||||
# Create new node with match and navigation infos
|
# Create new node with match and navigation infos
|
||||||
currentNode = {"text" => urlMatch[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => urlMatch[0]}}}
|
current_node = {"text" => url_match[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => url_match[0]}}}
|
||||||
currentNodes << (JSON.parse(currentNode.to_json))
|
current_nodes << (JSON.parse(current_node.to_json))
|
||||||
# If text remain after match create new simple node with text after match
|
# If text remain after match create new simple node with text after match
|
||||||
afterNode = {"text" => splittedLastNode.size > 1 ? splittedLastNode[1] : ""}
|
after_node = {"text" => splitted_last_node.size > 1 ? splitted_last_node[1] : ""}
|
||||||
currentNodes << (JSON.parse(afterNode.to_json))
|
current_nodes << (JSON.parse(after_node.to_json))
|
||||||
end
|
end
|
||||||
|
|
||||||
# After processing of matches inside line
|
# After processing of matches inside line
|
||||||
# Add \n at end of last node for preserve carriage return
|
# Add \n at end of last node for preserve carriage return
|
||||||
lastNode = currentNodes[currentNodes.size - 1].as_h
|
last_node = current_nodes[current_nodes.size - 1].as_h
|
||||||
lastNode["text"] = JSON.parse("#{currentNodes[currentNodes.size - 1]["text"]}\n".to_json)
|
last_node["text"] = JSON.parse("#{current_nodes[current_nodes.size - 1]["text"]}\n".to_json)
|
||||||
currentNodes[currentNodes.size - 1] = JSON.parse(lastNode.to_json)
|
current_nodes[current_nodes.size - 1] = JSON.parse(last_node.to_json)
|
||||||
|
|
||||||
# Finally add final nodes to nodes returned
|
# Finally add final nodes to nodes returned
|
||||||
currentNodes.each do |node|
|
current_nodes.each do |node|
|
||||||
nodes << (node)
|
nodes << (node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -53,8 +53,8 @@ def content_to_comment_html(content, video_id : String? = "")
|
|||||||
|
|
||||||
text = HTML.escape(run["text"].as_s)
|
text = HTML.escape(run["text"].as_s)
|
||||||
|
|
||||||
if navigationEndpoint = run.dig?("navigationEndpoint")
|
if navigation_endpoint = run.dig?("navigationEndpoint")
|
||||||
text = parse_link_endpoint(navigationEndpoint, text, video_id)
|
text = parse_link_endpoint(navigation_endpoint, text, video_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
text = "<b>#{text}</b>" if run["bold"]?
|
text = "<b>#{text}</b>" if run["bold"]?
|
||||||
|
@ -52,9 +52,9 @@ def recode_length_seconds(time)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def decode_interval(string : String) : Time::Span
|
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 = /(?<hours>\d+)h/.match(string).try &.["hours"].try &.to_i32
|
||||||
hours ||= 0
|
hours ||= 0
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ def decode_interval(string : String) : Time::Span
|
|||||||
|
|
||||||
time = Time::Span.new(hours: hours, minutes: minutes)
|
time = Time::Span.new(hours: hours, minutes: minutes)
|
||||||
else
|
else
|
||||||
time = Time::Span.new(minutes: rawMinutes)
|
time = Time::Span.new(minutes: raw_minutes)
|
||||||
end
|
end
|
||||||
|
|
||||||
return time
|
return time
|
||||||
|
@ -177,8 +177,8 @@ module Invidious::Routes::API::V1::Misc
|
|||||||
begin
|
begin
|
||||||
resolved_url = YoutubeAPI.resolve_url(url.as(String))
|
resolved_url = YoutubeAPI.resolve_url(url.as(String))
|
||||||
endpoint = resolved_url["endpoint"]
|
endpoint = resolved_url["endpoint"]
|
||||||
pageType = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
|
page_type = endpoint.dig?("commandMetadata", "webCommandMetadata", "webPageType").try &.as_s || ""
|
||||||
if pageType == "WEB_PAGE_TYPE_UNKNOWN"
|
if page_type == "WEB_PAGE_TYPE_UNKNOWN"
|
||||||
return error_json(400, "Unknown url")
|
return error_json(400, "Unknown url")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ module Invidious::Routes::API::V1::Misc
|
|||||||
json.field "playlistId", sub_endpoint["playlistId"].as_s if sub_endpoint["playlistId"]?
|
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 "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_i if sub_endpoint["startTimeSeconds"]?
|
||||||
json.field "params", params.try &.as_s
|
json.field "params", params.try &.as_s
|
||||||
json.field "pageType", pageType
|
json.field "pageType", page_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user