[mpv] Fix battery detection

This commit is contained in:
Marty Oehme 2020-05-13 17:41:14 +02:00
parent cc942a55a1
commit d4257a4fce
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A
2 changed files with 24 additions and 14 deletions

View file

@ -147,8 +147,8 @@ ytdl-raw-options=playlist-reverse=
[lowquality] [lowquality]
scale=bilinear scale=bilinear
cscale=ewa_lanczossharp cscale=ewa_lanczossharp
video-sync=audio
interpolation=no interpolation=no
video-sync=audio
[highquality] [highquality]
scale=ewa_lanczossharp scale=ewa_lanczossharp
@ -156,3 +156,6 @@ cscale=ewa_lanczossharp
video-sync=display-resample video-sync=display-resample
interpolation=yes interpolation=yes
tscale=oversample tscale=oversample
# default to hq
profile=highquality

View file

@ -1,17 +1,24 @@
-- If the laptop is on battery, the profile 'lq' will be loaded; otherwise 'hq' is used -- If the laptop is on battery, the profile 'lq' will be loaded; otherwise 'hq' is used
local lqprofile = "lq" --
local hqprofile = "hq" local lqprofile = "lowquality"
local utils = require 'mp.utils' local hqprofile = "highquality"
if mp.get_property_bool("option-info/vo/set-from-commandline") == true then
return local function powerstate()
local f = assert(io.open("/sys/class/power_supply/AC/online"))
local t = f:read("*n")
f:close()
return t
end end
t = {}
t.args = {"/bin/cat", "/sys/class/power_supply/AC/online"} local function adjust()
res = utils.subprocess(t) local state = powerstate()
if res.stdout == "0\n" then -- this actually overrides automatically applied profiles
mp.msg.info("On Battery, setting low-quality options.") -- like 'protocol.http'
if state == 0 then
mp.msg.info("Running on battery, setting low-quality options.")
mp.set_property("profile", lqprofile) mp.set_property("profile", lqprofile)
mp.set_property("speed", 2)
else else
mp.msg.info("On AC, setting high-quality options.") mp.msg.info("Not running on battery, setting high-quality options.")
end end
end
mp.add_hook("on_load", 1, adjust)