-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtotem-remote.py
165 lines (120 loc) · 5.01 KB
/
totem-remote.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
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
# -*- coding: utf-8 -*-
from gi.repository import GObject, Peas
from flask import Flask, render_template, jsonify
# from flask import Flask, render_template, jsonify, request, Response
from threading import Thread
# from functools import wraps
from yaml import load
import os
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
app = Flask(__name__, static_url_path='/static')
class StarterPlugin (GObject.Object, Peas.Activatable):
__gtype_name__ = 'TotemRemote'
object = GObject.property (type = GObject.Object)
def __init__ (self):
GObject.Object.__init__ (self)
self._totem = None
print("Plugin Totem-Remote started")
def do_deactivate (self):
self._totem = None
print("Plugin Totem-Remote disabled")
def do_activate (self):
self._totem = self.object
with open(self.plugin_info.get_data_dir() + "/config.yml", 'r') as ymlfile:
self.cfg = load(ymlfile)
# def check_auth(username, password):
# return username == self.cfg["access"]["user"] and password == self.cfg["access"]["pass"]
# def authenticate():
# return Response('Could not verify your credentials', 401,
# {'WWW-Authenticate': 'Basic realm="Login Required"'})
# def requires_auth(f):
# @wraps(f)
# def decorated(*args, **kwargs):
# auth = request.authorization
# if not auth or not check_auth(auth.username, auth.password):
# return authenticate()
# return f(*args, **kwargs)
# return decorated
@app.route("/")
# @requires_auth
def home():
return render_template('home.html')
@app.route("/togglePlay")
# @requires_auth
def togglePlay():
self._totem.play_pause()
return jsonify(playing = True if self._totem.is_playing() else False)
@app.route("/next")
# @requires_auth
def next():
self._totem.seek_next()
return jsonify(info="Playing the next")
@app.route("/previous")
# @requires_auth
def previous():
self._totem.seek_previous()
return jsonify(info="Playing the previous")
@app.route("/toggleFullscreen")
# @requires_auth
def toggleFullscreen():
os.system('totem --fullscreen')
# return jsonify(info="Toggled fullscreen")
return jsonify(fullscreen = True if self._totem.get_property('fullscreen') else False)
@app.route("/exit")
# @requires_auth
def exit():
self._totem.exit()
return jsonify(info='Close Totem')
@app.route("/seekTime/<time>")
# @requires_auth
def seekTime(time):
self._totem.seek_time(int(time), False)
return jsonify(currentTime = self._totem.get_property('current_time'))
@app.route("/info")
# @requires_auth
def info():
info = {}
info['name'] = self._totem.get_property('current-display-name')
info['mrl'] = self._totem.get_property('current-mrl')
info['time'] = self._totem.get_property('current_time')
info['playing'] = self._totem.get_property('playing')
info['length'] = self._totem.get_property('stream-length')
info['seekable'] = self._totem.get_property('seekable')
info['fullscreen'] = self._totem.get_property('fullscreen')
info['volume'] = self._totem.get_volume()
# print(info)
return jsonify(info)
@app.route("/volumeUp")
# @requires_auth
def volumeUp():
os.system('totem --volume-up')
return jsonify(volume = self._totem.get_volume())
@app.route("/volumeDown")
# @requires_auth
def volumeDown():
os.system('totem --volume-down')
return jsonify(volume = self._totem.get_volume())
@app.route("/seekFWD")
# @requires_auth
def seekFWD():
os.system('totem --seek-fwd')
return jsonify(time = self._totem.get_property('current_time'), length = self._totem.get_property('stream-length'))
@app.route("/seekBWD")
# @requires_auth
def seekBWD():
os.system('totem --seek-bwd')
return jsonify(time = self._totem.get_property('current_time'), length = self._totem.get_property('stream-length'))
@app.route("/toggleMute")
# @requires_auth
def toggleMute():
sound = self._totem.get_volume()
if (sound > 0):
os.system('totem --mute')
else:
os.system('totem --volume-up')
return jsonify(sound=sound)
t = Thread(name='flaskServer', target=app.run, kwargs={'port':self.cfg["server"]["port"], 'host':self.cfg["server"]["host"]})
t.start();
print("Plugin Totem-Remote enabled")