Skip to content

Instantly share code, notes, and snippets.

@KenV99
Last active April 23, 2016 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenV99/9240468103a02257524769eac1c3945d to your computer and use it in GitHub Desktop.
Save KenV99/9240468103a02257524769eac1c3945d to your computer and use it in GitHub Desktop.
import sys
import xbmc
import time
import requests
def http_get(url):
r = requests.get(url)
if r.status_code != requests.codes.ok:
xbmc.log('ERROR - %s') % r.text
r.raise_for_status()
def amp_on():
url = r'http://10.0.0.9/cgi-bin/relay.cgi?on'
http_get(url)
def amp_off():
start = time.time()
while time.time() - start < 60: # seconds
xbmc.sleep(1000)
if not xbmc.Player().isPlaying():
url = r'http://10.0.0.9/cgi-bin/relay.cgi?off'
http_get(url)
if __name__ == '__main__':
# use argument 'start' for onPlaybackStarted and 'end' for onPlaybackEnded
if sys.argv[1] == 'start':
amp_on()
else:
amp_off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment