Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 83 lines (55 sloc) 1.658 kB
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
1 from flask import Flask, jsonify, render_template
2
aa08f25 @N3MIS15 add --webroot arg
N3MIS15 authored
3 from maraschino import app, RUNDIR
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
4 from socket import *
0292eba @gugahoi moved xbmcclient lib file into lib/xbmc dir
gugahoi authored
5 from xbmc.xbmcclient import XBMCClient
8b56c1c @gugahoi ironed a couple of bugs
gugahoi authored
6 from maraschino.tools import get_setting_value
a7763a0 @mrkipling fixed remote
authored
7 from maraschino.noneditable import *
8
8f6f2cf @mrkipling ewww, this is such a gross hack, but at least the remote works in Apa…
authored
9 import time, os
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
10
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
11 global connected
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
12 connected = False
13
c3df2da @mrkipling moved update_xbmc_object position
authored
14 def update_xbmc_object():
a7763a0 @mrkipling fixed remote
authored
15 serversettings = server_settings()
16 host = serversettings['hostname']
17
c3df2da @mrkipling moved update_xbmc_object position
authored
18 try:
aa08f25 @N3MIS15 add --webroot arg
N3MIS15 authored
19 icon = RUNDIR + '/static/images/maraschino_logo.png'
8f6f2cf @mrkipling ewww, this is such a gross hack, but at least the remote works in Apa…
authored
20
21 xbmc = XBMCClient('Maraschino', icon, ip=host)
22
c3df2da @mrkipling moved update_xbmc_object position
authored
23 except:
24 xbmc = None
25
26 return xbmc
27
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
28 @app.route('/remote/<key>')
29 def remote(key):
30 global connected
31
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
32 xbmc = update_xbmc_object()
33
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
34 if not connected:
35 if xbmc.connect():
36 connected = True
4bc9e91 @mrkipling trailing whitespace
authored
37
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
38 xbmc.send_keyboard_button(key)
39
8b56c1c @gugahoi ironed a couple of bugs
gugahoi authored
40 time.sleep(0.3)
4bc9e91 @mrkipling trailing whitespace
authored
41
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
42 if xbmc.release_button():
4bc9e91 @mrkipling trailing whitespace
authored
43 return jsonify({ 'status': 'successful'})
9e1db61 @gugahoi initial eventserver implementation.
gugahoi authored
44
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
45 return jsonify({ 'error': 'failed'})
4bc9e91 @mrkipling trailing whitespace
authored
46
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
47 @app.route('/remote/ping')
48 def ping():
49 global connected
50
51 xbmc = update_xbmc_object()
4bc9e91 @mrkipling trailing whitespace
authored
52
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
53 if xbmc.ping():
54 connected = True
55 return jsonify({ 'status': 'successful'})
4bc9e91 @mrkipling trailing whitespace
authored
56
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
57 connected = False
4bc9e91 @mrkipling trailing whitespace
authored
58 return jsonify({ 'error': 'failed'})
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
59
60 @app.route('/remote/close')
61 def close():
62 global connected
4bc9e91 @mrkipling trailing whitespace
authored
63
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
64 xbmc = update_xbmc_object()
4bc9e91 @mrkipling trailing whitespace
authored
65
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
66 if xbmc.close():
67 connected = False
68 return jsonify({ 'status': 'successful'})
4bc9e91 @mrkipling trailing whitespace
authored
69
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
70 return jsonify({ 'error': 'failed'})
71
72 @app.route('/remote/connect')
73 def connect():
74 global connected
4bc9e91 @mrkipling trailing whitespace
authored
75
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
76 xbmc = update_xbmc_object()
77
78 if xbmc.connect():
79 connected = True
80 return jsonify({ 'status': 'successful'})
4bc9e91 @mrkipling trailing whitespace
authored
81
90ba915 @gugahoi Improved remote module connection method
gugahoi authored
82 return jsonify({ 'error': 'failed'})
Something went wrong with that request. Please try again.