summaryrefslogtreecommitdiff
path: root/mac/.config/mpv/scripts/blackout.lua
blob: 419f34d23c6d2a1b568170328ad13e2c16a17897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
--[[
	blackout / by sibwaf / https://github.com/sibwaf/mpv-scripts

	Turns the screen completely black and pauses on a button press ([b] by default)
	so you can hide whatever you are watching from other people fast enough.
	Unpause or press the same button to go back.

	May not work if your VO driver doesn't support changing contrast.

	MIT license - do whatever you want, but I'm not responsible for any possible problems.
	Please keep the URL to the original repository. Thanks!
]]

--[[
	Configuration:

	# property

	Theoratically, can be any of: "brightness", "contrast", "saturation", "gamma", "hue".
	In practice, "contrast" seems to work best. Setting it to "saturation" or "hue"
	is pretty much pointless as you will get gray-scale or a colored negative video.
]]

local property = "contrast"

----------

local watch_later_options_default = mp.get_property_native("watch-later-options")
local watch_later_options_blackout = {}

for _, option in pairs(watch_later_options_default) do
	if option == property then
		-- remove
	elseif option == "sid" then
		-- remove
	else
		table.insert(watch_later_options_blackout, option)
	end
end

local saved_value = nil
local saved_sid = nil

function toggle_blackout()
	if saved_value then
		mp.set_property(property, saved_value)
		saved_value = nil

		mp.set_property("sid", saved_sid)
		saved_sid = nil

		mp.set_property_native("watch-later-options", watch_later_options_default)
	else
		mp.set_property("pause", "yes")

		saved_value = mp.get_property(property)
		mp.set_property(property, -100)

		saved_sid = mp.get_property("sid")
		mp.set_property("sid", "no")

		mp.set_property_native("watch-later-options", watch_later_options_blackout)
	end
end

function on_pause_change(name, value)
	if not value and saved_value then
		toggle_blackout()
	end
end

mp.add_key_binding("b", "blackout", toggle_blackout)
mp.observe_property("pause", "bool", on_pause_change)