Merge pull request #91 from omarroth/add-preferred-captions
Add preferred captions
This commit is contained in:
commit
928ca94d8c
6 changed files with 158 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
})
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
Loading…
Reference in a new issue