Uh oh!
There was an error while loading. Please reload this page.
forked from veldenb/plugin.program.moonlight-qt
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon.py
More file actions
Latest commit
304 lines (241 loc) · 9.42 KB
/
Copy pathaddon.py
File metadata and controls
304 lines (241 loc) · 9.42 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
importconfigparser
importmoonlight
importsys
importurllib.parse
importxbmc
importxbmcaddon
importxbmcgui
importxbmcplugin
fromxbmcvfsimporttranslatePath
defbuild_url(query):
returnbase_url+'?'+urllib.parse.urlencode(query)
defget_addon_path(sub_path):
returntranslatePath(addon.getAddonInfo('path') +sub_path)
defget_addon_data_path(sub_path=''):
returntranslatePath('special://profile/addon_data/plugin.program.moonlight-qt'+sub_path)
defget_resource_path(sub_path):
returnget_addon_path('/resources'+sub_path)
defget_icon_path():
returnget_resource_path('/icon.png')
defget_poster_path():
returnget_resource_path('/poster.jpg')
defget_fanart_path():
returnget_resource_path('/fanart.jpg')
defget_boxart_path(host, app):
sampleBoxart='/moonlight-home/.cache/Moonlight Game Streaming Project/Moonlight/boxart/{}/{}.png'.format(
host.get('uuid'), app.get('id')
)
returnget_addon_data_path(sampleBoxart)
defget_moonlight_config():
# Load config
moonlight_full_config_path=get_addon_data_path(
'/moonlight-home/.config/Moonlight Game Streaming Project/Moonlight.conf'
)
returnparse_moonlight_config(moonlight_full_config_path)
defparse_moonlight_config(moonlight_config_file):
config=configparser.ConfigParser()
config.read(moonlight_config_file)
parsedOptions= {}
forsectioninconfig.sections():
parsedOptions[section] = {}
foroptioninconfig.options(section):
options=option.split('\\')
optionValue=config.get(section, option)
# It would be nice if the code below could be simplified, essentially you want to convert and merge
# \\a\\b\\c\\d1\\val1 and \\a\\b\\c\\d2\\val2 to { a: { b: { c: { d1: val1, d2: val2 }}}}
iflen(options) ==4:
o1, o2, o3, o4=options
ifo1notinparsedOptions[section]:
parsedOptions[section][o1] = {}
ifo2notinparsedOptions[section][o1]:
parsedOptions[section][o1][o2] = {}
ifo3notinparsedOptions[section][o1][o2]:
parsedOptions[section][o1][o2][o3] = {}
parsedOptions[section][o1][o2][o3][o4] =optionValue
eliflen(options) ==3:
o1, o2, o3=options
ifo1notinparsedOptions[section]:
parsedOptions[section][o1] = {}
ifo2notinparsedOptions[section][o1]:
parsedOptions[section][o1][o2] = {}
parsedOptions[section][o1][o2][o3] =optionValue
eliflen(options) ==2:
o1, o2=options
ifo1notinparsedOptions[section]:
parsedOptions[section][o1] = {}
parsedOptions[section][o1][o2] =optionValue
eliflen(options) ==1:
o1=options[0]
parsedOptions[section][o1] =optionValue
returnparsedOptions
defshow_hosts(handle, hosts):
# Show hosts
fortag_idinhosts:
if'apps'inhosts[tag_id]:
host=hosts[tag_id]
url=build_url({'mode': 'host', 'host_id': tag_id})
li=xbmcgui.ListItem(host.get('hostname'))
xbmcplugin.addDirectoryItem(handle, url, li, isFolder=True)
defshow_moonlight(handle):
url=build_url({'mode': 'launch'})
li=xbmcgui.ListItem(addon.getLocalizedString(30001))
icon=get_icon_path()
li.setArt({
'thumb': icon,
'poster': get_poster_path(),
'fanart': get_fanart_path(),
'icon': icon
})
xbmcplugin.addDirectoryItem(handle, url, li)
defshow_games(handle, hosts, host_id):
# Show games for host
host=hosts[host_id]
if'apps'inhost:
forapp_id, appinhost['apps'].items():
if'name'inapp:
url=build_url({'mode': 'launch', 'host_id': host_id, 'game_id': app_id})
boxart=get_boxart_path(host, app)
li=xbmcgui.ListItem()
li.setLabel(app.get('name'))
li.setArt({
'thumb': boxart,
'poster': boxart
})
xbmcplugin.addDirectoryItem(handle, url, li)
defshow_gui(handle, mode, host_id, game_id):
# Get hosts from moonlight config
hosts=get_moonlight_config().get('hosts')
ifmodeisNone:
ifhosts:
# If there is only one host and a size-item then show the games immediately
iflen(hosts) ==2:
host_id=list(hosts.keys())[0]
show_games(handle, hosts, host_id)
else:
show_hosts(handle, hosts)
# Always show Moonlight
show_moonlight(handle)
# Finish list
xbmcplugin.endOfDirectory(handle)
elifmode=='host'andhost_idinhosts:
# Show games
show_games(handle, hosts, host_id)
# Always show Moonlight
show_moonlight(handle)
# Finish list
xbmcplugin.endOfDirectory(handle)
elifmode=='launch':
# Launch game on host
ifhost_idisnotNoneandgame_idisnotNone:
host_name=hosts[host_id]['localaddress']
game_name=hosts[host_id]['apps'][game_id]['name']
# Launch game
moonlight.launch(addon, host_name, game_name)
else:
# Launch Moonlight
moonlight.launch(addon)
elifmode=='update':
# Update Moonlight
moonlight.update(addon)
else:
xbmc.log('Unknown GUI mode: {}'.format(mode), xbmc.LOGDEBUG)
# Arguments
base_url=sys.argv[0]
addon_handle=int(sys.argv[1])
args=urllib.parse.parse_qs(sys.argv[2][1:])
# Configure addon
addon=xbmcaddon.Addon()
ifaddon_handle!=-1:
xbmcplugin.setContent(addon_handle, 'games')
# Debug stuff
# See https://kodi.wiki/view/Audio-video_add-on_tutorial
# xbmc.log(sys.argv.__str__(), xbmc.LOGDEBUG)
# xbmc.log(args.__str__(), xbmc.LOGDEBUG)
# xbmc.log('CONFIG: ' + moonlight_config.__str__(), level=xbmc.LOGDEBUG)
page_mode=args.get('mode', None)
ifpage_modeisnotNone:
page_mode=page_mode[0]
page_host_id=args.get('host_id', None)
ifpage_host_idisnotNone:
page_host_id=page_host_id[0]
page_game_id=args.get('game_id', None)
ifpage_game_idisnotNone:
page_game_id=page_game_id[0]
# Show GUI
show_gui(addon_handle, page_mode, page_host_id, page_game_id)
# Parsed config example
# example_moonlight_config = {
# 'General': {
# 'abstouchmode': 'true',
# 'audiocfg': '1',
# 'backgroundgamepad': 'false',
# 'bitrate': '20000',
# 'capturesyskeys': '0',
# 'certificate': '"@ByteArray(-----BEGIN CERTIFICATE-----\\nABCDEFFF\\nABCDEF=\\n-----END CERTIFICATE-----\\n)"',
# 'connwarnings': 'true',
# 'defaultver': '1',
# 'detectnetblocking': 'false',
# 'fps': '60',
# 'framepacing': 'false',
# 'gameopts': 'false',
# 'gamepadmouse': 'true',
# 'height': '1080',
# 'hostaudio': 'true',
# 'key': '@ByteArray(-----BEGIN PRIVATE KEY-----\\nABCDEFFFFF\\ABCDEF\\n-----END PRIVATE KEY-----\\n)',
# 'language': '0',
# 'latestsupportedversion-v1': '99.99.99.99',
# 'mdns': 'false',
# 'mouseacceleration': 'false',
# 'multicontroller': 'true',
# 'muteonfocusloss': 'false',
# 'packetsize': '0',
# 'quitappafter': 'true',
# 'reversescroll': 'false',
# 'richpresence': 'true',
# 'swapfacebuttons': 'false',
# 'swapmousebuttons': 'false',
# 'uidisplaymode': '0',
# 'unsupportedfps': 'false',
# 'videocfg': '0',
# 'videodec': '0',
# 'vsync': 'false',
# 'width': '1920',
# 'windowmode': '0'
# },
# 'gcmapping': {
# '1': {'guid': '00001000010000100001000010000100',
# 'mapping': '"dev:xb1:Some joypad,platform:Linux,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,a:b2,"'},
# 'size': '1'},
# 'hosts': {
# '1': {
# 'apps': {
# '1': {
# 'appcollector': 'false',
# 'directlaunch': 'false',
# 'hdr': 'false',
# 'hidden': 'false',
# 'id': '1234567890',
# 'name': 'Some game 1'
# },
# '2': {
# 'appcollector': 'false',
# 'directlaunch': 'false',
# 'hdr': 'true',
# 'hidden': 'false',
# 'id': '0123456789',
# 'name': 'Some game 2'
# }, 'size': '2'
# },
# 'customname': 'false',
# 'hostname': 'MYHOSTNAME',
# 'ipv6address': '1000:0000:11:2:33:4444:5555:6666',
# 'localaddress': '192.168.0.2',
# 'mac': '@ByteArray(AA\\0\\aa0A])',
# 'manualaddress': '192.168.1.141',
# 'remoteaddress': '123.123.123.123',
# 'srvcert': '"@ByteArray(-----BEGIN CERTIFICATE-----\\nABCDEFFFFFF=\\n-----END CERTIFICATE-----\\n)"',
# 'uuid': 'aaaaaaaa-1234-aaaa-1234-aaaaaaaaaaaa'
# },
# 'size': '1'
# }
# }