private void Initialize() { this.Bridge = KodiBridge.CreateBridgeInstance(); // If we're being started as a service, don't run addon specific tasks if (this.IsService) { PyConsole.WriteLine(string.Format("Starting as Service: {0}", this.BaseUrl)); return; } this.Handle = Convert.ToInt32((PythonInterop.EvalToResult("sys.argv[1]")).Value); this.Parameters = (PythonInterop.EvalToResult("sys.argv[2]")).Value; PyConsole.WriteLine(string.Format("BaseUrl: {0}, Handle: {1}, Parameters: {2}", this.BaseUrl, this.Handle, this.Parameters)); PyVariableManager.Reset(); // Instance of XbmcAddon this.Addon = new Addon(PluginId); // Settings accessor this.Settings = new KodiAddonSettings(this.Addon); //this.Monitor = new XbmcMonitor(); //string addonName = BaseUrl.Replace("plugin://", "").Replace("/", ""); }
/// <summary> /// Writes the text representation of the specified object to kodi.log with "sys.stdout.write" /// </summary> /// <param name="value"></param> public static void Write(object value, EscapeFlags escapeMethod = EscapeFlags.Quotes) { string valueStr = value.ToString(); valueStr = PythonInterop.EscapeArgument(valueStr, escapeMethod); PythonInterop.Eval(string.Format("sys.stdout.write({0})", valueStr)); }
public static void WriteLine(string value, EscapeFlags escapeMethod = EscapeFlags.Quotes) { string valueStr; valueStr = PythonInterop.EscapeArgument(value, escapeMethod); valueStr += PythonInterop.EscapeArgument(NewLine, EscapeFlags.Quotes); PythonInterop.Eval(string.Format("sys.stdout.write({0})", valueStr)); }
public static void PlaySFX(string filename, bool?useCached = null) { PythonInterop.CallFunction( PyModule.Xbmc, "playSFX", new List <object> { filename, useCached } ); }
/// <summary> /// Writes the text representation of the specified object to kodi.log with "print" /// </summary> /// <param name="value"></param> public static void Print(object value) { string valueStr = PythonInterop.EscapeArgument(value.ToString()); if (KodiBridge.RunningAddon.DebugEnabled) { Console.Error.WriteLine($"[PyConsole] {valueStr}"); } PythonInterop.Eval(string.Format("print {0}", valueStr)); }
public static bool StartServer(ServerType type, bool bStart, bool?bWait = null) { string typeString = PyModule.Xbmc.GetString() + type.GetString(); return(bool.Parse(PythonInterop.CallFunction( PyModule.Xbmc, "startServer", new List <object> { typeString, bStart, bWait } ))); }
/// <summary> /// Writes the text representation of the specified object to kodi.log with "sys.stdout.write" /// </summary> /// <param name="value"></param> public static void Write(object value, EscapeFlags escapeMethod = EscapeFlags.Quotes) { string valueStr = value.ToString(); if (KodiBridge.RunningAddon.DebugEnabled) { Console.Error.WriteLine($"[PyConsole] {valueStr}"); } valueStr = PythonInterop.EscapeArgument(valueStr, escapeMethod); PythonInterop.Eval(string.Format("sys.stdout.write({0})", valueStr)); }
public static void Sleep(TimeSpan time) { /*PythonInterop.CallFunction( * new PythonFunction(PyModule.Xbmc, "sleep"), * new List<object> { 10000 } * );*/ PythonInterop.CallFunction( PyModule.Xbmc, "sleep", new List <object> { (ulong)time.TotalMilliseconds } ); }
public KodiAddon(bool persist = false, bool debug = false) { DebugEnabled = debug; IsPersistent = persist; try { PyVariableManager = new PyVariableManager(); // Parse parameters this.BaseUrl = PythonInterop.EvalToResult("sys.argv[0]").Value; this.IsService = PythonInterop.EvalToResult("len(sys.argv) < 2").Value; this.Router = new RouteManager(this); } catch (Exception ex) { KodiBridge.SaveException(ex); } }
/// <summary> /// Creates a new addon instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="enableDebug">Enables or disabled the debugging console (works on windows only)</param> /// <param name="persist">Whether or not to reuse a previous addon instance</param> /// <returns></returns> public static T GetInstance <T>(bool enableDebug = false, bool persist = false) where T : KodiAddon { if (enableDebug) { ConsoleHelper.CreateConsole(); } string BaseUrl = PythonInterop.EvalToResult("sys.argv[0]").Value; T instance = null; if (persist) { T previousInstance = (T)KodiBridge.GetPersistentAddon(BaseUrl); if (previousInstance != null) { Console.WriteLine("REUSING PREVIOUS INSTANCE"); instance = previousInstance; } } if (instance == null) { instance = (T)Activator.CreateInstance(typeof(T)); if (persist) { KodiBridge.RegisterPersistentAddon(BaseUrl, instance); } } instance.DebugEnabled = enableDebug; instance.IsPersistent = persist; // Set running addon KodiBridge.SetRunningAddon(instance); // Initialize addon fields. // If the addon is persistent, it updates fields that might have changed instance.Initialize(); return(instance); }
public string this[string key] { // FIXME: settings via XbmcPlugin cause "Invalid Handle" being printed in kodi.log // even if the handle seems valid #if false get { return(PythonInterop.CallFunction( new PythonFunction(PyModule.XbmcPlugin, "getSetting"), new List <object> { KodiBridge.RunningAddon.Handle, key } )); } set { PythonInterop.CallFunction( new PythonFunction(PyModule.XbmcPlugin, "setSetting"), new List <object> { KodiBridge.RunningAddon.Handle, key, value } ); }
public KodiAddon() { try { #if DEBUG ConsoleHelper.CreateConsole(); #endif // Clean the variables list from the previous run (we're in a new python instance so they don't exist anymore) Python.PyVariableManager.Initialize(); // Parse parameters this.BaseUrl = PythonInterop.EvalToResult("sys.argv[0]").Value; this.IsService = PythonInterop.EvalToResult("len(sys.argv) < 2").Value; // Initialize the Event Monitor //Modules.Xbmc.Events.Initialize(); // Set running addon KodiBridge.RunningAddon = this; // If we're being started as a service, don't run addon specific tasks if (this.IsService) { PyConsole.WriteLine(string.Format("Starting as Service: {0}", this.BaseUrl)); return; } this.Handle = int.Parse(PythonInterop.EvalToResult("sys.argv[1]").Value); this.Parameters = PythonInterop.EvalToResult("sys.argv[2]").Value; PyConsole.WriteLine(string.Format("BaseUrl: {0}, Handle: {1}, Parameters: {2}", this.BaseUrl, this.Handle, this.Parameters)); // Register routes for derived type RouteManager.RegisterRoutes(this.GetType()); } catch (Exception ex) { KodiBridge.SaveException(ex); } }
/// <summary> /// Writes the text representation of the specified object to kodi.log with "print" /// </summary> /// <param name="value"></param> public static void Print(object value) { string valueStr = PythonInterop.EscapeArgument(value.ToString()); PythonInterop.Eval(string.Format("print {0}", valueStr)); }
public static void AudioSuspend() { PythonInterop.CallFunction( PyModule.Xbmc, "audioSuspend" ); }
public static void AudioResume() { PythonInterop.CallFunction( PyModule.Xbmc, "audioResume" ); }