Last active
December 21, 2016 18:29
-
-
Save alexvicegrab/8d83b7ef3e26036dc78fc8c7e3a01091 to your computer and use it in GitHub Desktop.
Simple remote controller for Kodi player
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
#! /usr/bin/env python | |
import curses | |
import os | |
import sys | |
from socket import * | |
from kodi.xbmcclient import * # You may need to install the kodi xbmc client | |
from blessings import Terminal # Not strictly necessary, but for printing warning messages in colour | |
t = Terminal() | |
ip = "localhost" # Assuming you want to control your Kodi from within an SSH terminal connection | |
port = 9777 | |
addr = (ip, port) | |
sock = socket(AF_INET,SOCK_DGRAM) | |
# Most important keys for controlling Kodi | |
key_dict = {curses.KEY_RIGHT: "Right", | |
curses.KEY_LEFT: "Left", | |
curses.KEY_UP: "Up", | |
curses.KEY_DOWN: "Down", | |
10: "Select", | |
curses.KEY_BACKSPACE: "Back", | |
ord("m"): "OSD"} | |
def get_answer(stdscr): | |
answer = None | |
while answer != 27: | |
answer = stdscr.getch() | |
if answer in key_dict: | |
print t.yellow(key_dict[answer]) | |
packet = PacketACTION(actionmessage=key_dict[answer], actiontype=ACTION_BUTTON) | |
packet.send(sock, addr) | |
elif answer == 27: | |
break | |
else: | |
print t.red("Bad key: {}".format(answer)) | |
if __name__ == '__main__': | |
curses.wrapper(get_answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment