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 | 340 +++++++++++++++------------- 4 files changed, 221 insertions(+), 168 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 3c16650e3..68514a44f 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 bdaaccb51..f89746938 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 ce4ee64b0..ffd3e69fc 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 1f854d2a5..8294a6170 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -30,165 +30,6 @@ <%= rendered "components/player" %> - -

<%= HTML.escape(video.title) %> @@ -290,3 +131,184 @@ get_youtube_comments();

+ + \ No newline at end of file