def do_POST(self): global player global home_path jsonData = json.loads(self.rfile.read(int(self.headers.getheader('content-length')))) print 'Data received from phone : ' print jsonData command = jsonData['command']; if command == 'pause' and 'player' in globals(): player.pause() elif command == 'seek_backward' and 'player' in globals(): player.action(19) elif command == 'seek_forward' and 'player' in globals(): player.action(20) elif command == 'seek_fast_backward' and 'player' in globals(): player.action(21) elif command == 'seek_fast_forward' and 'player' in globals(): player.action(22) elif command == 'previous_audio_stream' and 'player' in globals(): player.action(6) elif command == 'next_audio_stream' and 'player' in globals(): player.action(7) elif command == 'previous_subtitle_stream' and 'player' in globals(): player.action(10) elif command == 'next_subtitle_stream' and 'player' in globals(): player.action(11) elif command == 'decrease_subtitle_delay' and 'player' in globals(): player.action(13) elif command == 'increase_subtitle_delay' and 'player' in globals(): player.action(14) elif command == 'stop' and 'player' in globals(): player.stop() player.quit() del player elif command == 'delete_file': os.remove(jsonData['path']) elif command == 'delete_folder': shutil.rmtree(jsonData['path']) elif command == 'poweroff': call(['sudo', 'poweroff']) elif command == 'reboot': call(['sudo', 'reboot']) elif command == 'play': if 'player' in globals(): player.stop() player.quit() player = OMXPlayer(jsonData['path'], args=['-b']) player.play() elif command == 'is_playing': if 'player' in globals(): SendResponse(self, {'command': command, 'path': player.get_filename()}) else: SendResponse(self, {'command': command, 'path': ''}) elif command == 'list_dir': path = jsonData['path'] if 'path' in jsonData else home_path files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and os.path.splitext(f)[1] in SUPPORTED_FORMATS] dirs = [f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))] files.sort() dirs.sort() SendResponse(self, {'command': command, 'path': path, 'files': files, 'dirs': dirs})