mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Fetch external links favicon and add to about page
(cherry picked from commit 9c3a932217
)
This commit is contained in:
parent
0a2d910668
commit
ed64def5a6
4 changed files with 40 additions and 5 deletions
|
@ -397,6 +397,7 @@ Invidious::Routing.get "/sb/:authority/:id/:storyboard/:index", Invidious::Route
|
||||||
Invidious::Routing.get "/s_p/:id/:name", Invidious::Routes::Images, :s_p_image
|
Invidious::Routing.get "/s_p/:id/:name", Invidious::Routes::Images, :s_p_image
|
||||||
Invidious::Routing.get "/yts/img/:name", Invidious::Routes::Images, :yts_image
|
Invidious::Routing.get "/yts/img/:name", Invidious::Routes::Images, :yts_image
|
||||||
Invidious::Routing.get "/vi/:id/:name", Invidious::Routes::Images, :thumbnails
|
Invidious::Routing.get "/vi/:id/:name", Invidious::Routes::Images, :thumbnails
|
||||||
|
Invidious::Routing.get "/fetch_link_favicon", Invidious::Routes::Images, :link_favicon
|
||||||
|
|
||||||
# API routes (macro)
|
# API routes (macro)
|
||||||
define_v1_api_routes()
|
define_v1_api_routes()
|
||||||
|
|
|
@ -17,7 +17,7 @@ struct AboutChannel
|
||||||
property allowed_regions : Array(String)
|
property allowed_regions : Array(String)
|
||||||
property related_channels : Array(AboutRelatedChannel)
|
property related_channels : Array(AboutRelatedChannel)
|
||||||
property tabs : Array(String)
|
property tabs : Array(String)
|
||||||
property links : Array(Tuple(String, String))
|
property links : Array(Tuple(String, String, String))
|
||||||
end
|
end
|
||||||
|
|
||||||
struct AboutRelatedChannel
|
struct AboutRelatedChannel
|
||||||
|
@ -125,7 +125,7 @@ def get_about_info(ucid, locale)
|
||||||
total_views = 0_i64
|
total_views = 0_i64
|
||||||
joined = Time.unix(0)
|
joined = Time.unix(0)
|
||||||
tabs = [] of String
|
tabs = [] of String
|
||||||
links = [] of {String, String}
|
links = [] of {String, String, String}
|
||||||
|
|
||||||
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
|
tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?.try &.as_a?
|
||||||
if !tabs_json.nil?
|
if !tabs_json.nil?
|
||||||
|
@ -146,6 +146,7 @@ def get_about_info(ucid, locale)
|
||||||
channel_about_meta["primaryLinks"]?.try &.as_a.each do |link|
|
channel_about_meta["primaryLinks"]?.try &.as_a.each do |link|
|
||||||
link_title = link["title"]["simpleText"].as_s
|
link_title = link["title"]["simpleText"].as_s
|
||||||
link_url = URI.parse(link["navigationEndpoint"]["urlEndpoint"]["url"].to_s)
|
link_url = URI.parse(link["navigationEndpoint"]["urlEndpoint"]["url"].to_s)
|
||||||
|
link_icon_url = link["icon"]?.try &.["thumbnails"][0]["url"].to_s || ""
|
||||||
|
|
||||||
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? link_url.host
|
if {"m.youtube.com", "www.youtube.com", "youtu.be"}.includes? link_url.host
|
||||||
if link_url.path == "/redirect"
|
if link_url.path == "/redirect"
|
||||||
|
@ -157,12 +158,11 @@ def get_about_info(ucid, locale)
|
||||||
link_url = link_url.to_s
|
link_url = link_url.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
links << {link_title, link_url}
|
links << {link_title, link_url, link_icon_url}
|
||||||
end
|
end
|
||||||
|
|
||||||
country = channel_about_meta["country"]?.try &.["simpleText"].as_s || ""
|
country = channel_about_meta["country"]?.try &.["simpleText"].as_s || ""
|
||||||
|
|
||||||
|
|
||||||
# Normal Auto-generated channels
|
# Normal Auto-generated channels
|
||||||
# https://support.google.com/youtube/answer/2579942
|
# https://support.google.com/youtube/answer/2579942
|
||||||
# For auto-generated channels, channel_about_meta only has ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
|
# For auto-generated channels, channel_about_meta only has ["description"]["simpleText"] and ["primaryLinks"][0]["title"]["simpleText"]
|
||||||
|
@ -194,6 +194,6 @@ def get_about_info(ucid, locale)
|
||||||
allowed_regions: allowed_regions,
|
allowed_regions: allowed_regions,
|
||||||
related_channels: related_channels,
|
related_channels: related_channels,
|
||||||
tabs: tabs,
|
tabs: tabs,
|
||||||
links: links
|
links: links,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -188,4 +188,37 @@ module Invidious::Routes::Images
|
||||||
rescue ex
|
rescue ex
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Used in fetching the favicons of featured links on channel pages
|
||||||
|
def self.link_favicon(env)
|
||||||
|
url = env.params.query["url"]
|
||||||
|
url = URI.parse(url)
|
||||||
|
|
||||||
|
if url.host.to_s.ends_with?("gstatic.com")
|
||||||
|
# headers = HTTP::Headers{"Content-Encoding" => "gzip"}
|
||||||
|
headers = HTTP::Headers{} of String => String
|
||||||
|
|
||||||
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
||||||
|
if env.request.headers[header]?
|
||||||
|
headers[header] = env.request.headers[header]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
HTTP::Client.get(url.to_s, headers) do |favicon_response|
|
||||||
|
env.response.status_code = favicon_response.status_code
|
||||||
|
favicon_response.headers.each do |key, value|
|
||||||
|
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
|
||||||
|
env.response.headers[key] = value
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
||||||
|
proxy_file(favicon_response, env)
|
||||||
|
end
|
||||||
|
rescue ex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
<h3> <%= translate(locale, "channel_about_page_links_section_header") %> </h3>
|
<h3> <%= translate(locale, "channel_about_page_links_section_header") %> </h3>
|
||||||
<% channel.links.each do |link_tuple| %>
|
<% channel.links.each do |link_tuple| %>
|
||||||
<p class="pure-u-11-24">
|
<p class="pure-u-11-24">
|
||||||
|
<img src="/fetch_link_favicon?url=<%=link_tuple[2]%>">
|
||||||
<a href="<%=link_tuple[1]%>"><%=link_tuple[0]%></a>
|
<a href="<%=link_tuple[1]%>"><%=link_tuple[0]%></a>
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue