This repository has been archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
server.py
86 lines (56 loc) · 1.73 KB
/
server.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
import sys
import alexandra
import click
import pychromecast
device_name = None
cast = None
app = alexandra.Application()
@click.command()
@click.option('--device', help='name of chromecast device', required=True)
def server(device):
global cast
global device_name
print('>> trying to connect to {}'.format(device))
device_name = device
cast = pychromecast.get_chromecast(friendly_name=device)
if cast is None:
click.echo("Couldn't find device '{}'".format(device))
sys.exit(-1)
print(repr(cast))
print('connected, starting up...')
app.run('0.0.0.0', 8183)
@app.intent('Reconnect')
def reconnect(slots, session):
global cast
cast = pychromecast.get_chromecast(friendly_name=device_name)
if cast is None:
return alexandra.respond(
'Failed to connect to Chromecast named %s.' % device_name)
return alexandra.respond('Reconnected.')
@app.intent('SkipMedia')
def skip_media(slots, session):
mc = cast.media_controller
if not mc.status.supports_skip_forward:
return alexandra.respond("Skipping not supported")
mc.skip()
return alexandra.respond()
@app.intent('PlayMedia')
def play_media(slots, session):
mc = cast.media_controller
if mc.status.player_is_playing:
return alexandra.respond("Already playing")
mc.play()
return alexandra.respond()
@app.intent('PauseMedia')
def pause_media(slots, session):
mc = cast.media_controller
if not mc.status.player_is_playing:
return alexandra.respond("Already paused")
mc.pause()
return alexandra.respond()
@app.intent('Reboot')
def reboot(slots, session):
cast.reboot()
return alexandra.respond()
if __name__ == '__main__':
server()