-
-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Allow diffrent preset for video quality based on power source #103 #2292
Conversation
Thank you! @Nirbhay97
Typically our users might want 1080p usually and 720p or 480p on battery or to pause when the charger is unplugged "qualityWhenRunningOnBattery":{ "message": "Quality, when running on battery" },
"pauseWhileIUnplugTheCharger":{ "message": "Pause when I unplug the charger!" },
"whenBatteryIslowDecreaseQuality":{ "message": "Low battery: Gradually decrease the quality!" }, The battery listener/s can depend on battery feature/s being enabled. if (improvedTube.storage.qualityWhenRunningOnBattery || improvedTube.storage.pauseWhileIUnplugTheCharger || improvedTube.storage.whenBatteryIslowDecreaseQuality) {
async function battery() {
try {
const battery = await navigator.getBattery();
if (battery === null) {
console.log('Desktop!(?) "Battery === null"');
} else if (battery.level === null) {
console.log("No battery present");
} else if (improvedTube.storage.qualityWhenRunningOnBattery || improvedTube.storage.whenBatteryIslowDecreaseQuality) {
battery.addEventListener("levelchange", () => {
if (!battery.charging) {
if (improvedTube.storage.qualityWhenRunningOnBattery) {
playerQuality(improvedTube.storage.qualityWhenRunningOnBattery);
}
if (improvedTube.storage.whenBatteryIslowDecreaseQuality && (battery.level < 0.15 || battery.dischargingTime < 1200)) {
if (battery.level > 0.11 || battery.dischargingTime > 900) {
playerQuality("large");
} else if (battery.level > 0.08 || battery.dischargingTime > 600) {
playerQuality("medium");
} else if (battery.level > 0.04 && battery.dischargingTime > 360) {
playerQuality("small");
} else {
playerQuality("tiny");
}
}
}
});
}
if (improvedTube.storage.pauseWhileIUnplugTheCharger) {
battery.addEventListener("chargingchange", () => {
if (!battery.charging) {
ImprovedTube.elements.player.pauseVideo();
ImprovedTube.paused = true;
} else if (ImprovedTube.paused === true) {
ImprovedTube.elements.player.playVideo();
delete ImprovedTube.paused;
}
});
}
} catch (error) {
console.error("Error accessing battery information:", error.message);
}
}
battery();
} (untested)
(BTW, in our menu UI, we only used the |
That's a really well written and improved code considering different battery cases, a whole lot of learning for me! Thanks @ImprovedTube . Since the PR is still open, what is to be done from my side now? Or what things shall I focus on now for this feat. |
Hi! @Nirbhay97 if you like you can.. : ..test/finish this with my code:
(we dont need to call it on focus, like QualityWithoutFocus) ..and/or check how to do this too:
(which wont matter if it will be the same PR or another) |
Yes, I tested my code and it worked well,
Yes, it makes more sense to hide this feat when using on desktop, which is currently not handled. |
hi! @Nirbhay97
if it was set with our quality feature,
|
inconsistent Naming convention, lets stick to snake case since every other option is already that please :) someone already planned that, because: youtube/menu/skeleton-parts/player.js Line 925 in e8bd44f
but didnt finish, didnt add id and forgot to comment it :) no quality_when_low_battery ID = Codec h254 modal doesnt close on OK :
|
Sorry my additions & tuned numbers delayed the release of the feature yet. Greetings @Nirbhay97 |
issue -> quality and bandwidth #2240