Created
July 18, 2022 02:46
-
-
Save vgmoose/9f5f0c1793313b12af2f2cb489d67ae0 to your computer and use it in GitHub Desktop.
Python script to relatively adjust the volume of a roku TV, can be used in combination with http://devtools.web.roku.com/RokuRemote/
This file contains hidden or 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 os, sys | |
# You can hardcode the IP here if it does not change much | |
ip = "192.168.1.111" | |
args = sys.argv | |
del args[0] | |
if len(args) == 0: | |
print("Needs one or two arguments, eg:") | |
print("\tpython3 roku_vol.py {relative_volume}") | |
print("\tpython3 roku_vol.py {relative_volume} {ip_address}") | |
exit() | |
if len(args) == 1: | |
args.append(ip) | |
amount, ip = args | |
amount = int(amount) | |
if amount < -20 or amount > 20: | |
print("relative_volume must be between -20 and 20 (run the script multiple times for other ranges)") | |
exit() | |
dir = "Up" | |
if amount < 0: | |
dir = "Down" | |
# the actual curl command we'll run amount times | |
cmd = f""" | |
curl 'http://{ip}:8060/keypress/Volume{dir}' \ | |
-X 'POST' \ | |
-H 'Accept: application/json, text/plain, */*' \ | |
-H 'Origin: http://devtools.web.roku.com' \ | |
-H 'Referer: http://devtools.web.roku.com/' \ | |
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15' | |
""" | |
for x in range(abs(amount)): | |
os.system(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment