/
launch_playlist_youtube.py
52 lines (42 loc) · 1.37 KB
/
launch_playlist_youtube.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
import time
from roku import Roku
def main():
# Locate the roku device
printing("Finding roku device ...")
rokus = Roku.discover()
printing("Done finding roku device ...")
# IF no devices found ...
if len(rokus) == 0:
print("No rokus found")
sys.exit(-1)
# Otherwise, get the ip and port of the device
else:
roku_ip_address = rokus[0].host
roku_port = rokus[0].port
# Setup API object to make requests to the roku device
print("Connecting ...")
roku = Roku(host=roku_ip_address, port=roku_port)
print("Done connecting ...")
# Find youtube app
print("Finding youtube app ...")
youtube_app = [ a for a in roku.apps if 'youtube' in a.name.lower() ][0]
print("Done finding youtube app ...")
# Wait for the app to start
print("Starting youtube app ...")
APP_LAUNCH_TIMEOUT = 15
youtube_app.launch()
time.sleep(APP_LAUNCH_TIMEOUT)
print("Done starting youtube app ...")
# Series of remote clicks to get to youtube Watch Later playlist
# TODO: sleeps may not be needed
roku.left(); time.sleep(1)
roku.left(); time.sleep(1)
roku.down(); time.sleep(1)
roku.down(); time.sleep(1)
roku.right(); time.sleep(1)
roku.down(); time.sleep(1)
roku.down(); time.sleep(1)
roku.right(); time.sleep(1)
roku.select();
if __name__ == '__main__':
main()