-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpv-osc.py
100 lines (77 loc) · 2.34 KB
/
mpv-osc.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import mpv
from pythonosc.dispatcher import Dispatcher
from pythonosc import osc_server
import subprocess
ip="192.168.178.255"
port=53035
mpv = mpv.MPV(ytdl=True, keep_open=True, input_default_bindings=True, loop=True, osd_level=0)
#blackout console:
mpv.play("black.png")
def command_handler(unused_addr, *args):
if args[0] == "restart":
mpv.play("black.png")
print("mpv is runing again :)")
if args[0] == "brightness down":
mpv.keypress(3)
print(args[0])
if args[0] == "brightness up":
mpv.keypress(4)
print(args[0])
# if args[0] == "zoom in":
# mpv.keypress('e')
# print(args[0])
# if args[0] == "zoom out":
# mpv.keypress('w')
# print(args[0])
if args[0] == "speed up":
mpv.keypress(']')
print(args[0])
if args[0] == "speed down":
mpv.keypress('[')
print(args[0])
if args[0] == "osd":
mpv.toggle_osd()
print(args[0])
if args[0] == "stop hold":
mpv.keypress("Q")
print(args[0])
if args[0] == "info":
mpv.keypress("i")
print(args[0])
if args[0] == "quit" or args[0] == "console":
print("back to console! :)")
subprocess.call(["pkill", "python"])
if args[0] == "force reboot":
mpv.stop()
print("Rebooting, Bye :)")
subprocess.call(["sudo", "reboot", "now"])
if args[0] == "force shutdown":
mpv.stop()
print("Shutting down, Bye :)")
subprocess.call(["sudo", "shutdown", "now"])
def volume_handler(unused_addr, args):
arg = round(args,2)
print(unused_addr, arg)
mpv.volume = arg
def play_handler(unused_addr, args):
args = str(args)
print(unused_addr, args)
mpv.play(args)
mpv.wait_for_playback()
def stop_handler(unused_addr, *args):
print(unused_addr, args)
mpv.stop()
mpv.play("black.png")
def pause_handler(unused_addr, *args):
mpv.keypress('P')
print('pause key pressed')
dispatcher = Dispatcher()
dispatcher.map("/command", command_handler)
dispatcher.map("/volume", volume_handler)
dispatcher.map("/play", play_handler)
dispatcher.map("/stop", stop_handler)
dispatcher.map("/pause", pause_handler)
server = osc_server.ThreadingOSCUDPServer(
(ip, port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()