From 7a0f0ca5cecb0dc5cc65effa878a456cc3cce4aa Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 27 Mar 2019 11:31:05 -0500 Subject: [PATCH] Fix thin mode --- src/invidious.cr | 19 +++++++++---------- src/invidious/comments.cr | 19 ++++++++++++++----- src/invidious/views/components/item.ecr | 10 +++++----- src/invidious/views/history.ecr | 2 +- src/invidious/views/watch.ecr | 6 +++--- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 64273a17..0daecfda 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -307,9 +307,7 @@ get "/watch" do |env| nojs ||= "0" nojs = nojs == "1" - if env.get? "preferences" - preferences = env.get("preferences").as(Preferences) - end + preferences = env.get("preferences").as(Preferences) if env.get? "user" user = env.get("user").as(User) @@ -344,7 +342,7 @@ get "/watch" do |env| if source == "youtube" begin - comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, proxies, "html", locale, region))["contentHtml"] + comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, proxies, "html", locale, preferences.thin_mode, region))["contentHtml"] rescue ex if preferences.comments[1] == "reddit" comments, reddit_thread = fetch_reddit_comments(id) @@ -363,12 +361,12 @@ get "/watch" do |env| comment_html = replace_links(comment_html) rescue ex if preferences.comments[1] == "youtube" - comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, proxies, "html", locale, region))["contentHtml"] + comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, proxies, "html", locale, preferences.thin_mode, region))["contentHtml"] end end end else - comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, proxies, "html", locale, region))["contentHtml"] + comment_html = JSON.parse(fetch_youtube_comments(id, PG_DB, nil, proxies, "html", locale, preferences.thin_mode, region))["contentHtml"] end comment_html ||= "" @@ -447,9 +445,7 @@ get "/embed/:id" do |env| locale = LOCALES[env.get("preferences").as(Preferences).locale]? id = env.params.url["id"] - if env.get? "preferences" - preferences = env.get("preferences").as(Preferences) - end + preferences = env.get("preferences").as(Preferences) if id.includes?("%20") || id.includes?("+") || env.params.query.to_s.includes?("%20") || env.params.query.to_s.includes?("+") id = env.params.url["id"].gsub("%20", "").delete("+") @@ -2682,6 +2678,9 @@ get "/api/v1/comments/:id" do |env| source = env.params.query["source"]? source ||= "youtube" + thin_mode = env.params.query["thin_mode"]? + thin_mode = thin_mode == "true" + format = env.params.query["format"]? format ||= "json" @@ -2689,7 +2688,7 @@ get "/api/v1/comments/:id" do |env| if source == "youtube" begin - comments = fetch_youtube_comments(id, PG_DB, continuation, proxies, format, locale, region) + comments = fetch_youtube_comments(id, PG_DB, continuation, proxies, format, locale, thin_mode, region) rescue ex error_message = {"error" => ex.message}.to_json env.response.status_code = 500 diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 275de470..dc5db766 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -56,7 +56,7 @@ class RedditListing }) end -def fetch_youtube_comments(id, db, continuation, proxies, format, locale, region) +def fetch_youtube_comments(id, db, continuation, proxies, format, locale, thin_mode, region) video = get_video(id, db, proxies, region: region) session_token = video.info["session_token"]? @@ -232,7 +232,7 @@ def fetch_youtube_comments(id, db, continuation, proxies, format, locale, region if format == "html" comments = JSON.parse(comments) - content_html = template_youtube_comments(comments, locale) + content_html = template_youtube_comments(comments, locale, thin_mode) comments = JSON.build do |json| json.object do @@ -278,7 +278,7 @@ def fetch_reddit_comments(id) return comments, thread end -def template_youtube_comments(comments, locale) +def template_youtube_comments(comments, locale, thin_mode) html = "" root = comments["comments"].as_a @@ -297,7 +297,11 @@ def template_youtube_comments(comments, locale) END_HTML end - author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).full_path}" + if !thin_mode + author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).full_path}" + else + author_thumbnail = "" + end html += <<-END_HTML
@@ -318,7 +322,12 @@ def template_youtube_comments(comments, locale) END_HTML if child["creatorHeart"]? - creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).full_path}" + if !thin_mode + creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).full_path}" + else + creator_thumbnail = "" + end + html += <<-END_HTML
diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 8226dc6f..e2a5195c 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -3,7 +3,7 @@ <% case item when %> <% when SearchChannel %> - <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> + <% if env.get("preferences").as(Preferences).thin_mode %> <% else %>
@@ -21,7 +21,7 @@ <% url = "/playlist?list=#{item.id}" %> <% end %> - <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> + <% if env.get("preferences").as(Preferences).thin_mode %> <% else %>
@@ -35,7 +35,7 @@

<% when MixVideo %>
- <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> + <% if env.get("preferences").as(Preferences).thin_mode %> <% else %>
@@ -51,7 +51,7 @@

<% when PlaylistVideo %>
- <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> + <% if env.get("preferences").as(Preferences).thin_mode %> <% else %>
@@ -74,7 +74,7 @@
<%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
<% end %> <% else %> - <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> + <% if env.get("preferences").as(Preferences).thin_mode %> <% else %>
diff --git a/src/invidious/views/history.ecr b/src/invidious/views/history.ecr index e3cbd7eb..a68b3274 100644 --- a/src/invidious/views/history.ecr +++ b/src/invidious/views/history.ecr @@ -19,7 +19,7 @@