[mpv] Fix battery detection
This commit is contained in:
parent
cc942a55a1
commit
d4257a4fce
2 changed files with 24 additions and 14 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue