-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlexAdvanced.remote
195 lines (160 loc) · 4.53 KB
/
PlexAdvanced.remote
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
-- *Metadata*
meta.id = "br0sk.PlexAdvanced"
meta.name = "Plex Advanced"
meta.author = "John Eskilsson"
meta.description = "A Remote for Controlling Plex Media Center"
-- *Initialise Unified Remote Libs*
local keyboard = libs.keyboard;
local task = libs.task;
local server = libs.server;
local device = libs.device;
local log = libs.log;
local server = libs.server;
-- *Common functions*
-- Make the Plex application take focus before the command is executed.
-- Makes it possible to click any of the controls even if the Plex Window is not active.
function bringToFront()
local hwnd = task.window("Plex.exe");
task.switchtowait(hwnd);
end
-- This function splits a string separated by a character and returns an array
-- This function is based on answer 8 here http://stackoverflow.com/questions/1426954/split-string-in-lua
-- The default separator is ,
function explode(inputstr, sep)
if sep == nil then
sep = ","
end
t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
-- *General control actions*
-- Start the Plex application using the app path in PlexAdvanced.properties
actions.launch_plex = function()
task.start ( server.get ( "appPath" ));
end
-- This runs the first time the remote is loaded
events.focus = function ()
if(server.get ( "screenSwitchActive" ) == "yes") then
-- Test code
log.info("Screen switcher active!");
server.update("restart_plex_server", "text", "Test text");
-- server.update("restart_plex_server", "visibility", "gone");
end
end
-- *Button control actions*
-- Start rewinding, run several times to change the rewind speed
actions.rwd = function()
bringToFront();
keyboard.stroke("r");
end
-- Toggle fullscreen and window mode
actions.fullscreen = function()
bringToFront();
keyboard.stroke("alt", "return");
end
-- Fast forward, run several times to change the fast forward speed
actions.ff = function()
bringToFront();
keyboard.stroke("f");
end
-- Decrease the Plex volume
actions.vdown = function()
bringToFront();
keyboard.stroke("oem_minus");
end
-- Increase the Plex volume
actions.vup = function()
bringToFront();
keyboard.stroke("oem_plus");
end
-- Stop playback
actions.stop = function()
bringToFront();
keyboard.stroke("x");
end
-- Toggle play/pause
actions.play_pause = function()
bringToFront();
keyboard.stroke("p");
end
-- Move the selection up
actions.up = function()
bringToFront();
keyboard.stroke("up");
end
-- Move the selection left
actions.left = function()
bringToFront();
keyboard.stroke("left");
end
-- Select or activate current selection
actions.select = function()
bringToFront();
keyboard.stroke("return");
end
-- Move the selection to the right
actions.right = function()
bringToFront();
keyboard.stroke("right");
end
-- Bring up the menu during playback
actions.toggle_movie_menu = function()
bringToFront();
keyboard.stroke("tab");
end
-- Move the selection down
actions.down = function()
bringToFront();
keyboard.stroke("down");
end
-- Go back or cancel
actions.back1 = function()
bringToFront();
keyboard.stroke("escape");
end
-- Toggle between fullscreen video and navigation when media is playing
actions.play_menu = function()
bringToFront();
keyboard.stroke("m");
end
-- Brings up the popup menu when you for instance is browsing the episodes in a TV series
actions.popup_menu = function()
bringToFront();
keyboard.stroke("c");
end
-- Reloads the sections specified in the properties file
actions.reload_plex_library = function()
local testArray = explode(server.get( "plexSections" ), ",");
for i, section in ipairs(testArray) do
local http = libs.net.http();
local sectionRequestResult = http:request({
method = "get",
url = server.get ( "plexBaseUrl" ) .. "/library/sections/".. section .."/refresh",
});
log.info (("Refreshing section ".. section));
end
end
-- This function will restart the server if it exists on the controlled PC
actions.restart_plex_server = function()
-- Not implemented yet
device.toast ("Not yet implemented!");
end
-- Decreases the global Windows volume
actions.windows_volume_down = function()
bringToFront();
keyboard.stroke("volumedown");
end
-- Mutes the global Windows sounds
actions.windows_volume_mute = function()
bringToFront();
keyboard.stroke("volumemute");
end
-- Increases the global Windows volume
actions.windows_volume_up = function()
bringToFront();
keyboard.stroke("volumeup");
end