diff --git a/assets/js/player.js b/assets/js/player.js index a6b35d35..fcba43d8 100644 --- a/assets/js/player.js +++ b/assets/js/player.js @@ -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); +} diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 7a871dba..efd4d255 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -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 diff --git a/src/invidious/routes/user_preferences.cr b/src/invidious/routes/user_preferences.cr index 3e4ec330..3ca8ed1b 100644 --- a/src/invidious/routes/user_preferences.cr +++ b/src/invidious/routes/user_preferences.cr @@ -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, diff --git a/src/invidious/users.cr b/src/invidious/users.cr index 46bf8865..6a3ca5c1 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -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 diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 084cda49..4a831110 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -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, diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr index aebdab9e..6f674e86 100644 --- a/src/invidious/views/preferences.ecr +++ b/src/invidious/views/preferences.ecr @@ -57,6 +57,17 @@ + <% if !CONFIG.disabled?("dash") %> +