From 23aaf7f1b745b830e42b133a7d3f380eac2c30f9 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 25 Aug 2018 18:33:15 -0500 Subject: [PATCH] Add comments fallback --- src/invidious.cr | 6 +- src/invidious/users.cr | 26 +++- src/invidious/views/preferences.ecr | 17 +- src/invidious/views/watch.ecr | 232 +++++++++++++++------------- 4 files changed, 167 insertions(+), 114 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 3c16650e..68514a44 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -761,8 +761,10 @@ post "/preferences" do |env| volume = env.params.body["volume"]?.try &.as(String).to_i? volume ||= 100 - comments = env.params.body["comments"]? - comments ||= "youtube" + puts env.params.body + comments_0 = env.params.body["comments_0"]?.try &.as(String) || "youtube" + comments_1 = env.params.body["comments_1"]?.try &.as(String) || "" + comments = [comments_0, comments_1] captions_0 = env.params.body["captions_0"]?.try &.as(String) || "" captions_1 = env.params.body["captions_1"]?.try &.as(String) || "" diff --git a/src/invidious/users.cr b/src/invidious/users.cr index bdaaccb5..f8974693 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -32,7 +32,7 @@ DEFAULT_USER_PREFERENCES = Preferences.from_json({ "speed" => 1.0, "quality" => "hd720", "volume" => 100, - "comments" => "youtube", + "comments" => ["youtube", ""], "captions" => ["", "", ""], "dark_mode" => false, "thin_mode " => false, @@ -43,6 +43,25 @@ DEFAULT_USER_PREFERENCES = Preferences.from_json({ }.to_json) class Preferences + module StringToArray + def self.to_json(value : Array(String), json : JSON::Builder) + return value.to_json + end + + def self.from_json(value : JSON::PullParser) : Array(String) + begin + result = [] of String + value.read_array do + result << value.read_string + end + rescue ex + result = [value.read_string, ""] + end + + result + end + end + JSON.mapping({ video_loop: Bool, autoplay: Bool, @@ -50,8 +69,9 @@ class Preferences quality: String, volume: Int32, comments: { - type: String, - default: "youtube", + type: Array(String), + default: ["youtube", ""], + converter: StringToArray, }, captions: { type: Array(String), diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr index ce4ee64b..ffd3e69f 100644 --- a/src/invidious/views/preferences.ecr +++ b/src/invidious/views/preferences.ecr @@ -48,10 +48,19 @@ function update_value(element) {
- - + <% {"", "youtube", "reddit"}.each do |option| %> + + <% end %> + +
+ +
+ +
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 1f854d2a..8294a617 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -30,6 +30,108 @@ <%= rendered "components/player" %> +
+

+ <%= HTML.escape(video.title) %> + <% if listen %> + + + + <% else %> + + + + <% end %> +

+<% if !reason.empty? %> +

<%= reason %>

+<% end %> +
+ +
+
+
+

Watch video on YouTube

+

<%= number_with_separator(video.views) %>

+

<%= number_with_separator(video.likes) %>

+

<%= number_with_separator(video.dislikes) %>

+

Genre: <%= video.genre %>

+

Family Friendly? <%= video.is_family_friendly %>

+

Wilson Score: <%= video.wilson_score.round(4) %>

+

Rating: <%= rating.round(4) %> / 5

+

Engagement: <%= engagement.round(2) %>%

+ <% if video.allowed_regions.size != REGIONS.size %> +

+ <% if video.allowed_regions.size < REGIONS.size / 2 %> + Whitelisted regions: <%= video.allowed_regions.join(", ") %> + <% else %> + Blacklisted regions: <%= (REGIONS.to_a - video.allowed_regions).join(", ") %> + <% end %> +

+ <% end %> +
+
+ +
+
+

+ +

<%= video.author %>

+ +

+ <% if user %> + <% if subscriptions.includes? video.ucid %> +

+ "> + Unsubscribe from <%= video.author %> + +

+ <% else %> +

+ "> + Subscribe to <%= video.author %> + +

+ <% end %> + <% else %> +

+ "> + Login to subscribe to <%= video.author %> + +

+ <% end %> +

+ Shared <%= video.published.to_s("%B %-d, %Y") %> +

+
+ <%= video.description %> +
+
+
+

+
+
+
+
+ +
+
+ - -
-

- <%= HTML.escape(video.title) %> - <% if listen %> - - - +<% if preferences %> + <% if preferences.comments[0] == "youtube" %> + get_youtube_comments(); + <% elsif preferences.comments[0] == "reddit" %> + get_reddit_comments(); <% else %> - - - + <% if preferences.comments[1] == "youtube" %> + get_youtube_comments(); + <% elsif preferences.comments[1] == "reddit" %> + get_reddit_comments(); + <% else %> + comments = document.getElementById("comments"); + comments.innerHTML = ""; + <% end %> <% end %> -

-<% if !reason.empty? %> -

<%= reason %>

+<% else %> +get_youtube_comments(); <% end %> -
-
-
-
-

Watch video on YouTube

-

<%= number_with_separator(video.views) %>

-

<%= number_with_separator(video.likes) %>

-

<%= number_with_separator(video.dislikes) %>

-

Genre: <%= video.genre %>

-

Family Friendly? <%= video.is_family_friendly %>

-

Wilson Score: <%= video.wilson_score.round(4) %>

-

Rating: <%= rating.round(4) %> / 5

-

Engagement: <%= engagement.round(2) %>%

- <% if video.allowed_regions.size != REGIONS.size %> -

- <% if video.allowed_regions.size < REGIONS.size / 2 %> - Whitelisted regions: <%= video.allowed_regions.join(", ") %> - <% else %> - Blacklisted regions: <%= (REGIONS.to_a - video.allowed_regions).join(", ") %> - <% end %> -

- <% end %> -
-
- -
-
-

- -

<%= video.author %>

- -

- <% if user %> - <% if subscriptions.includes? video.ucid %> -

- "> - Unsubscribe from <%= video.author %> - -

- <% else %> -

- "> - Subscribe to <%= video.author %> - -

- <% end %> - <% else %> -

- "> - Login to subscribe to <%= video.author %> - -

- <% end %> -

- Shared <%= video.published.to_s("%B %-d, %Y") %> -

-
- <%= video.description %> -
-
-
-

-
-
-
-
- -
-
+ \ No newline at end of file