Created
November 12, 2017 00:59
-
-
Save HiromuKato/561e548520569fd70877ac3babbcd14a to your computer and use it in GitHub Desktop.
Pythonista application which controls HoloLens recording.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ui | |
import console | |
import requests | |
import base64 | |
isRecording = False | |
url = "192.168.0." # Input Device Portal url | |
token = "" | |
def btnAuth_tapped(sender): | |
global token | |
h = makeHeader(sender) | |
u = "https://" + url | |
try: | |
r = requests.get(url=u, headers=h, verify=False) | |
except requests.exceptions.Timeout as e: | |
print(e) | |
return | |
except requests.exceptions.HTTPError as e: | |
print(e) | |
return | |
token = r.headers['Set-Cookie'] | |
showResponse(sender, r.text) | |
def btnRec_tapped(sender): | |
global isRecording | |
global token | |
h = makeHeader(sender) | |
h["x-csrf-token"] = token.replace("CSRF-Token=", "") | |
if isRecording == False: | |
isRecording = True | |
btn = sender.superview['btnRecord'] | |
btn.title = "Stop" | |
api = "/api/holographic/mrc/video/control/start" | |
p = "?holo=true&pv=true&mic=true&loopback=true" | |
u = "http://" + url + api + p | |
else: | |
isRecording = False | |
btn = sender.superview['btnRecord'] | |
btn.title = "Record" | |
api = "/api/holographic/mrc/video/control/stop" | |
u = "http://" + url + api | |
try: | |
r = requests.post(url=u, headers=h, verify=False) | |
except requests.exceptions.Timeout as e: | |
print(e) | |
return | |
except requests.exceptions.HTTPError as e: | |
print(e) | |
return | |
showResponse(sender, r.text) | |
def makeHeader(sender): | |
user = sender.superview['user'] | |
password = sender.superview['pass'] | |
headers = {} | |
u = user.text + ":" + password.text | |
auth = base64.b64encode(u.encode('utf-8')) | |
headers["authorization"] = "Basic " + auth.decode('utf-8') | |
return headers | |
def showResponse(sender, resText): | |
view = sender.superview['resText'] | |
if resText == "": | |
view.text = "The response was empty." | |
else: | |
view.text = resText | |
v = ui.load_view() | |
v.present('sheet') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UI settings are below.