From d4257a4fce9b682e3e2b99dfc05c8d47bca16c8f Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 13 May 2020 17:41:14 +0200 Subject: [PATCH] [mpv] Fix battery detection --- mpv/.config/mpv/mpv.conf | 5 ++++- mpv/.config/mpv/scripts/battery.lua | 33 +++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/mpv/.config/mpv/mpv.conf b/mpv/.config/mpv/mpv.conf index a5baffc..963da5f 100644 --- a/mpv/.config/mpv/mpv.conf +++ b/mpv/.config/mpv/mpv.conf @@ -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 diff --git a/mpv/.config/mpv/scripts/battery.lua b/mpv/.config/mpv/scripts/battery.lua index a38381e..3133cde 100644 --- a/mpv/.config/mpv/scripts/battery.lua +++ b/mpv/.config/mpv/scripts/battery.lua @@ -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)