def xhr_notify_message(): label = str(request.form['label']) hostname = str(request.form['hostname']) message = str(request.form['message']) title = str(request.form['title']) if title == "Title": title = "Maraschino" if server_type() == "XBMC": port = 9777 icon = os.path.join(RUNDIR, 'static', 'images', 'notifications', request.form['image']) if not os.path.exists(icon): icon = os.path.join(RUNDIR, 'static', 'images', 'maraschino_logo.png') if icon[-3:] == "png": icon_type = ICON_PNG elif icon[-3:] == "jpg": icon_type = ICON_JPEG elif icon[-4:] == "jpeg": icon_type = ICON_JPEG elif icon[-3:] == "gif": icon_type = ICON_GIF else: icon_type = ICON_NONE addr = (hostname, port) sock = socket(AF_INET,SOCK_DGRAM) try: logger.log('NOTIFY XBMC :: Sending message to %s' % label, 'INFO') packet = PacketNOTIFICATION(title, message, icon_type, icon) packet.send(sock, addr) return jsonify({ 'status': 'successful'}) except: logger.log('NOTIFY XBMC :: Message failed to send', 'ERROR') return jsonify({ 'error': 'Message failed to send'}) elif server_type() == "PLEX": try: logger.log('NOTIFY XBMC :: Sending message %s' % label, 'INFO') server = PLEXLibrary(server_address()) for connectedclient in server.getClients(): client = PLEXClient(connectedclient['host'], connectedclient['port']) client.sendmessage(title + "," + message) return jsonify({'status': 'successful'}) except Exception, e: logger.log('NOTIFY XBMC :: Message failed to send', 'ERROR') logger.log('NOTIFY XBMC :: Error %s' % e, 'ERROR') return jsonify({'error': 'Message failed to send'})
def xhr_notify_message(): label = str(request.form["label"]) hostname = str(request.form["hostname"]) message = str(request.form["message"]) title = str(request.form["title"]) if title == "Title": title = "Maraschino" if server_type() == "XBMC": port = 9777 icon = os.path.join(RUNDIR, "static", "images", "notifications", request.form["image"]) if not os.path.exists(icon): icon = os.path.join(RUNDIR, "static", "images", "maraschino_logo.png") if icon[-3:] == "png": icon_type = ICON_PNG elif icon[-3:] == "jpg": icon_type = ICON_JPEG elif icon[-4:] == "jpeg": icon_type = ICON_JPEG elif icon[-3:] == "gif": icon_type = ICON_GIF else: icon_type = ICON_NONE addr = (hostname, port) sock = socket(AF_INET, SOCK_DGRAM) try: logger.log("NOTIFY :: Sending message to %s" % label, "INFO") packet = PacketNOTIFICATION(title, message, icon_type, icon) packet.send(sock, addr) return jsonify({"status": "successful"}) except: logger.log("NOTIFY :: Message failed to send", "ERROR") return jsonify({"error": "Message failed to send"}) else: try: logger.log("NOTIFY :: Sending message to %s" % label, "INFO") server = PLEXLibrary(server_address()) for connectedclient in server.getclients(): client = PLEXClient(connectedclient.host, connectedclient.port) client.sendmessage(title + "," + message) return jsonify({"status": "successful"}) except: logger.log("NOTIFY :: Message failed to send", "ERROR") return jsonify({"error": "Message failed to send"})
def xhr_controls(command): if server_type()=="XBMC": serversettings = server_settings() xbmc = jsonrpclib.Server(server_api_address()) try: active_player = xbmc.Player.GetActivePlayers() if active_player[0]['type'] == 'video': playerid = 1 elif active_player[0]['type'] == 'audio': playerid = 0 except: active_player = None if command == 'play_pause': logger.log('CONTROLS :: Play/Pause', 'INFO') try: xbmc.Player.PlayPause(playerid=playerid) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'stop': logger.log('CONTROLS :: Stop', 'INFO') try: xbmc.Player.Stop(playerid=playerid) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif 'volume' in command: logger.log('CONTROLS :: Volume', 'INFO') try: volume = command.split('_') volume = int(volume[1]) xbmc.Application.SetVolume(volume=volume) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'next': logger.log('CONTROLS :: Next', 'INFO') try: xbmc.Player.GoNext(playerid=playerid) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'previous': logger.log('CONTROLS :: Previous', 'INFO') try: xbmc.Player.GoPrevious(playerid=playerid) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'fast_forward': logger.log('CONTROLS :: Fast forward', 'INFO') try: xbmc.Player.SetSpeed(playerid=playerid, speed='increment') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'rewind': logger.log('CONTROLS :: Rewind', 'INFO') try: xbmc.Player.SetSpeed(playerid=playerid, speed='decrement') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif 'seek' in command: logger.log('CONTROLS :: Seek', 'INFO') try: percentage = command.split('_') percentage = int(percentage[1]) xbmc.Player.Seek(playerid=playerid, value=percentage) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'shuffle': logger.log('CONTROLS :: Shuffle', 'INFO') try: version = xbmc.Application.GetProperties(properties=['version'])['version']['major'] if version > 11: xbmc.Player.SetShuffle(playerid=playerid, shuffle='toggle') else: shuffled = xbmc.Player.GetProperties(playerid=playerid, properties=['shuffled'])['shuffled'] if shuffled == True: xbmc.Player.UnShuffle(playerid=playerid) else: xbmc.Player.Shuffle(playerid=playerid) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'repeat': logger.log('CONTROLS :: Repeat', 'INFO') try: version = xbmc.Application.GetProperties(properties=['version'])['version']['major'] if version > 11: xbmc.Player.SetRepeat(playerid=playerid, repeat='cycle') else: states = ['off', 'one', 'all'] repeat = xbmc.Player.GetProperties(playerid=playerid, properties=['repeat'])['repeat'] state = states.index(repeat) if state <= 1: state = state + 1 else: state = 0 state = states[state] xbmc.Player.Repeat(playerid=playerid, state=state) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'update_video': logger.log('CONTROLS :: Updating video library', 'INFO') try: xbmc.VideoLibrary.Scan() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'clean_video': logger.log('CONTROLS :: Cleaning video library', 'INFO') try: xbmc.VideoLibrary.Clean() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'update_audio': logger.log('CONTROLS :: Updating audio library', 'INFO') try: xbmc.AudioLibrary.Scan() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'clean_audio': logger.log('CONTROLS :: Cleaning audio library', 'INFO') try: xbmc.AudioLibrary.Clean() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'poweroff': logger.log('CONTROLS :: Shutting down XBMC machine', 'INFO') try: xbmc.System.Shutdown() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'suspend': logger.log('CONTROLS :: Suspending XBMC machine', 'INFO') try: xbmc.System.Suspend() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'reboot': logger.log('CONTROLS :: Rebooting XBMC machine', 'INFO') try: xbmc.System.Reboot() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'pvr-scan': logger.log('CONTROLS :: Scanning PVR EPG', 'INFO') try: xbmc.PVR.Scan() return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'poweron': logger.log('CONTROLS :: Powering on XBMC machine', 'INFO') server_macaddress = serversettings['mac_address'] if not server_macaddress: logger.log('CONTROLS :: No XBMC machine MAC address defined', 'ERROR') return jsonify({ 'failed': True }) else: try: addr_byte = server_macaddress.split(':') hw_addr = struct.pack('BBBBBB', int(addr_byte[0], 16), int(addr_byte[1], 16), int(addr_byte[2], 16), int(addr_byte[3], 16), int(addr_byte[4], 16), int(addr_byte[5], 16)) msg = '\xff' * 6 + hw_addr * 16 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.sendto(msg, ("255.255.255.255", 9)) return_response = 'success' except: logger.log('CONTROLS :: Failed to send WOL packet', 'ERROR') return_response = 'failed' elif server_type()=="PLEX": mediaplayer = PLEXLibrary(server_address()) active_players=mediaplayer.activePlayers() active_player=active_players[0] client=PLEXClient(active_player['host']) if command == 'play_pause': logger.log('CONTROLS :: Play/Pause', 'INFO') try: mediaplayer.doAction (active_player['host'], 'playback/pause') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'stop': logger.log('CONTROLS :: Stop', 'INFO') try: mediaplayer.doAction (active_player['host'], 'playback/stop') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'fast_forward': logger.log('CONTROLS :: Fast forward', 'INFO') try: mediaplayer.doAction (active_player['host'], 'playback/fastForward') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'rewind': logger.log('CONTROLS :: Rewind', 'INFO') try: mediaplayer.doAction (active_player['host'], 'playback/rewind') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'next': logger.log('CONTROLS :: Next', 'INFO') try: mediaplayer.doAction (active_player['host'], 'playback/skipNext') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif command == 'previous': logger.log('CONTROLS :: Previous', 'INFO') try: mediaplayer.doAction (active_player['host'], 'playback/skipPrevious') return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif 'volume' in command: logger.log('CONTROLS :: Volume', 'INFO') try: volume = command.split('_') volume = int(volume[1]) client.setVolume(volume) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' elif 'seek' in command: logger.log('CONTROLS :: Seek', 'INFO') try: percentage = command.split('_') percentage = int(percentage[1]) client.seekPercentage(percentage) return_response = 'success' except: logger.log('CONTROLS :: %s' % xbmc_error, 'ERROR') return_response = 'failed' return_response="success" if return_response == 'success': return jsonify({ 'success': True }) else: return jsonify({ 'failed': True })