Last active
April 23, 2016 00:48
-
-
Save KenV99/9240468103a02257524769eac1c3945d to your computer and use it in GitHub Desktop.
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 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