Merge pull request #1572 from saltycrys/add-dash-quality-preference
Add DASH quality preference
This commit is contained in:
commit
eeeecf9763
|
@ -154,6 +154,35 @@ if (video_data.params.autoplay) {
|
|||
|
||||
if (!video_data.params.listen && video_data.params.quality === 'dash') {
|
||||
player.httpSourceSelector();
|
||||
|
||||
if (video_data.params.quality_dash != "auto") {
|
||||
player.ready(() => {
|
||||
player.on("loadedmetadata", () => {
|
||||
const qualityLevels = Array.from(player.qualityLevels()).sort((a, b) => a.height - b.height);
|
||||
let targetQualityLevel;
|
||||
switch (video_data.params.quality_dash) {
|
||||
case "best":
|
||||
targetQualityLevel = qualityLevels.length - 1;
|
||||
break;
|
||||
case "worst":
|
||||
targetQualityLevel = 0;
|
||||
break;
|
||||
default:
|
||||
const targetHeight = Number.parseInt(video_data.params.quality_dash, 10);
|
||||
for (let i = 0; i < qualityLevels.length; i++) {
|
||||
if (qualityLevels[i].height <= targetHeight) {
|
||||
targetQualityLevel = i;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < qualityLevels.length; i++) {
|
||||
qualityLevels[i].enabled = (i == targetQualityLevel);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
player.vttThumbnails({
|
||||
|
@ -510,4 +539,6 @@ window.addEventListener('keydown', e => {
|
|||
}());
|
||||
|
||||
// Since videojs-share can sometimes be blocked, we defer it until last
|
||||
player.share(shareOptions);
|
||||
if (player.share) {
|
||||
player.share(shareOptions);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ struct ConfigPreferences
|
|||
property notifications_only : Bool = false
|
||||
property player_style : String = "invidious"
|
||||
property quality : String = "hd720"
|
||||
property quality_dash : String = "auto"
|
||||
property default_home : String = "Popular"
|
||||
property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"]
|
||||
property related_videos : Bool = true
|
||||
|
|
|
@ -54,6 +54,9 @@ class Invidious::Routes::UserPreferences < Invidious::Routes::BaseRoute
|
|||
quality = env.params.body["quality"]?.try &.as(String)
|
||||
quality ||= CONFIG.default_user_preferences.quality
|
||||
|
||||
quality_dash = env.params.body["quality_dash"]?.try &.as(String)
|
||||
quality_dash ||= CONFIG.default_user_preferences.quality_dash
|
||||
|
||||
volume = env.params.body["volume"]?.try &.as(String).to_i?
|
||||
volume ||= CONFIG.default_user_preferences.volume
|
||||
|
||||
|
@ -127,6 +130,7 @@ class Invidious::Routes::UserPreferences < Invidious::Routes::BaseRoute
|
|||
notifications_only: notifications_only,
|
||||
player_style: player_style,
|
||||
quality: quality,
|
||||
quality_dash: quality_dash,
|
||||
default_home: default_home,
|
||||
feed_menu: feed_menu,
|
||||
related_videos: related_videos,
|
||||
|
|
|
@ -66,6 +66,8 @@ struct Preferences
|
|||
|
||||
@[JSON::Field(converter: Preferences::ProcessString)]
|
||||
property quality : String = CONFIG.default_user_preferences.quality
|
||||
@[JSON::Field(converter: Preferences::ProcessString)]
|
||||
property quality_dash : String = CONFIG.default_user_preferences.quality_dash
|
||||
property default_home : String = CONFIG.default_user_preferences.default_home
|
||||
property feed_menu : Array(String) = CONFIG.default_user_preferences.feed_menu
|
||||
property related_videos : Bool = CONFIG.default_user_preferences.related_videos
|
||||
|
|
|
@ -235,6 +235,7 @@ struct VideoPreferences
|
|||
property preferred_captions : Array(String)
|
||||
property player_style : String
|
||||
property quality : String
|
||||
property quality_dash : String
|
||||
property raw : Bool
|
||||
property region : String?
|
||||
property related_videos : Bool
|
||||
|
@ -1043,6 +1044,7 @@ def process_video_params(query, preferences)
|
|||
player_style = query["player_style"]?
|
||||
preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }
|
||||
quality = query["quality"]?
|
||||
quality_dash = query["quality_dash"]?
|
||||
region = query["region"]?
|
||||
related_videos = query["related_videos"]?.try { |q| (q == "true" || q == "1").to_unsafe }
|
||||
speed = query["speed"]?.try &.rchop("x").to_f?
|
||||
|
@ -1061,6 +1063,7 @@ def process_video_params(query, preferences)
|
|||
player_style ||= preferences.player_style
|
||||
preferred_captions ||= preferences.captions
|
||||
quality ||= preferences.quality
|
||||
quality_dash ||= preferences.quality_dash
|
||||
related_videos ||= preferences.related_videos.to_unsafe
|
||||
speed ||= preferences.speed
|
||||
video_loop ||= preferences.video_loop.to_unsafe
|
||||
|
@ -1077,6 +1080,7 @@ def process_video_params(query, preferences)
|
|||
player_style ||= CONFIG.default_user_preferences.player_style
|
||||
preferred_captions ||= CONFIG.default_user_preferences.captions
|
||||
quality ||= CONFIG.default_user_preferences.quality
|
||||
quality_dash ||= CONFIG.default_user_preferences.quality_dash
|
||||
related_videos ||= CONFIG.default_user_preferences.related_videos.to_unsafe
|
||||
speed ||= CONFIG.default_user_preferences.speed
|
||||
video_loop ||= CONFIG.default_user_preferences.video_loop.to_unsafe
|
||||
|
@ -1129,6 +1133,7 @@ def process_video_params(query, preferences)
|
|||
player_style: player_style,
|
||||
preferred_captions: preferred_captions,
|
||||
quality: quality,
|
||||
quality_dash: quality_dash,
|
||||
raw: raw,
|
||||
region: region,
|
||||
related_videos: related_videos,
|
||||
|
|
|
@ -57,6 +57,17 @@
|
|||
</select>
|
||||
</div>
|
||||
|
||||
<% if !CONFIG.disabled?("dash") %>
|
||||
<div class="pure-control-group">
|
||||
<label for="quality_dash"><%= translate(locale, "Preferred dash video quality: ") %></label>
|
||||
<select name="quality_dash" id="quality_dash">
|
||||
<% {"auto", "best", "4320p", "2160p", "1440p", "1080p", "720p", "480p", "360p", "240p", "144p", "worst"}.each do |option| %>
|
||||
<option value="<%= option %>" <% if preferences.quality_dash == option %> selected <% end %>><%= translate(locale, option) %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="pure-control-group">
|
||||
<label for="volume"><%= translate(locale, "Player volume: ") %></label>
|
||||
<input name="volume" id="volume" data-onrange="update_volume_value" type="range" min="0" max="100" step="5" value="<%= preferences.volume %>">
|
||||
|
|
Loading…
Reference in a new issue