Fix Style/RedundantSelf type of Ameba issues

This commit is contained in:
Sijawusz Pur Rahnama 2026-01-11 22:34:23 +01:00
parent db8e73760d
commit d371829477
18 changed files with 214 additions and 214 deletions

View File

@ -26,21 +26,21 @@ struct ChannelVideo
json.object do json.object do
json.field "type", "shortVideo" json.field "type", "shortVideo"
json.field "title", self.title json.field "title", title
json.field "videoId", self.id json.field "videoId", id
json.field "videoThumbnails" do json.field "videoThumbnails" do
Invidious::JSONify::APIv1.thumbnails(json, self.id) Invidious::JSONify::APIv1.thumbnails(json, id)
end end
json.field "lengthSeconds", self.length_seconds json.field "lengthSeconds", length_seconds
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", "/channel/#{self.ucid}" json.field "authorUrl", "/channel/#{ucid}"
json.field "published", self.published.to_unix json.field "published", published.to_unix
json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale)) json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale))
json.field "viewCount", self.views json.field "viewCount", views
end end
end end
@ -51,34 +51,34 @@ struct ChannelVideo
end end
def to_xml(locale, query_params, xml : XML::Builder) def to_xml(locale, query_params, xml : XML::Builder)
query_params["v"] = self.id query_params["v"] = id
xml.element("entry") do xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{self.id}" } xml.element("id") { xml.text "yt:video:#{id}" }
xml.element("yt:videoId") { xml.text self.id } xml.element("yt:videoId") { xml.text id }
xml.element("yt:channelId") { xml.text self.ucid } xml.element("yt:channelId") { xml.text ucid }
xml.element("title") { xml.text self.title } xml.element("title") { xml.text title }
xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}") xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}")
xml.element("author") do xml.element("author") do
xml.element("name") { xml.text self.author } xml.element("name") { xml.text author }
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
end end
xml.element("content", type: "xhtml") do xml.element("content", type: "xhtml") do
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg") xml.element("img", src: "#{HOST_URL}/vi/#{id}/mqdefault.jpg")
end end
end end
end end
xml.element("published") { xml.text self.published.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("published") { xml.text published.to_s("%Y-%m-%dT%H:%M:%S%:z") }
xml.element("updated") { xml.text self.updated.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("updated") { xml.text updated.to_s("%Y-%m-%dT%H:%M:%S%:z") }
xml.element("media:group") do xml.element("media:group") do
xml.element("media:title") { xml.text self.title } xml.element("media:title") { xml.text title }
xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg", xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{id}/mqdefault.jpg",
width: "320", height: "180") width: "320", height: "180")
end end
end end

View File

@ -11,7 +11,7 @@ module Invidious::Frontend::Comments
replies_html = "" replies_html = ""
if child.replies.is_a?(RedditThing) if child.replies.is_a?(RedditThing)
replies = child.replies.as(RedditThing) replies = child.replies.as(RedditThing)
replies_html = self.template_reddit(replies.data.as(RedditListing).children, locale) replies_html = template_reddit(replies.data.as(RedditListing).children, locale)
end end
if child.depth > 0 if child.depth > 0

View File

@ -70,7 +70,7 @@ module Invidious::Frontend::Pagination
params_prev = URI::Params{"page" => (current_page - 1).to_s} params_prev = URI::Params{"page" => (current_page - 1).to_s}
url_prev = HttpServer::Utils.add_params_to_url(base_url, params_prev) url_prev = HttpServer::Utils.add_params_to_url(base_url, params_prev)
self.previous_page(str, locale, url_prev.to_s) previous_page(str, locale, url_prev.to_s)
end end
str << %(</div>\n) str << %(</div>\n)
@ -80,7 +80,7 @@ module Invidious::Frontend::Pagination
params_next = URI::Params{"page" => (current_page + 1).to_s} params_next = URI::Params{"page" => (current_page + 1).to_s}
url_next = HttpServer::Utils.add_params_to_url(base_url, params_next) url_next = HttpServer::Utils.add_params_to_url(base_url, params_next)
self.next_page(str, locale, url_next.to_s) next_page(str, locale, url_next.to_s)
end end
str << %(</div>\n) str << %(</div>\n)
@ -109,7 +109,7 @@ module Invidious::Frontend::Pagination
params["continuation"] = ctoken params["continuation"] = ctoken
url_next = HttpServer::Utils.add_params_to_url(base_url, params) url_next = HttpServer::Utils.add_params_to_url(base_url, params)
self.next_page(str, locale, url_next.to_s) next_page(str, locale, url_next.to_s)
end end
str << %(</div>\n) str << %(</div>\n)

View File

@ -151,17 +151,17 @@ module I18next::Plurals
@version = version.to_u8 @version = version.to_u8
end end
self.init_rules init_rules
end end
def init_rules def init_rules
# Look into sets # Look into sets
PLURAL_SETS.each do |form, langs| PLURAL_SETS.each do |form, langs|
langs.each { |lang| self.forms[lang] = form } langs.each { |lang| forms[lang] = form }
end end
# Add plurals from the "singles" set # Add plurals from the "singles" set
self.forms.merge!(PLURAL_SINGLES) forms.merge!(PLURAL_SINGLES)
end end
def get_plural_form(locale : String) : PluralForms def get_plural_form(locale : String) : PluralForms
@ -170,7 +170,7 @@ module I18next::Plurals
locale = locale.split('-')[0] locale = locale.split('-')[0]
end end
return self.forms[locale] if self.forms[locale]? return forms[locale] if forms[locale]?
# If nothing was found, then use the most common form, i.e # If nothing was found, then use the most common form, i.e
# one singular and one plural, as in english. Not perfect, # one singular and one plural, as in english. Not perfect,

View File

@ -28,19 +28,19 @@ struct SearchVideo
property badges : VideoBadges property badges : VideoBadges
def to_xml(auto_generated, query_params, xml : XML::Builder) def to_xml(auto_generated, query_params, xml : XML::Builder)
query_params["v"] = self.id query_params["v"] = id
xml.element("entry") do xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{self.id}" } xml.element("id") { xml.text "yt:video:#{id}" }
xml.element("yt:videoId") { xml.text self.id } xml.element("yt:videoId") { xml.text id }
xml.element("yt:channelId") { xml.text self.ucid } xml.element("yt:channelId") { xml.text ucid }
xml.element("title") { xml.text self.title } xml.element("title") { xml.text title }
xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}") xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?#{query_params}")
xml.element("author") do xml.element("author") do
if auto_generated if auto_generated
xml.element("name") { xml.text self.author } xml.element("name") { xml.text author }
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
else else
xml.element("name") { xml.text author } xml.element("name") { xml.text author }
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" } xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
@ -50,24 +50,24 @@ struct SearchVideo
xml.element("content", type: "xhtml") do xml.element("content", type: "xhtml") do
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do xml.element("a", href: "#{HOST_URL}/watch?#{query_params}") do
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg") xml.element("img", src: "#{HOST_URL}/vi/#{id}/mqdefault.jpg")
end end
xml.element("p", style: "word-break:break-word;white-space:pre-wrap") { xml.text html_to_content(self.description_html) } xml.element("p", style: "word-break:break-word;white-space:pre-wrap") { xml.text html_to_content(description_html) }
end end
end end
xml.element("published") { xml.text self.published.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("published") { xml.text published.to_s("%Y-%m-%dT%H:%M:%S%:z") }
xml.element("media:group") do xml.element("media:group") do
xml.element("media:title") { xml.text self.title } xml.element("media:title") { xml.text title }
xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg", xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{id}/mqdefault.jpg",
width: "320", height: "180") width: "320", height: "180")
xml.element("media:description") { xml.text html_to_content(self.description_html) } xml.element("media:description") { xml.text html_to_content(description_html) }
end end
xml.element("media:community") do xml.element("media:community") do
xml.element("media:statistics", views: self.views) xml.element("media:statistics", views: views)
end end
end end
end end
@ -81,13 +81,13 @@ struct SearchVideo
def to_json(locale : String?, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "video" json.field "type", "video"
json.field "title", self.title json.field "title", title
json.field "videoId", self.id json.field "videoId", id
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", "/channel/#{self.ucid}" json.field "authorUrl", "/channel/#{ucid}"
json.field "authorVerified", self.author_verified json.field "authorVerified", author_verified
author_thumbnail = self.author_thumbnail author_thumbnail = self.author_thumbnail
@ -108,31 +108,31 @@ struct SearchVideo
end end
json.field "videoThumbnails" do json.field "videoThumbnails" do
Invidious::JSONify::APIv1.thumbnails(json, self.id) Invidious::JSONify::APIv1.thumbnails(json, id)
end end
json.field "description", html_to_content(self.description_html) json.field "description", html_to_content(description_html)
json.field "descriptionHtml", self.description_html json.field "descriptionHtml", description_html
json.field "viewCount", self.views json.field "viewCount", views
json.field "viewCountText", translate_count(locale, "generic_views_count", self.views, NumberFormatting::Short) json.field "viewCountText", translate_count(locale, "generic_views_count", views, NumberFormatting::Short)
json.field "published", self.published.to_unix json.field "published", published.to_unix
json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale)) json.field "publishedText", translate(locale, "`x` ago", recode_date(published, locale))
json.field "lengthSeconds", self.length_seconds json.field "lengthSeconds", length_seconds
json.field "liveNow", self.badges.live_now? json.field "liveNow", badges.live_now?
json.field "premium", self.badges.premium? json.field "premium", badges.premium?
json.field "isUpcoming", self.upcoming? json.field "isUpcoming", upcoming?
if self.premiere_timestamp if premiere_timestamp
json.field "premiereTimestamp", self.premiere_timestamp.try &.to_unix json.field "premiereTimestamp", premiere_timestamp.try &.to_unix
end end
json.field "isNew", self.badges.new? json.field "isNew", badges.new?
json.field "is4k", self.badges.four_k? json.field "is4k", badges.four_k?
json.field "is8k", self.badges.eight_k? json.field "is8k", badges.eight_k?
json.field "isVr180", self.badges.vr180? json.field "isVr180", badges.vr180?
json.field "isVr360", self.badges.vr360? json.field "isVr360", badges.vr360?
json.field "is3d", self.badges.three_d? json.field "is3d", badges.three_d?
json.field "hasCaptions", self.badges.closed_captions? json.field "hasCaptions", badges.closed_captions?
end end
end end
@ -175,20 +175,20 @@ struct SearchPlaylist
def to_json(locale : String?, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "playlist" json.field "type", "playlist"
json.field "title", self.title json.field "title", title
json.field "playlistId", self.id json.field "playlistId", id
json.field "playlistThumbnail", self.thumbnail json.field "playlistThumbnail", thumbnail
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", "/channel/#{self.ucid}" json.field "authorUrl", "/channel/#{ucid}"
json.field "authorVerified", self.author_verified json.field "authorVerified", author_verified
json.field "videoCount", self.video_count json.field "videoCount", video_count
json.field "videos" do json.field "videos" do
json.array do json.array do
self.videos.each do |video| videos.each do |video|
json.object do json.object do
json.field "title", video.title json.field "title", video.title
json.field "videoId", video.id json.field "videoId", video.id
@ -232,17 +232,17 @@ struct SearchChannel
def to_json(locale : String?, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "channel" json.field "type", "channel"
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", "/channel/#{self.ucid}" json.field "authorUrl", "/channel/#{ucid}"
json.field "authorVerified", self.author_verified json.field "authorVerified", author_verified
json.field "authorThumbnails" do json.field "authorThumbnails" do
json.array do json.array do
qualities = {32, 48, 76, 100, 176, 512} qualities = {32, 48, 76, 100, 176, 512}
qualities.each do |quality| qualities.each do |quality|
json.object do json.object do
json.field "url", self.author_thumbnail.gsub(/=s\d+/, "=s#{quality}") json.field "url", author_thumbnail.gsub(/=s\d+/, "=s#{quality}")
json.field "width", quality json.field "width", quality
json.field "height", quality json.field "height", quality
end end
@ -250,13 +250,13 @@ struct SearchChannel
end end
end end
json.field "autoGenerated", self.auto_generated json.field "autoGenerated", auto_generated
json.field "subCount", self.subscriber_count json.field "subCount", subscriber_count
json.field "videoCount", self.video_count json.field "videoCount", video_count
json.field "channelHandle", self.channel_handle json.field "channelHandle", channel_handle
json.field "description", html_to_content(self.description_html) json.field "description", html_to_content(description_html)
json.field "descriptionHtml", self.description_html json.field "descriptionHtml", description_html
end end
end end
@ -283,10 +283,10 @@ struct SearchHashtag
def to_json(locale : String?, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "hashtag" json.field "type", "hashtag"
json.field "title", self.title json.field "title", title
json.field "url", self.url json.field "url", url
json.field "videoCount", self.video_count json.field "videoCount", video_count
json.field "channelCount", self.channel_count json.field "channelCount", channel_count
end end
end end
end end
@ -352,10 +352,10 @@ class Category
def to_json(locale : String?, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "category" json.field "type", "category"
json.field "title", self.title json.field "title", title
json.field "contents" do json.field "contents" do
json.array do json.array do
self.contents.each do |item| contents.each do |item|
item.to_json(locale, json) item.to_json(locale, json)
end end
end end

View File

@ -20,7 +20,7 @@ module WebVTT
# Writes an vtt cue with the specified time stamp and contents # Writes an vtt cue with the specified time stamp and contents
def cue(start_time : Time::Span, end_time : Time::Span, text : String) def cue(start_time : Time::Span, end_time : Time::Span, text : String)
timestamp(start_time, end_time) timestamp(start_time, end_time)
@io << self.escape(text) @io << escape(text)
@io << "\n\n" @io << "\n\n"
end end

View File

@ -25,7 +25,7 @@ class Invidious::Jobs::InstanceListRefreshJob < Invidious::Jobs::BaseJob
# - Is it an instance with a good uptime? # - Is it an instance with a good uptime?
# - Is it an updated instance? # - Is it an updated instance?
private def refresh_instances private def refresh_instances
raw_instance_list = self.fetch_instances raw_instance_list = fetch_instances
filtered_instance_list = [] of Tuple(String, String) filtered_instance_list = [] of Tuple(String, String)
raw_instance_list.each do |instance_data| raw_instance_list.each do |instance_data|

View File

@ -13,10 +13,10 @@ module Invidious::JSONify::APIv1
json.field "error", video.info["reason"] if video.info["reason"]? json.field "error", video.info["reason"] if video.info["reason"]?
json.field "videoThumbnails" do json.field "videoThumbnails" do
self.thumbnails(json, video.id) thumbnails(json, video.id)
end end
json.field "storyboards" do json.field "storyboards" do
self.storyboards(json, video.id, video.storyboards) storyboards(json, video.id, video.storyboards)
end end
json.field "description", video.description json.field "description", video.description
@ -241,7 +241,7 @@ module Invidious::JSONify::APIv1
json.field "videoId", rv["id"] json.field "videoId", rv["id"]
json.field "title", rv["title"] json.field "title", rv["title"]
json.field "videoThumbnails" do json.field "videoThumbnails" do
self.thumbnails(json, rv["id"]) thumbnails(json, rv["id"])
end end
json.field "author", rv["author"] json.field "author", rv["author"]

View File

@ -13,30 +13,30 @@ struct PlaylistVideo
def to_xml(xml : XML::Builder) def to_xml(xml : XML::Builder)
xml.element("entry") do xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{self.id}" } xml.element("id") { xml.text "yt:video:#{id}" }
xml.element("yt:videoId") { xml.text self.id } xml.element("yt:videoId") { xml.text id }
xml.element("yt:channelId") { xml.text self.ucid } xml.element("yt:channelId") { xml.text ucid }
xml.element("title") { xml.text self.title } xml.element("title") { xml.text title }
xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?v=#{self.id}") xml.element("link", rel: "alternate", href: "#{HOST_URL}/watch?v=#{id}")
xml.element("author") do xml.element("author") do
xml.element("name") { xml.text self.author } xml.element("name") { xml.text author }
xml.element("uri") { xml.text "#{HOST_URL}/channel/#{self.ucid}" } xml.element("uri") { xml.text "#{HOST_URL}/channel/#{ucid}" }
end end
xml.element("content", type: "xhtml") do xml.element("content", type: "xhtml") do
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
xml.element("a", href: "#{HOST_URL}/watch?v=#{self.id}") do xml.element("a", href: "#{HOST_URL}/watch?v=#{id}") do
xml.element("img", src: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg") xml.element("img", src: "#{HOST_URL}/vi/#{id}/mqdefault.jpg")
end end
end end
end end
xml.element("published") { xml.text self.published.to_s("%Y-%m-%dT%H:%M:%S%:z") } xml.element("published") { xml.text published.to_s("%Y-%m-%dT%H:%M:%S%:z") }
xml.element("media:group") do xml.element("media:group") do
xml.element("media:title") { xml.text self.title } xml.element("media:title") { xml.text title }
xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{self.id}/mqdefault.jpg", xml.element("media:thumbnail", url: "#{HOST_URL}/vi/#{id}/mqdefault.jpg",
width: "320", height: "180") width: "320", height: "180")
end end
end end
@ -54,15 +54,15 @@ struct PlaylistVideo
json.object do json.object do
json.field "type", "video" json.field "type", "video"
json.field "title", self.title json.field "title", title
json.field "videoId", self.id json.field "videoId", id
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", "/channel/#{self.ucid}" json.field "authorUrl", "/channel/#{ucid}"
json.field "videoThumbnails" do json.field "videoThumbnails" do
Invidious::JSONify::APIv1.thumbnails(json, self.id) Invidious::JSONify::APIv1.thumbnails(json, id)
end end
if index if index
@ -72,8 +72,8 @@ struct PlaylistVideo
json.field "index", self.index json.field "index", self.index
end end
json.field "lengthSeconds", self.length_seconds json.field "lengthSeconds", length_seconds
json.field "liveNow", self.live_now json.field "liveNow", live_now
end end
end end
@ -101,14 +101,14 @@ struct Playlist
def to_json(offset, json : JSON::Builder, video_id : String? = nil) def to_json(offset, json : JSON::Builder, video_id : String? = nil)
json.object do json.object do
json.field "type", "playlist" json.field "type", "playlist"
json.field "title", self.title json.field "title", title
json.field "playlistId", self.id json.field "playlistId", id
json.field "playlistThumbnail", self.thumbnail json.field "playlistThumbnail", thumbnail
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", "/channel/#{self.ucid}" json.field "authorUrl", "/channel/#{ucid}"
json.field "subtitle", self.subtitle json.field "subtitle", subtitle
json.field "authorThumbnails" do json.field "authorThumbnails" do
json.array do json.array do
@ -116,7 +116,7 @@ struct Playlist
qualities.each do |quality| qualities.each do |quality|
json.object do json.object do
json.field "url", self.author_thumbnail.not_nil!.gsub(/=\d+/, "=s#{quality}") json.field "url", author_thumbnail.not_nil!.gsub(/=\d+/, "=s#{quality}")
json.field "width", quality json.field "width", quality
json.field "height", quality json.field "height", quality
end end
@ -124,13 +124,13 @@ struct Playlist
end end
end end
json.field "description", self.description json.field "description", description
json.field "descriptionHtml", self.description_html json.field "descriptionHtml", description_html
json.field "videoCount", self.video_count json.field "videoCount", video_count
json.field "viewCount", self.views json.field "viewCount", views
json.field "updated", self.updated.to_unix json.field "updated", updated.to_unix
json.field "isListed", self.privacy.public? json.field "isListed", privacy.public?
json.field "videos" do json.field "videos" do
json.array do json.array do
@ -187,26 +187,26 @@ struct InvidiousPlaylist
def to_json(offset, json : JSON::Builder, video_id : String? = nil) def to_json(offset, json : JSON::Builder, video_id : String? = nil)
json.object do json.object do
json.field "type", "invidiousPlaylist" json.field "type", "invidiousPlaylist"
json.field "title", self.title json.field "title", title
json.field "playlistId", self.id json.field "playlistId", id
json.field "author", self.author json.field "author", author
json.field "authorId", self.ucid json.field "authorId", ucid
json.field "authorUrl", nil json.field "authorUrl", nil
json.field "authorThumbnails", [] of String json.field "authorThumbnails", [] of String
json.field "description", html_to_content(self.description_html) json.field "description", html_to_content(description_html)
json.field "descriptionHtml", self.description_html json.field "descriptionHtml", description_html
json.field "videoCount", self.video_count json.field "videoCount", video_count
json.field "viewCount", self.views json.field "viewCount", views
json.field "updated", self.updated.to_unix json.field "updated", updated.to_unix
json.field "isListed", self.privacy.public? json.field "isListed", privacy.public?
json.field "videos" do json.field "videos" do
json.array do json.array do
if (!offset || offset == 0) && !video_id.nil? if (!offset || offset == 0) && !video_id.nil?
index = Invidious::Database::PlaylistVideos.select_index(self.id, video_id) index = Invidious::Database::PlaylistVideos.select_index(id, video_id)
offset = self.index.index(index) || 0 offset = self.index.index(index) || 0
end end
@ -227,7 +227,7 @@ struct InvidiousPlaylist
def thumbnail def thumbnail
# TODO: Get playlist thumbnail from playlist data rather than first video # TODO: Get playlist thumbnail from playlist data rather than first video
@thumbnail_id ||= Invidious::Database::PlaylistVideos.select_one_id(self.id, self.index) || "-----------" @thumbnail_id ||= Invidious::Database::PlaylistVideos.select_one_id(id, index) || "-----------"
"/vi/#{@thumbnail_id}/mqdefault.jpg" "/vi/#{@thumbnail_id}/mqdefault.jpg"
end end
@ -244,7 +244,7 @@ struct InvidiousPlaylist
end end
def description_html def description_html
HTML.escape(self.description) HTML.escape(description)
end end
end end

View File

@ -137,7 +137,7 @@ module Invidious::Routes::API::V1::Channels
env.params.query.delete("sort_by") if env.params.query.has_key?("sort_by") env.params.query.delete("sort_by") if env.params.query.has_key?("sort_by")
env.params.query.delete("continuation") if env.params.query.has_key?("continuation") env.params.query.delete("continuation") if env.params.query.has_key?("continuation")
return self.videos(env) return videos(env)
end end
def self.videos(env) def self.videos(env)

View File

@ -8,11 +8,11 @@ module Invidious::Routes::Channels
end end
def self.home(env) def self.home(env)
self.videos(env) videos(env)
end end
def self.videos(env) def self.videos(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -64,7 +64,7 @@ module Invidious::Routes::Channels
end end
def self.shorts(env) def self.shorts(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -99,7 +99,7 @@ module Invidious::Routes::Channels
end end
def self.streams(env) def self.streams(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -134,7 +134,7 @@ module Invidious::Routes::Channels
end end
def self.playlists(env) def self.playlists(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -158,7 +158,7 @@ module Invidious::Routes::Channels
end end
def self.podcasts(env) def self.podcasts(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -178,7 +178,7 @@ module Invidious::Routes::Channels
end end
def self.releases(env) def self.releases(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -198,7 +198,7 @@ module Invidious::Routes::Channels
end end
def self.courses(env) def self.courses(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -220,7 +220,7 @@ module Invidious::Routes::Channels
def self.community(env) def self.community(env)
return env.redirect env.request.path.sub("posts", "community") if env.request.path.split("/").last == "posts" return env.redirect env.request.path.sub("posts", "community") if env.request.path.split("/").last == "posts"
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
if !data.is_a?(Tuple) if !data.is_a?(Tuple)
return data return data
end end
@ -298,7 +298,7 @@ module Invidious::Routes::Channels
end end
def self.channels(env) def self.channels(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
return data if !data.is_a?(Tuple) return data if !data.is_a?(Tuple)
locale, user, subscriptions, continuation, ucid, channel = data locale, user, subscriptions, continuation, ucid, channel = data
@ -318,7 +318,7 @@ module Invidious::Routes::Channels
end end
def self.about(env) def self.about(env)
data = self.fetch_basic_information(env) data = fetch_basic_information(env)
if !data.is_a?(Tuple) if !data.is_a?(Tuple)
return data return data
end end

View File

@ -9,7 +9,7 @@ module Invidious::Routes::Companion
begin begin
COMPANION_POOL.client do |wrapper| COMPANION_POOL.client do |wrapper|
wrapper.client.get(url, env.request.headers) do |resp| wrapper.client.get(url, env.request.headers) do |resp|
return self.proxy_companion(env, resp) return proxy_companion(env, resp)
end end
end end
rescue ex rescue ex
@ -26,7 +26,7 @@ module Invidious::Routes::Companion
begin begin
COMPANION_POOL.client do |wrapper| COMPANION_POOL.client do |wrapper|
wrapper.client.post(url, env.request.headers, env.request.body) do |resp| wrapper.client.post(url, env.request.headers, env.request.body) do |resp|
return self.proxy_companion(env, resp) return proxy_companion(env, resp)
end end
end end
rescue ex rescue ex
@ -42,7 +42,7 @@ module Invidious::Routes::Companion
begin begin
COMPANION_POOL.client do |wrapper| COMPANION_POOL.client do |wrapper|
wrapper.client.options(url, env.request.headers) do |resp| wrapper.client.options(url, env.request.headers) do |resp|
return self.proxy_companion(env, resp) return proxy_companion(env, resp)
end end
end end
rescue ex rescue ex

View File

@ -13,7 +13,7 @@ module Invidious::Routes::Images
begin begin
GGPHT_POOL.client &.get(url, headers) do |resp| GGPHT_POOL.client &.get(url, headers) do |resp|
return self.proxy_image(env, resp) return proxy_image(env, resp)
end end
rescue ex rescue ex
end end
@ -44,7 +44,7 @@ module Invidious::Routes::Images
begin begin
get_ytimg_pool(authority).client &.get(url, headers) do |resp| get_ytimg_pool(authority).client &.get(url, headers) do |resp|
env.response.headers["Connection"] = "close" env.response.headers["Connection"] = "close"
return self.proxy_image(env, resp) return proxy_image(env, resp)
end end
rescue ex rescue ex
end end
@ -66,7 +66,7 @@ module Invidious::Routes::Images
begin begin
get_ytimg_pool("i9").client &.get(url, headers) do |resp| get_ytimg_pool("i9").client &.get(url, headers) do |resp|
return self.proxy_image(env, resp) return proxy_image(env, resp)
end end
rescue ex rescue ex
end end
@ -128,7 +128,7 @@ module Invidious::Routes::Images
begin begin
get_ytimg_pool("i").client &.get(url, headers) do |resp| get_ytimg_pool("i").client &.get(url, headers) do |resp|
return self.proxy_image(env, resp) return proxy_image(env, resp)
end end
rescue ex rescue ex
end end

View File

@ -42,11 +42,11 @@ module Invidious::Routing
end end
{% end %} {% end %}
self.register_image_routes register_image_routes
self.register_api_v1_routes register_api_v1_routes
self.register_api_manifest_routes register_api_manifest_routes
self.register_video_playback_routes register_video_playback_routes
self.register_companion_routes register_companion_routes
end end
# ------------------- # -------------------

View File

@ -30,7 +30,7 @@ module Invidious::Search
# Same as `empty_raw_query?`, but named for external use # Same as `empty_raw_query?`, but named for external use
def empty? def empty?
return self.empty_raw_query? return empty_raw_query?
end end
# Getter for the query string. # Getter for the query string.
@ -70,7 +70,7 @@ module Invidious::Search
# Stop here if raw query is empty # Stop here if raw query is empty
# NOTE: maybe raise in the future? # NOTE: maybe raise in the future?
return if self.empty_raw_query? return if empty_raw_query?
# Specific handling # Specific handling
case @type case @type
@ -120,7 +120,7 @@ module Invidious::Search
items = [] of SearchItem items = [] of SearchItem
# Don't bother going further if search query is empty # Don't bother going further if search query is empty
return items if self.empty_raw_query? return items if empty_raw_query?
case @type case @type
when .regular?, .playlist? when .regular?, .playlist?

View File

@ -73,7 +73,7 @@ struct Video
end end
def live_now def live_now
return (self.video_type == VideoType::Livestream) return (video_type == VideoType::Livestream)
end end
def post_live_dvr def post_live_dvr
@ -124,11 +124,11 @@ struct Video
def storyboards def storyboards
container = info.dig?("storyboards") || JSON::Any.new("{}") container = info.dig?("storyboards") || JSON::Any.new("{}")
return IV::Videos::Storyboard.from_yt_json(container, self.length_seconds) return IV::Videos::Storyboard.from_yt_json(container, length_seconds)
end end
def paid def paid
return (self.reason || "").includes? "requires payment" return (reason || "").includes? "requires payment"
end end
def premium def premium
@ -170,7 +170,7 @@ struct Video
end end
def vr? : Bool? def vr? : Bool?
return {"EQUIRECTANGULAR", "MESH"}.includes? self.projection_type return {"EQUIRECTANGULAR", "MESH"}.includes? projection_type
end end
def projection_type : String? def projection_type : String?

View File

@ -64,7 +64,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = (item["videoRenderer"]? || item["gridVideoRenderer"]?) if item_contents = (item["videoRenderer"]? || item["gridVideoRenderer"]?)
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -192,7 +192,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = (item["channelRenderer"]? || item["gridChannelRenderer"]?) if item_contents = (item["channelRenderer"]? || item["gridChannelRenderer"]?)
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -255,7 +255,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["hashtagTileRenderer"]? if item_contents = item["hashtagTileRenderer"]?
return self.parse(item_contents) return parse(item_contents)
end end
end end
@ -308,7 +308,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["gridPlaylistRenderer"]? if item_contents = item["gridPlaylistRenderer"]?
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -352,7 +352,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["playlistRenderer"]? if item_contents = item["playlistRenderer"]?
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -415,7 +415,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["shelfRenderer"]? if item_contents = item["shelfRenderer"]?
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -484,7 +484,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item.dig?("itemSectionRenderer", "contents", 0) if item_contents = item.dig?("itemSectionRenderer", "contents", 0)
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -513,7 +513,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item.dig?("richItemRenderer", "content") if item_contents = item.dig?("richItemRenderer", "content")
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -546,7 +546,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["reelItemRenderer"]? if item_contents = item["reelItemRenderer"]?
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -643,7 +643,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["lockupViewModel"]? if item_contents = item["lockupViewModel"]?
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -721,7 +721,7 @@ private module Parsers
def process(item : JSON::Any, author_fallback : AuthorFallback) def process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["shortsLockupViewModel"]? if item_contents = item["shortsLockupViewModel"]?
return self.parse(item_contents, author_fallback) return parse(item_contents, author_fallback)
end end
end end
@ -778,7 +778,7 @@ private module Parsers
module ContinuationItemRendererParser module ContinuationItemRendererParser
def self.process(item : JSON::Any, author_fallback : AuthorFallback) def self.process(item : JSON::Any, author_fallback : AuthorFallback)
if item_contents = item["continuationItemRenderer"]? if item_contents = item["continuationItemRenderer"]?
return self.parse(item_contents) return parse(item_contents)
end end
end end
@ -831,7 +831,7 @@ private module Extractors
module YouTubeTabs module YouTubeTabs
def self.process(initial_data : InitialData) def self.process(initial_data : InitialData)
if target = initial_data["twoColumnBrowseResultsRenderer"]? if target = initial_data["twoColumnBrowseResultsRenderer"]?
self.extract(target) extract(target)
end end
end end
@ -853,7 +853,7 @@ private module Extractors
contents.as_a.each do |item| contents.as_a.each do |item|
if item_section_content = item.dig?("itemSectionRenderer", "contents") if item_section_content = item.dig?("itemSectionRenderer", "contents")
raw_items += self.unpack_item_section(item_section_content) raw_items += unpack_item_section(item_section_content)
else else
raw_items << item raw_items << item
end end
@ -902,7 +902,7 @@ private module Extractors
module SearchResults module SearchResults
def self.process(initial_data : InitialData) def self.process(initial_data : InitialData)
if target = initial_data["twoColumnSearchResultsRenderer"]? if target = initial_data["twoColumnSearchResultsRenderer"]?
self.extract(target) extract(target)
end end
end end
@ -936,11 +936,11 @@ private module Extractors
module ContinuationContent module ContinuationContent
def self.process(initial_data : InitialData) def self.process(initial_data : InitialData)
if target = initial_data["continuationContents"]? if target = initial_data["continuationContents"]?
self.extract(target) extract(target)
elsif target = initial_data["appendContinuationItemsAction"]? elsif target = initial_data["appendContinuationItemsAction"]?
self.extract(target) extract(target)
elsif target = initial_data["reloadContinuationItemsCommand"]? elsif target = initial_data["reloadContinuationItemsCommand"]?
self.extract(target) extract(target)
end end
end end

View File

@ -268,7 +268,7 @@ module YoutubeAPI
# Convert to string, for logging purposes # Convert to string, for logging purposes
def to_s def to_s
return { return {
client_type: self.name, client_type: name,
region: @region, region: @region,
}.to_s }.to_s
end end
@ -356,11 +356,11 @@ module YoutubeAPI
def browse(continuation : String, client_config : ClientConfig? = nil) def browse(continuation : String, client_config : ClientConfig? = nil)
# JSON Request data, required by the API # JSON Request data, required by the API
data = { data = {
"context" => self.make_context(client_config), "context" => make_context(client_config),
"continuation" => continuation, "continuation" => continuation,
} }
return self._post_json("/youtubei/v1/browse", data, client_config) return _post_json("/youtubei/v1/browse", data, client_config)
end end
# :ditto: # :ditto:
@ -373,7 +373,7 @@ module YoutubeAPI
# JSON Request data, required by the API # JSON Request data, required by the API
data = { data = {
"browseId" => browse_id, "browseId" => browse_id,
"context" => self.make_context(client_config), "context" => make_context(client_config),
} }
# Append the additional parameters if those were provided # Append the additional parameters if those were provided
@ -382,7 +382,7 @@ module YoutubeAPI
data["params"] = params data["params"] = params
end end
return self._post_json("/youtubei/v1/browse", data, client_config) return _post_json("/youtubei/v1/browse", data, client_config)
end end
#################################################################### ####################################################################
@ -424,21 +424,21 @@ module YoutubeAPI
def next(continuation : String, *, client_config : ClientConfig? = nil) def next(continuation : String, *, client_config : ClientConfig? = nil)
# JSON Request data, required by the API # JSON Request data, required by the API
data = { data = {
"context" => self.make_context(client_config), "context" => make_context(client_config),
"continuation" => continuation, "continuation" => continuation,
} }
return self._post_json("/youtubei/v1/next", data, client_config) return _post_json("/youtubei/v1/next", data, client_config)
end end
# :ditto: # :ditto:
def next(data : Hash, *, client_config : ClientConfig? = nil) def next(data : Hash, *, client_config : ClientConfig? = nil)
# JSON Request data, required by the API # JSON Request data, required by the API
data2 = data.merge({ data2 = data.merge({
"context" => self.make_context(client_config), "context" => make_context(client_config),
}) })
return self._post_json("/youtubei/v1/next", data2, client_config) return _post_json("/youtubei/v1/next", data2, client_config)
end end
# Allow a NamedTuple to be passed, too. # Allow a NamedTuple to be passed, too.
@ -461,7 +461,7 @@ module YoutubeAPI
} }
if CONFIG.invidious_companion.present? if CONFIG.invidious_companion.present?
return self._post_invidious_companion("/youtubei/v1/player", data) return _post_invidious_companion("/youtubei/v1/player", data)
else else
return nil return nil
end end
@ -497,11 +497,11 @@ module YoutubeAPI
# #
def resolve_url(url : String, client_config : ClientConfig? = nil) def resolve_url(url : String, client_config : ClientConfig? = nil)
data = { data = {
"context" => self.make_context(nil), "context" => make_context(nil),
"url" => url, "url" => url,
} }
return self._post_json("/youtubei/v1/navigation/resolve_url", data, client_config) return _post_json("/youtubei/v1/navigation/resolve_url", data, client_config)
end end
#################################################################### ####################################################################
@ -526,11 +526,11 @@ module YoutubeAPI
# JSON Request data, required by the API # JSON Request data, required by the API
data = { data = {
"query" => search_query, "query" => search_query,
"context" => self.make_context(client_config), "context" => make_context(client_config),
"params" => params, "params" => params,
} }
return self._post_json("/youtubei/v1/search", data, client_config) return _post_json("/youtubei/v1/search", data, client_config)
end end
#################################################################### ####################################################################
@ -550,11 +550,11 @@ module YoutubeAPI
client_config : ClientConfig? = nil, client_config : ClientConfig? = nil,
) : Hash(String, JSON::Any) ) : Hash(String, JSON::Any)
data = { data = {
"context" => self.make_context(client_config), "context" => make_context(client_config),
"params" => params, "params" => params,
} }
return self._post_json("/youtubei/v1/get_transcript", data, client_config) return _post_json("/youtubei/v1/get_transcript", data, client_config)
end end
#################################################################### ####################################################################
@ -602,7 +602,7 @@ module YoutubeAPI
status code #{response.status_code}. See <a href=\"https://docs.invidious.io/youtube-errors-explained/\"> \ status code #{response.status_code}. See <a href=\"https://docs.invidious.io/youtube-errors-explained/\"> \
https://docs.invidious.io/youtube-errors-explained/</a> for troubleshooting.") https://docs.invidious.io/youtube-errors-explained/</a> for troubleshooting.")
end end
self._decompress(response.body_io, response.headers["Content-Encoding"]?) _decompress(response.body_io, response.headers["Content-Encoding"]?)
end end
end end