mirror of
https://github.com/iv-org/invidious.git
synced 2025-05-02 06:26:27 -04:00
Improve DASH quality preference
Besides `auto`, `best` and `worst` it is now possible to select a target height. If the target height is not available the closest lower height is selected.
This commit is contained in:
parent
eea7ca9b72
commit
eed78c960d
2 changed files with 20 additions and 3 deletions
|
@ -159,9 +159,26 @@ if (!video_data.params.listen && video_data.params.quality === 'dash') {
|
|||
player.ready(() => {
|
||||
player.on("loadedmetadata", () => {
|
||||
const qualityLevels = Array.from(player.qualityLevels()).sort((a, b) => a.height - b.height);
|
||||
const targetQualityLevel = video_data.params.quality_dash == "best" ? qualityLevels.length - 1 : 0;
|
||||
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)
|
||||
qualityLevels[i].enabled = (i == targetQualityLevel);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue