Fix Style/VariableNames issues

pull/2428/head
syeopite 3 years ago
parent 20cb751ff6
commit 35d15c7c2b
No known key found for this signature in database
GPG Key ID: 6FA616E5A5294A82

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

@ -1,17 +1,17 @@
def fetch_channel_playlists(ucid, author, continuation, sort_by) def fetch_channel_playlists(ucid, author, continuation, sort_by)
if continuation if continuation
response_json = YoutubeAPI.browse(continuation) response_json = YoutubeAPI.browse(continuation)
continuationItems = response_json["onResponseReceivedActions"]? continuation_items = response_json["onResponseReceivedActions"]?
.try &.[0]["appendContinuationItemsAction"]["continuationItems"] .try &.[0]["appendContinuationItemsAction"]["continuationItems"]
return [] of SearchItem, nil if !continuationItems return [] of SearchItem, nil if !continuation_items
items = [] of SearchItem 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 } 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 .try &.["continuationEndpoint"]["continuationCommand"]["token"].as_s
else else
url = "/channel/#{ucid}/playlists?flow=list&view=1" url = "/channel/#{ucid}/playlists?flow=list&view=1"

@ -73,9 +73,9 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
contents = nil contents = nil
if response["onResponseReceivedEndpoints"]? if response["onResponseReceivedEndpoints"]?
onResponseReceivedEndpoints = response["onResponseReceivedEndpoints"] on_response_received_endpoints = response["onResponseReceivedEndpoints"]
header = nil header = nil
onResponseReceivedEndpoints.as_a.each do |item| on_response_received_endpoints.as_a.each do |item|
if item["reloadContinuationItemsCommand"]? if item["reloadContinuationItemsCommand"]?
case item["reloadContinuationItemsCommand"]["slot"] case item["reloadContinuationItemsCommand"]["slot"]
when "RELOAD_CONTINUATION_SLOT_HEADER" 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"]? contents = body["contents"]?
header = body["header"]? header = body["header"]?
if body["continuations"]? 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 end
else else
raise InfoException.new("Could not fetch comments") 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
end end
continuationItemRenderer = nil continuation_item_renderer = nil
contents.as_a.reject! do |item| contents.as_a.reject! do |item|
if item["continuationItemRenderer"]? if item["continuationItemRenderer"]?
continuationItemRenderer = item["continuationItemRenderer"] continuation_item_renderer = item["continuationItemRenderer"]
true true
end end
end end
@ -232,14 +233,14 @@ def fetch_youtube_comments(id, cursor, format, locale, thin_mode, region, sort_b
end end
end end
if continuationItemRenderer if continuation_item_renderer
if continuationItemRenderer["continuationEndpoint"]? if continuation_item_renderer["continuationEndpoint"]?
continuationEndpoint = continuationItemRenderer["continuationEndpoint"] continuation_endpoint = continuation_item_renderer["continuationEndpoint"]
elsif continuationItemRenderer["button"]? elsif continuation_item_renderer["button"]?
continuationEndpoint = continuationItemRenderer["button"]["buttonRenderer"]["command"] continuation_endpoint = continuation_item_renderer["button"]["buttonRenderer"]["command"]
end end
if continuationEndpoint if continuation_endpoint
json.field "continuation", continuationEndpoint["continuationCommand"]["token"].as_s json.field "continuation", continuation_endpoint["continuationCommand"]["token"].as_s
end end
end end
end end

@ -58,7 +58,7 @@ module Invidious::Routes::API::V1::Videos
captions.each do |caption| captions.each do |caption|
json.object do json.object do
json.field "label", caption.name 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)}" json.field "url", "/api/v1/captions/#{id}?label=#{URI.encode_www_form(caption.name)}"
end end
end end
@ -73,7 +73,7 @@ module Invidious::Routes::API::V1::Videos
env.response.content_type = "text/vtt; charset=UTF-8" env.response.content_type = "text/vtt; charset=UTF-8"
if lang if lang
caption = captions.select { |caption| caption.languageCode == lang } caption = captions.select { |caption| caption.language_code == lang }
else else
caption = captions.select { |caption| caption.name == label } caption = captions.select { |caption| caption.name == label }
end end
@ -84,7 +84,7 @@ module Invidious::Routes::API::V1::Videos
caption = caption[0] caption = caption[0]
end 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, # 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 # 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 str << <<-END_VTT
WEBVTT WEBVTT
Kind: captions Kind: captions
Language: #{tlang || caption.languageCode} Language: #{tlang || caption.language_code}
END_VTT END_VTT

@ -168,11 +168,11 @@ module Invidious::Routes::Embed
preferred_captions = captions.select { |caption| preferred_captions = captions.select { |caption|
params.preferred_captions.includes?(caption.name) || 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| preferred_captions.sort_by! { |caption|
(params.preferred_captions.index(caption.name) || (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 captions = captions - preferred_captions

@ -153,11 +153,11 @@ module Invidious::Routes::Watch
preferred_captions = captions.select { |caption| preferred_captions = captions.select { |caption|
params.preferred_captions.includes?(caption.name) || 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| preferred_captions.sort_by! { |caption|
(params.preferred_captions.index(caption.name) || (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 captions = captions - preferred_captions

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

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

@ -184,7 +184,7 @@ we're going to need to do it here in order to allow for translations.
</option> </option>
<% end %> <% end %>
<% captions.each do |caption| %> <% 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) %> <%= translate(locale, "Subtitles - `x` (.vtt)", caption.name) %>
</option> </option>
<% end %> <% end %>

Loading…
Cancel
Save