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) {
<%= 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 %> ++ "> + 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") %> +
+<%= rv["title"] %>
++ <%= rv["author"] %> +
+ + <% end %> + <% end %> +<%= 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 %> -- "> - 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") %> -
-<%= rv["title"] %>
-- <%= rv["author"] %> -
- - <% end %> - <% end %> -
+