def setup(self, hosts=None, username=None, password=None): self._connections = [] for host in (x.strip() for x in (hosts or sickbeard.KODI_HOST or '').split(",") if x.strip()): try: kodi = Kodi(host, username or sickbeard.KODI_USERNAME, password or sickbeard.KODI_PASSWORD) kodi.host = kodi.variables()['hostname']['value'] kodi.name = kodi.Settings.GetSettingValue( setting="services.devicename")['result']['value'] if kodi not in self._connections: self._connections.append(kodi) except (URLError, RequestTimeout): pass
def __init__(self, config): log.debug("init: %s:%d u:%s", config['host'], config['port'], config['username']) self.kd = Kodi(hostname=config['host'], port=config['port'], username=config['username'], password=config['password'])
def stopKodi(ip): try: k = Kodi(ip) resp = k.System.Shutdown() sleep(15) return True except: return False
def setup(self, hosts=None, username=None, password=None): self._connections = [] for host in (x.strip() for x in (hosts or settings.KODI_HOST or "").split(",") if x.strip()): try: if ":" in host: bare_host, port = host.split(":") kodi = Kodi(bare_host, username or settings.KODI_USERNAME, password or settings.KODI_PASSWORD, port=try_int(port, 8080)) else: kodi = Kodi(host, username or settings.KODI_USERNAME, password or settings.KODI_PASSWORD) kodi.host = kodi.variables()["hostname"]["value"] try: server_name = kodi.Settings.GetSettingValue( setting="services.devicename")["result"]["value"] kodi.name = server_name except: pass if kodi not in self._connections: self._connections.append(kodi) except (URLError, RequestTimeout, KeyError, IndexError): pass
def __init__(self): super(KodiControllerSkill, self).__init__(name="KodiControllerSkill") # Initialize working variables used within the skill. self.myKodi = Kodi(self.settings["ip_address"], port=self.settings["port"], username=self.settings["user"], password=self.settings["password"]) self.vocabs = [] self.debug_mode = False
def play(): params = request.get_json() url = params['url'] client = FsToClient() content = client.get_content(url) file_url = content.file.hd_url kodi = Kodi(connection['server'], username=auth['username'], password=auth['password']) resp = kodi.Player.Open(item={'file': file_url})
def isKodiUp(ip, ntry=5): count = 1 while count < ntry: try: k = Kodi(ip) k.JSONRPC.Version() return True except: sleep(1) count += 1 return False
def do_kodi(): """ # /kodi?id=[rPI_DAC | rPI_SPDIF]&method=['ON'|'OFF'|'FAV'][&favidx=n] :return: """ try: id = request.forms.get('id') method = request.forms.get('method') kodi_ip = rPIs[id] except: kodi_ip = None if method == 'ON': resp = tdtool.doMethod(devices[id], methods[method]) count = 0 if method == 'ON': maxcount = 10 else: maxcount = 1 while count < maxcount: try: kodi = Kodi(kodi_ip) print 'Connected to Kodi %s' % id break except: print 'Retrying...' sleep(1) count += 1 else: # resp = tdtool.doMethod(devices[id], methods['OFF']) if method == 'ON': return 'POWERED' else: print 'Failed' return 'Failed' response.content_type = 'application/json' if method == 'ON': resp = kodi.JSONRPC.Version() return 'Kodi On' else: resp = kodi.System.Shutdown() sleep(5) resp = tdtool.doMethod(devices[id], methods[method]) return 'OFF'
def do_kodistate(): """ # /kodistate?id=<device> :return: 'ON', 'OFF' """ id = request.query.id resp = tdtool.getDeviceState(devices[id]) if resp == 'OFF': return 'OFF' else: try: kodi = Kodi(rPIs[id]) resp = kodi.JSONRPC.Ping() return 'Kodi On' except: # resp = tdtool.doMethod(devices[id], methods['OFF']) return 'POWERED'
def main(): parser = ArgumentParser() parser.add_argument('--hd', metavar='N', type=bool, default=True, help='Play in HD quality. True by default.') parser.add_argument('-d', metavar='N', dest='direct' type=bool, default=False, help='Play direct url. Dont parse.') parser.add_argument('url') args = parser.parse_args() file_url = '' if (!args.direct): client = FsToClient() content = client.get_content(args.url) file_url = content.file.hd_url if args.hd else content.file.url else: file_url = args.url kodi = Kodi('192.168.0.105', username='******', password='******') resp = kodi.Player.Open(item={'file': file_url}) print(resp)
def on_websettings_changed(self): if not self._is_setup: kodi_ip = self.settings.get("kodi_ip", "127.0.0.1") kodi_port = self.settings.get("kodi_port", "8080") kodi_user = self.settings.get("kodi_user", "") kodi_pass = self.settings.get("kodi_pass", "") try: if kodi_ip and kodi_port: kodi_ip = self.settings["kodi_ip"] kodi_port = self.settings["kodi_port"] kodi_user = self.settings["kodi_user"] kodi_pass = self.settings["kodi_pass"] # self.kodi_instance = Kodi(kodi_ip) self.kodi_instance = Kodi(hostname=kodi_ip, port=kodi_port, username=kodi_user, password=kodi_pass) self.kodi_path = "http://" + kodi_ip + ":" + kodi_port + "/jsonrpc" # self.kodi_payload = '{"jsonrpc":"2.0","method":"player.open", "params": {"item":{"playlistid":1}}}' self._is_setup = True except Exception as e: LOG.error(e)
def on_websettings_changed(self): # when updating mycroft home page if not self._is_setup: kodi_ip = self.settings.get("kodi_ip", "127.0.0.1") kodi_port = self.settings.get("kodi_port", "8080") kodi_user = self.settings.get("kodi_user", "") kodi_pass = self.settings.get("kodi_pass", "") try: if kodi_ip and kodi_port: kodi_ip = self.settings["kodi_ip"] kodi_port = self.settings["kodi_port"] kodi_user = self.settings["kodi_user"] kodi_pass = self.settings["kodi_pass"] # TODO - remove kodipydent usage self.kodi_instance = Kodi(hostname=kodi_ip, port=kodi_port, username=kodi_user, password=kodi_pass) self.kodi_path = "http://" + kodi_user + ":" + kodi_pass + "@" + kodi_ip + ":" + str(kodi_port) + \ "/jsonrpc" self._is_setup = True except Exception as e: LOG.error(e)
def __init__(self, client, playerPath, filePath, args): self._client = client self._paused = None self._position = 0.0 self._duration = None self._filename = None self.quitReason = None self.lastLoadedTime = None self.fileLoaded = False self.delayedFilePath = None self._kodiHost = self.getParamValue(args, 'kodiHost', '127.0.0.1') self._kodiPort = self.getParamValue(args, 'kodiPort', 8080) self._kodiUser = self.getParamValue(args, 'kodiUser', 'kodi') self._kodiPass = self.getParamValue(args, 'kodiPass', '1234') try: self.kodipydent = Kodi(self._kodiHost, port=self._kodiPort, username=self._kodiUser, password=self._kodiPass) except ValueError: return
def __init__(self): super(KodiSkill, self).__init__(name="KodiSkill") self.kodi = Kodi('10.21.5.180')
from kodipydent import Kodi import re my_kodi_instance = Kodi('192.168.0.32') def find_films_matching(kodi_id, search): """ Find all Movies Matching the search """ my_movies = kodi_id.VideoLibrary.GetMovies()['result']['movies'] results = [] print(search) for m in my_movies: index_movie = re.sub('\W', ' ', m['label'].lower()) index_movie = re.sub(' +', ' ', index_movie) if search in index_movie: results.append(m) return results def play_film(kodi_id, movieid): """ Play a movie by id. """ kodi_id.Playlist.Clear(playlistid=1) kodi_id.Playlist.Add(playlistid=1, item={'movieid': movieid}) kodi_id.Player.Open(item={'playlistid': 1}) def play_film_by_search(kodi_id, film_search):
def on_websettings_changed(self): self.myKodi = Kodi(self.settings["ip_address"], port=self.settings["port"], username=self.settings["user"], password=self.settings["password"])
for each in movies: movie_list.append(each["label"]) return get_close_matches(string, movie_list) if __name__ == "__main__": config = { "server.socket_host": "127.0.0.1", "server.socket_port": 8989, "request.show_tracebacks": False, "tools.response_headers.on": True, "tools.response_headers.headers": [("Content-Type", "text/plain")] } cherrypy.config.update(config) try: KODI = Kodi("localhost") except Exception as err: reason = str(err.reason) cherrypy.log("Failed to load Kodi") cherrypy.log(reason) import sys sys.exit("Failed to load Kodi\n" + reason) else: try: cherrypy.quickstart(KodiServ()) except Exception as err: sys.exit(err)
def show_info(): check = Kodi(data[main_option.get()]).Input.ShowPlayerProcessInfo()
def show_menu(): check = Kodi(data[main_option.get()]).Input.ContextMenu()
def key_select(): check = Kodi(data[main_option.get()]).Input.Select()
def stop(): check = Kodi(data[main_option.get()]).Player.Stop(playerid=1)
def play_pause(): check = Kodi(data[main_option.get()]).Player.PlayPause(playerid=1)
def key_home(): check = Kodi(data[main_option.get()]).Input.Home()
def key_back(): check = Kodi(data[main_option.get()]).Input.Back()
def key_right(): check = Kodi(data[main_option.get()]).Input.Right()
def key_down(): check = Kodi(data[main_option.get()]).Input.Down()
else: config = configparser.ConfigParser() config.read(kapiconfig) cherrypyconfig = { "server.socket_host": config["Server"]["host"], "server.socket_port": config.getint("Server", "port"), "request.show_tracebacks": config.getboolean("Server", "debug", fallback=False), "tools.response_headers.on": True, "tools.response_headers.headers": [("Content-Type", "text/html")], "tools.response_headers.headers": [("Access-Control-Allow-Origin", "https://0xfdb.xyz")], } cherrypy.config.update(cherrypyconfig) try: KODI = Kodi( hostname=config["Kodi"]["hostname"], port=config["Kodi"]["port"], username=config.get("Kodi", "username", fallback=None), password=config.get("Kodi", "password", fallback=None), ) except Exception as err: cherrypy.log(str(err.reason)) sys.exit(f"Failed to load Kodi\n{str(err.reason)}") else: style = config.get("Server", "style") cherrypy.quickstart(KodiServ(key=config["Server"]["key"], style=style))
def show_notification(): check = Kodi(data[main_option.get()]).GUI.ShowNotification(title=p1.get(), message='')
def key_left(): check = Kodi(data[main_option.get()]).Input.Left()
def key_up(): check = Kodi(data[main_option.get()]).Input.Up()