~pistos/remoteku

ref: d97f342e0298830f855edb1e05004e6fae706887 remoteku/sample.py -rw-r--r-- 1.6 KiB
d97f342e — Pistos Clarify backend startup instructions 1 year, 4 months ago
                                                                                
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
from roku import Roku

from flask import Flask, jsonify, make_response, request
app = Flask(__name__)

current_roku = None

# @app.route('/')
# def hello_world():
    # return 'Hello, World!'

@app.route('/api/choose-roku', methods=["PUT"])
def choose_roku():
    global current_roku
    req = request.get_json()
    host = req['host']

    rokus = Roku.discover()
    matches = [roku for roku in rokus if roku.host == host]
    current_roku = list(matches)[0]

    return "OK", 200

@app.route('/api/apps')
def apps():
    apps = dict()
    for a in current_roku.apps:
        apps[a.id] = a.name

    return make_response(
        jsonify(apps),
        200
    )

@app.route('/api/launch/<app_id>')
def launch(app_id):
    current_roku[app_id].launch()

    return "OK", 200

@app.route('/api/discover')
def discover():
    rokus = Roku.discover()
    hosts = list(
        map(
            lambda r: r.host,
            rokus
        )
    )

    return make_response(
        jsonify(hosts),
        200
    )

@app.route('/api/press/<button>')
def press(button):
    allowed = [
        "back",
        "backspace",
        "down",
        "forward",
        "home",
        "info",
        "left",
        "mute",
        "play",
        "power",
        "replay",
        "reverse",
        "right",
        "search",
        "select",
        "up",
    ]
    if button in allowed:
        getattr(current_roku, button)()
        return 'OK', 200
    else:
        return 'ERROR: invalid button', 400

@app.route('/api/literal', methods=["POST"])
def literal():
    req = request.get_json()
    string = str(req['string'])

    current_roku.literal(string)

    return 'OK', 200