From 48ad744ebfca0437b1cb6d91c155e31dffe7f2b6 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 30 Jun 2019 12:59:38 -0500 Subject: [PATCH] Add support for default channel banners --- src/invidious.cr | 34 ++++++++++++++++--------------- src/invidious/channels.cr | 6 +++++- src/invidious/views/channel.ecr | 14 +++++++------ src/invidious/views/playlists.ecr | 14 +++++++------ 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index ad9859241..5c054c4c6 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -3565,23 +3565,25 @@ get "/api/v1/channels/:ucid" do |env| json.field "authorBanners" do json.array do - qualities = { - {width: 2560, height: 424}, - {width: 2120, height: 351}, - {width: 1060, height: 175}, - } - qualities.each do |quality| - json.object do - json.field "url", channel.banner.gsub("=w1060", "=w#{quality[:width]}") - json.field "width", quality[:width] - json.field "height", quality[:height] + if channel.banner + qualities = { + {width: 2560, height: 424}, + {width: 2120, height: 351}, + {width: 1060, height: 175}, + } + qualities.each do |quality| + json.object do + json.field "url", channel.banner.not_nil!.gsub("=w1060", "=w#{quality[:width]}") + json.field "width", quality[:width] + json.field "height", quality[:height] + end end - end - json.object do - json.field "url", channel.banner.rchop("=w1060-fcrop64=1,00005a57ffffa5a8-nd-c0xffffffff-rj-k-no") - json.field "width", 512 - json.field "height", 288 + json.object do + json.field "url", channel.banner.not_nil!.rchop("=w1060-fcrop64=1,00005a57ffffa5a8-nd-c0xffffffff-rj-k-no") + json.field "width", 512 + json.field "height", 288 + end end end end @@ -3592,7 +3594,7 @@ get "/api/v1/channels/:ucid" do |env| qualities.each do |quality| json.object do - json.field "url", channel.author_thumbnail.gsub("/s100-", "/s#{quality}-") + json.field "url", channel.author_thumbnail.gsub("=s100-", "=s#{quality}-") json.field "width", quality json.field "height", quality end diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index 1fd94ca4a..598ca2947 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -114,7 +114,7 @@ struct AboutChannel auto_generated: Bool, author_url: String, author_thumbnail: String, - banner: String, + banner: String?, description_html: String, paid: Bool, total_views: Int64, @@ -654,6 +654,10 @@ def get_about_info(ucid, locale) banner = about.xpath_node(%q(//div[@id="gh-banner"]/style)).not_nil!.content banner = "https:" + banner.match(/background-image: url\((?[^)]+)\)/).not_nil!["url"] + if banner.includes? "channels/c4/default_banner" + banner = nil + end + description_html = about.xpath_node(%q(//div[contains(@class,"about-description")])).try &.to_s || "" paid = about.xpath_node(%q(//meta[@itemprop="paid"])).not_nil!["content"] == "True" diff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecr index cccd349cb..17365b683 100644 --- a/src/invidious/views/channel.ecr +++ b/src/invidious/views/channel.ecr @@ -3,13 +3,15 @@ <% end %> -
- "> -
+<% if channel.banner %> +
+ "> +
-
-
-
+
+
+
+<% end %>
diff --git a/src/invidious/views/playlists.ecr b/src/invidious/views/playlists.ecr index 28de9ec2f..0a4b6e680 100644 --- a/src/invidious/views/playlists.ecr +++ b/src/invidious/views/playlists.ecr @@ -2,13 +2,15 @@ <%= channel.author %> - Invidious <% end %> -
- "> -
+<% if channel.banner %> +
+ "> +
-
-
-
+
+
+
+<% end %>