-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathandroidviewclient.py
98 lines (76 loc) · 3 KB
/
androidviewclient.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import re
import traceback
from time import sleep, time
from com.dtmilano.android.viewclient import ViewClient
def loop_until(func, seconds=15, nofail=False):
start = time()
firstrun = True
while True:
try:
print("Looping " + str(func))
ret = func(firstrun=firstrun)
if ret != "continue":
break
except Exception:
traceback.print_exc()
if (time() - start) > seconds:
if nofail:
return
else:
raise
if (time() - start) > seconds:
return
sleep(0.5)
firstrun = False
class Netflix:
def __init__(self, chromecast_name, connect_ip=None):
self.chromecast_name = chromecast_name
self.connect_ip = connect_ip
def cast(self, search_term):
if self.connect_ip:
subprocess.check_call(["adb", "connect", self.connect_ip])
kwargs1 = {"verbose": False, "ignoresecuredevice": False, "ignoreversioncheck": False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {
"forceviewserveruse": False,
"startviewserver": True,
"autodump": False,
"ignoreuiautomatorkilled": True,
"compresseddump": True,
"useuiautomatorhelper": False,
"debug": {},
}
vc = ViewClient(device, serialno, **kwargs2)
vc.device.shell("input keyevent KEYCODE_WAKEUP")
vc.device.shell("input keyevent KEYCODE_WAKEUP")
vc.device.shell("am force-stop com.netflix.mediaclient")
vc.device.startActivity(
"com.netflix.mediaclient/com.netflix.mediaclient.ui.launch.NetflixComLaunchActivity"
)
vc.dump(window="-1", sleep=2)
def _cast(**kwargs):
vc.dump(window="-1", sleep=1)
vc.findViewById("com.netflix.mediaclient:id/ab_menu_cast_item").touch()
vc.dump(window="-1", sleep=1)
vc.findViewWithTextOrRaise(re.compile(self.chromecast_name)).touch()
loop_until(_cast, seconds=5, nofail=True)
def _search(firstrun):
vc.dump(window="-1", sleep=2)
if not firstrun:
vc.findViewByIdOrRaise("com.netflix.mediaclient:id/ab_menu_search_item").touch()
vc.dump(window="-1", sleep=2)
vc.setText((vc.findViewByIdOrRaise("android:id/search_src_text")), search_term)
vc.device.shell("input keyevent KEYCODE_BACK")
loop_until(_search)
def _clicksearch(**kwargs):
vc.dump(window="-1", sleep=1)
vc.findViewById("com.netflix.mediaclient:id/search_result_img").touch()
loop_until(_clicksearch)
def _play(**kwargs):
vc.dump(window="-1", sleep=1)
vc.findViewById("com.netflix.mediaclient:id/video_img").touch()
loop_until(_play)
vc.dump(window="-1", sleep=2)