-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapp.py
More file actions
executable file
·167 lines (141 loc) · 3.66 KB
/
webapp.py
File metadata and controls
executable file
·167 lines (141 loc) · 3.66 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
from flask import Flask, render_template, redirect, request, url_for
from lib.kodi import Kodi as Kodi
class NowPlaying:
def __init__(self):
#self.title = 'Nothing Playing'
#self.artist = 'Unknown'
#self.album_art = '/static/ben.jpg'
self.title = ''
self.artist = ''
self.album_art = '/static/blue.png'
self.play = False
self.position = 0
self.active = False
def reset(self):
self.__init__()
def update(self):
player = kodi.get_active_player()
if len(player) != 0:
self.active = True
item = kodi.get_item()
now_playing.title = item['label']
if item['type'] == 'episode':
now_playing.artist = item['showtitle']
else:
now_playing.artist = item['showtitle']
now_playing.album_art = kodi.album_art()
else:
now_playing.reset()
app = Flask(__name__)
kodi = Kodi('192.168.1.10')
now_playing = NowPlaying()
@app.route('/')
@app.route('/index')
def index():
global kodi
global now_playing
now_playing.update()
return render_template('now_playing.html', now_playing=now_playing)
@app.route('/play')
def play():
global kodi
global now_playing
try:
now_playing.play = kodi.play_pause()
now_playing.get_position = kodi.get_position()['percentage']
now_playing.update()
except:
now_playing.reset()
return redirect(request.referrer)
@app.route('/stop')
def stop():
global kodi
global now_playing
kodi.stop()
now_playing.reset()
return redirect(url_for('index'))
@app.route('/next')
def next():
global kodi
global now_playing
try:
now_playing.get_position = kodi.fast_forward()['percentage']
except:
now_playing.reset()
return redirect(url_for('index'))
@app.route('/previous')
def previous():
global kodi
global now_playing
try:
now_playing.get_position = kodi.fast_rewind()['percentage']
except:
now_playing.reset()
return redirect(url_for('index'))
@app.route('/remote')
def remote():
now_playing.update()
return render_template('remote.html', now_playing=now_playing)
@app.route('/up')
def up():
global kodi
kodi.input_up()
return redirect(url_for('remote'))
@app.route('/down')
def down():
global kodi
kodi.input_down()
return redirect(url_for('remote'))
@app.route('/left')
def left():
global kodi
kodi.input_left()
return redirect(url_for('remote'))
@app.route('/right')
def right():
global kodi
kodi.input_right()
return redirect(url_for('remote'))
@app.route('/select')
def select():
global kodi
now_playing.update()
kodi.input_select()
return redirect(url_for('remote'))
@app.route('/back')
def back():
global kodi
kodi.input_back()
return redirect(url_for('remote'))
@app.route('/home')
def home():
global kodi
kodi.input_home()
return redirect(url_for('remote'))
@app.route('/context_menu')
def context_menu():
global kodi
kodi.input_context_menu()
return redirect(url_for('remote'))
@app.route('/info')
def info():
global kodi
kodi.input_info()
return redirect(url_for('remote'))
@app.route('/translate_sub')
def translate_sub():
global kodi
kodi.translate_subtitle()
return redirect(url_for('index'))
@app.route('/next_sub')
def next_sub():
global kodi
kodi.next_subtitle()
return redirect(url_for('index'))
@app.route('/update')
def update():
global kodi
kodi.update_library()
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')