[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]
scale=bilinear
cscale=ewa_lanczossharp
video-sync=audio
interpolation=no
video-sync=audio
[highquality]
scale=ewa_lanczossharp
@ -156,3 +156,6 @@ cscale=ewa_lanczossharp
video-sync=display-resample
interpolation=yes
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
local lqprofile = "lq"
local hqprofile = "hq"
local utils = require 'mp.utils'
if mp.get_property_bool("option-info/vo/set-from-commandline") == true then
return
--
local lqprofile = "lowquality"
local hqprofile = "highquality"
local function powerstate()
local f = assert(io.open("/sys/class/power_supply/AC/online"))
local t = f:read("*n")
f:close()
return t
end
t = {}
t.args = {"/bin/cat", "/sys/class/power_supply/AC/online"}
res = utils.subprocess(t)
if res.stdout == "0\n" then
mp.msg.info("On Battery, setting low-quality options.")
local function adjust()
local state = powerstate()
-- this actually overrides automatically applied profiles
-- 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("speed", 2)
else
mp.msg.info("On AC, setting high-quality options.")
else
mp.msg.info("Not running on battery, setting high-quality options.")
end
end
mp.add_hook("on_load", 1, adjust)