Fix Style/VariableNames issues

This commit is contained in:
syeopite 2021-09-24 19:15:23 -07:00
parent 20cb751ff6
commit 35d15c7c2b
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
9 changed files with 42 additions and 41 deletions

View file

@ -703,13 +703,13 @@ get "/subscription_manager" do |env|
xml.element("outline", text: title, title: title) do
subscriptions.each do |channel|
if format == "newpipe"
xmlUrl = "https://www.youtube.com/feeds/videos.xml?channel_id=#{channel.id}"
xml_url = "https://www.youtube.com/feeds/videos.xml?channel_id=#{channel.id}"
else
xmlUrl = "#{HOST_URL}/feed/channel/#{channel.id}"
xml_url = "#{HOST_URL}/feed/channel/#{channel.id}"
end
xml.element("outline", text: channel.author, title: channel.author,
"type": "rss", xmlUrl: xmlUrl)
"type": "rss", xmlUrl: xml_url)
end
end
end
@ -1351,7 +1351,7 @@ error 500 do |env, ex|
error_template(500, ex)
end
static_headers do | response |
static_headers do |response|
response.headers.add("Cache-Control", "max-age=2629800")
end

View file

@ -1,17 +1,17 @@
def fetch_channel_playlists(ucid, author, continuation, sort_by)
if continuation
response_json = YoutubeAPI.browse(continuation)
continuationItems = response_json["onResponseReceivedActions"]?
continuation_items = response_json["onResponseReceivedActions"]?
.try &.[0]["appendContinuationItemsAction"]["continuationItems"]
return [] of SearchItem, nil if !continuationItems
return [] of SearchItem, nil if !continuation_items
items = [] of SearchItem
continuationItems.as_a.select(&.as_h.has_key?("gridPlaylistRenderer")).each { |item|
continuation_items.as_a.select(&.as_h.has_key?("gridPlaylistRenderer")).each { |item|
extract_item(item, author, ucid).try { |t| items << t }
}
continuation = continuationItems.as_a.last["continuationItemRenderer"]?
continuation = continuation_items.as_a.last["continuationItemRenderer"]?
.try &.["continuationEndpoint"]["continuationCommand"]["token"].as_s
else
url = "/channel/#{ucid}/playlists?flow=list&view=1"

View file

@ -73,9 +73,9 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
contents = nil
if response["onResponseReceivedEndpoints"]?
onResponseReceivedEndpoints = response["onResponseReceivedEndpoints"]
on_response_received_endpoints = response["onResponseReceivedEndpoints"]
header = nil
onResponseReceivedEndpoints.as_a.each do |item|
on_response_received_endpoints.as_a.each do |item|
if item["reloadContinuationItemsCommand"]?
case item["reloadContinuationItemsCommand"]["slot"]
when "RELOAD_CONTINUATION_SLOT_HEADER"
@ -97,7 +97,8 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
contents = body["contents"]?
header = body["header"]?
if body["continuations"]?
moreRepliesContinuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
# Removable? Doesn't seem like this is used.
more_replies_continuation = body["continuations"][0]["nextContinuationData"]["continuation"].as_s
end
else
raise InfoException.new("Could not fetch comments")
@ -111,10 +112,10 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
end
end
continuationItemRenderer = nil
continuation_item_renderer = nil
contents.as_a.reject! do |item|
if item["continuationItemRenderer"]?
continuationItemRenderer = item["continuationItemRenderer"]
continuation_item_renderer = item["continuationItemRenderer"]
true
end
end
@ -232,14 +233,14 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
end
end
if continuationItemRenderer
if continuationItemRenderer["continuationEndpoint"]?
continuationEndpoint = continuationItemRenderer["continuationEndpoint"]
elsif continuationItemRenderer["button"]?
continuationEndpoint = continuationItemRenderer["button"]["buttonRenderer"]["command"]
if continuation_item_renderer
if continuation_item_renderer["continuationEndpoint"]?
continuation_endpoint = continuation_item_renderer["continuationEndpoint"]
elsif continuation_item_renderer["button"]?
continuation_endpoint = continuation_item_renderer["button"]["buttonRenderer"]["command"]
end
if continuationEndpoint
json.field "continuation", continuationEndpoint["continuationCommand"]["token"].as_s
if continuation_endpoint
json.field "continuation", continuation_endpoint["continuationCommand"]["token"].as_s
end
end
end

View file

@ -58,7 +58,7 @@ module Invidious::Routes::API::V1::Videos
captions.each do |caption|
json.object do
json.field "label", caption.name
json.field "languageCode", caption.languageCode
json.field "languageCode", caption.language_code
json.field "url", "/api/v1/captions/#{id}?label=#{URI.encode_www_form(caption.name)}"
end
end
@ -73,7 +73,7 @@ module Invidious::Routes::API::V1::Videos
env.response.content_type = "text/vtt; charset=UTF-8"
if lang
caption = captions.select { |caption| caption.languageCode == lang }
caption = captions.select { |caption| caption.language_code == lang }
else
caption = captions.select { |caption| caption.name == label }
end
@ -84,7 +84,7 @@ module Invidious::Routes::API::V1::Videos
caption = caption[0]
end
url = URI.parse("#{caption.baseUrl}&tlang=#{tlang}").request_target
url = URI.parse("#{caption.base_url}&tlang=#{tlang}").request_target
# Auto-generated captions often have cues that aren't aligned properly with the video,
# as well as some other markup that makes it cumbersome, so we try to fix that here
@ -96,7 +96,7 @@ module Invidious::Routes::API::V1::Videos
str << <<-END_VTT
WEBVTT
Kind: captions
Language: #{tlang || caption.languageCode}
Language: #{tlang || caption.language_code}
END_VTT

View file

@ -168,11 +168,11 @@ module Invidious::Routes::Embed
preferred_captions = captions.select { |caption|
params.preferred_captions.includes?(caption.name) ||
params.preferred_captions.includes?(caption.languageCode.split("-")[0])
params.preferred_captions.includes?(caption.language_code.split("-")[0])
}
preferred_captions.sort_by! { |caption|
(params.preferred_captions.index(caption.name) ||
params.preferred_captions.index(caption.languageCode.split("-")[0])).not_nil!
params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil!
}
captions = captions - preferred_captions

View file

@ -153,11 +153,11 @@ module Invidious::Routes::Watch
preferred_captions = captions.select { |caption|
params.preferred_captions.includes?(caption.name) ||
params.preferred_captions.includes?(caption.languageCode.split("-")[0])
params.preferred_captions.includes?(caption.language_code.split("-")[0])
}
preferred_captions.sort_by! { |caption|
(params.preferred_captions.index(caption.name) ||
params.preferred_captions.index(caption.languageCode.split("-")[0])).not_nil!
params.preferred_captions.index(caption.language_code.split("-")[0])).not_nil!
}
captions = captions - preferred_captions

View file

@ -14,13 +14,13 @@ def channel_search(query, page, channel)
continuation = produce_channel_search_continuation(ucid, query, page)
response_json = YoutubeAPI.browse(continuation)
continuationItems = response_json["onResponseReceivedActions"]?
continuation_items = response_json["onResponseReceivedActions"]?
.try &.[0]["appendContinuationItemsAction"]["continuationItems"]
return 0, [] of SearchItem if !continuationItems
return 0, [] of SearchItem if !continuation_items
items = [] of SearchItem
continuationItems.as_a.select(&.as_h.has_key?("itemSectionRenderer")).each { |item|
continuation_items.as_a.select(&.as_h.has_key?("itemSectionRenderer")).each { |item|
extract_item(item["itemSectionRenderer"]["contents"].as_a[0])
.try { |t| items << t }
}

View file

@ -426,7 +426,7 @@ struct Video
self.captions.each do |caption|
json.object do
json.field "label", caption.name
json.field "languageCode", caption.languageCode
json.field "language_code", caption.language_code
json.field "url", "/api/v1/captions/#{id}?label=#{URI.encode_www_form(caption.name)}"
end
end
@ -703,10 +703,10 @@ struct Video
return @captions.as(Array(Caption)) if @captions
captions = info["captions"]?.try &.["playerCaptionsTracklistRenderer"]?.try &.["captionTracks"]?.try &.as_a.map do |caption|
name = caption["name"]["simpleText"]? || caption["name"]["runs"][0]["text"]
languageCode = caption["languageCode"].to_s
baseUrl = caption["baseUrl"].to_s
language_code = caption["languageCode"].to_s
base_url = caption["baseUrl"].to_s
caption = Caption.new(name.to_s, languageCode, baseUrl)
caption = Caption.new(name.to_s, language_code, base_url)
caption.name = caption.name.split(" - ")[0]
caption
end
@ -785,16 +785,16 @@ end
struct Caption
property name
property languageCode
property baseUrl
property language_code
property base_url
getter name : String
getter languageCode : String
getter baseUrl : String
getter language_code : String
getter base_url : String
setter name
def initialize(@name, @languageCode, @baseUrl)
def initialize(@name, @language_code, @base_url)
end
end

View file

@ -184,7 +184,7 @@ we're going to need to do it here in order to allow for translations.
</option>
<% end %>
<% captions.each do |caption| %>
<option value='{"id":"<%= video.id %>","label":"<%= caption.name %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= caption.languageCode %>.vtt"}'>
<option value='{"id":"<%= video.id %>","label":"<%= caption.name %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= caption.language_code %>.vtt"}'>
<%= translate(locale, "Subtitles - `x` (.vtt)", caption.name) %>
</option>
<% end %>