summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-08-06 16:58:53 -0500
committerGitHub <noreply@github.com>2018-08-06 16:58:53 -0500
commit928ca94d8c6a4f080293ea23381cdae9c0eadbe3 (patch)
tree64bc448c51088d0db05d417c72f7d73000b71e95
parentc8d56fb426deaa5ea25e9adccefe85f2f6c35bb2 (diff)
parentca7c376874fd7b491dd388a40943ae8d78cae6e7 (diff)
downloadinvidious-928ca94d8c6a4f080293ea23381cdae9c0eadbe3.tar.gz
invidious-928ca94d8c6a4f080293ea23381cdae9c0eadbe3.tar.bz2
invidious-928ca94d8c6a4f080293ea23381cdae9c0eadbe3.zip
Merge pull request #91 from omarroth/add-preferred-captions
Add preferred captions
-rw-r--r--src/invidious.cr13
-rw-r--r--src/invidious/users.cr10
-rw-r--r--src/invidious/videos.cr109
-rw-r--r--src/invidious/views/embed.ecr2
-rw-r--r--src/invidious/views/preferences.ecr24
-rw-r--r--src/invidious/views/watch.ecr7
6 files changed, 158 insertions, 7 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 0913a137..ce818b69 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -215,6 +215,13 @@ get "/watch" do |env|
audio_streams = video.audio_streams(adaptive_fmts)
captions = video.captions
+ if preferences
+ preferred_captions = captions.select { |caption| preferences.captions.includes? caption["name"]["simpleText"] }
+ preferred_captions.sort_by! { |caption| preferences.captions.index(caption["name"]["simpleText"]).not_nil! }
+
+ captions = captions - preferred_captions
+ end
+ preferred_captions ||= [] of JSON::Any
video.description = fill_links(video.description, "https", "www.youtube.com")
video.description = add_alt_links(video.description)
@@ -713,6 +720,11 @@ post "/preferences" do |env|
comments = env.params.body["comments"]?
comments ||= "youtube"
+ captions_0 = env.params.body["captions_0"]?.try &.as(String) || ""
+ captions_1 = env.params.body["captions_1"]?.try &.as(String) || ""
+ captions_2 = env.params.body["captions_2"]?.try &.as(String) || ""
+ captions = [captions_0, captions_1, captions_2]
+
redirect_feed = env.params.body["redirect_feed"]?.try &.as(String)
redirect_feed ||= "off"
redirect_feed = redirect_feed == "on"
@@ -750,6 +762,7 @@ post "/preferences" do |env|
"quality" => quality,
"volume" => volume,
"comments" => comments,
+ "captions" => captions,
"redirect_feed" => redirect_feed,
"dark_mode" => dark_mode,
"thin_mode" => thin_mode,
diff --git a/src/invidious/users.cr b/src/invidious/users.cr
index c27825e7..be71cd94 100644
--- a/src/invidious/users.cr
+++ b/src/invidious/users.cr
@@ -33,6 +33,7 @@ DEFAULT_USER_PREFERENCES = Preferences.from_json({
"quality" => "hd720",
"volume" => 100,
"comments" => "youtube",
+ "captions" => ["", "", ""],
"dark_mode" => false,
"thin_mode " => false,
"max_results" => 40,
@@ -41,7 +42,6 @@ DEFAULT_USER_PREFERENCES = Preferences.from_json({
"unseen_only" => false,
}.to_json)
-# TODO: Migrate preferences so fields will not be nilable
class Preferences
JSON.mapping({
video_loop: Bool,
@@ -51,18 +51,19 @@ class Preferences
volume: Int32,
comments: {
type: String,
- nilable: true,
default: "youtube",
},
+ captions: {
+ type: Array(String),
+ default: ["", "", ""],
+ },
redirect_feed: {
type: Bool,
- nilable: true,
default: false,
},
dark_mode: Bool,
thin_mode: {
type: Bool,
- nilable: true,
default: false,
},
max_results: Int32,
@@ -71,7 +72,6 @@ class Preferences
unseen_only: Bool,
notifications_only: {
type: Bool,
- nilable: true,
default: false,
},
})
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index cb66bd22..1985ac77 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -1,3 +1,112 @@
+CAPTION_LANGUAGES = [
+ "",
+ "English",
+ "English (auto-generated)",
+ "Afrikaans",
+ "Albanian",
+ "Amharic",
+ "Arabic",
+ "Armenian",
+ "Azerbaijani",
+ "Bangla",
+ "Basque",
+ "Belarusian",
+ "Bosnian",
+ "Bulgarian",
+ "Burmese",
+ "Catalan",
+ "Cebuano",
+ "Chinese (Simplified)",
+ "Chinese (Traditional)",
+ "Corsican",
+ "Croatian",
+ "Czech",
+ "Danish",
+ "Dutch",
+ "Esperanto",
+ "Estonian",
+ "Filipino",
+ "Finnish",
+ "French",
+ "Galician",
+ "Georgian",
+ "German",
+ "Greek",
+ "Gujarati",
+ "Haitian Creole",
+ "Hausa",
+ "Hawaiian",
+ "Hebrew",
+ "Hindi",
+ "Hmong",
+ "Hungarian",
+ "Icelandic",
+ "Igbo",
+ "Indonesian",
+ "Irish",
+ "Italian",
+ "Japanese",
+ "Javanese",
+ "Kannada",
+ "Kazakh",
+ "Khmer",
+ "Korean",
+ "Kurdish",
+ "Kyrgyz",
+ "Lao",
+ "Latin",
+ "Latvian",
+ "Lithuanian",
+ "Luxembourgish",
+ "Macedonian",
+ "Malagasy",
+ "Malay",
+ "Malayalam",
+ "Maltese",
+ "Maori",
+ "Marathi",
+ "Mongolian",
+ "Nepali",
+ "Norwegian",
+ "Nyanja",
+ "Pashto",
+ "Persian",
+ "Polish",
+ "Portuguese",
+ "Punjabi",
+ "Romanian",
+ "Russian",
+ "Samoan",
+ "Scottish Gaelic",
+ "Serbian",
+ "Shona",
+ "Sindhi",
+ "Sinhala",
+ "Slovak",
+ "Slovenian",
+ "Somali",
+ "Southern Sotho",
+ "Spanish",
+ "Sundanese",
+ "Swahili",
+ "Swedish",
+ "Tajik",
+ "Tamil",
+ "Telugu",
+ "Thai",
+ "Turkish",
+ "Ukrainian",
+ "Urdu",
+ "Uzbek",
+ "Vietnamese",
+ "Welsh",
+ "Western Frisian",
+ "Xhosa",
+ "Yiddish",
+ "Yoruba",
+ "Zulu",
+]
+
class Video
module HTTPParamConverter
def self.from_rs(rs)
diff --git a/src/invidious/views/embed.ecr b/src/invidious/views/embed.ecr
index 222b02f6..b7bec5d5 100644
--- a/src/invidious/views/embed.ecr
+++ b/src/invidious/views/embed.ecr
@@ -55,7 +55,7 @@ video, #my_video, .video-js, .vjs-default-skin
<% end %>
<% captions.each do |caption| %>
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
- srclang="<%= caption["languageCode"] %>" label="<%= caption["name"]["simpleText"]%> ">
+ label="<%= caption["name"]["simpleText"]%> ">
<% end %>
<% end %>
<% end %>
diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr
index 57e40967..5fe4cf52 100644
--- a/src/invidious/views/preferences.ecr
+++ b/src/invidious/views/preferences.ecr
@@ -56,6 +56,30 @@ function update_value(element) {
</select>
</div>
+ <div class="pure-control-group">
+ <label for="captions_0">Default captions: </label>
+ <select class="pure-u-1-5" name="captions_0" id="captions_0">
+ <% CAPTION_LANGUAGES.each do |option| %>
+ <option <% if user.preferences.captions[0] == option %> selected <% end %>><%= option %></option>
+ <% end %>
+ </select>
+ </div>
+
+ <div class="pure-control-group">
+ <label for="captions_fallback">Fallback languages: </label>
+ <select class="pure-u-1-5" name="captions_1" id="captions_1">
+ <% CAPTION_LANGUAGES.each do |option| %>
+ <option <% if user.preferences.captions[1] == option %> selected <% end %>><%= option %></option>
+ <% end %>
+ </select>
+
+ <select class="pure-u-1-5" name="captions_2" id="captions_2">
+ <% CAPTION_LANGUAGES.each do |option| %>
+ <option <% if user.preferences.captions[2] == option %> selected <% end %>><%= option %></option>
+ <% end %>
+ </select>
+ </div>
+
<legend>Visual preferences</legend>
<div class="pure-control-group">
<label for="dark_mode">Dark mode: </label>
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 963f1733..0aacf91b 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -60,9 +60,14 @@
<% end %>
<% end %>
+ <% preferred_captions.each_with_index do |caption, i| %>
+ <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
+ label="<%= caption["name"]["simpleText"]%>" <% if i == 0 %>default<% end %>>
+ <% end %>
+
<% captions.each do |caption| %>
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
- srclang="<%= caption["languageCode"] %>" label="<%= caption["name"]["simpleText"]%> ">
+ label="<%= caption["name"]["simpleText"]%>">
<% end %>
<% end %>
<% end %>