Kodi Community Forum
Your 1st Add-On: Hello World! - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Your 1st Add-On: Hello World! (/showthread.php?tid=209948)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


RE: Your First Add-On: Hello World! - cayfordb - 2015-06-07

Hi. I'm working on a Plugin that lets me control my AVR (Pioneer VSX1023) from various Remotes. I want to be able to hit a button on the Tivo remote and have the AVR change to the Tivo Input. Hit a button on the AppleTV remote and change to the AppleTV input. Hit a button on the Kodi remote and have the AVR change to the Raspberry Pi input.

I've used Hello World as a starting point. I have a FLIRC, and have mapped various remote keys to unused keyboard commands like "ALT-a", "ALT-b", "ALT-SHIFT-A" etc. So Apple TV Remote "Menu" is ALT-Shift-F, and Apple Down is "Alt-shift-B". Tivo Remote Home is Alt-Shift-V.

I have keymap.xml set up in userdata/keymaps, and with experimentation I now have several Apple-TV keys starting Hello World. From Keymaps is can add arguments so that the Plugin knows what key was hit.

Separately, with Telnet, I can ask the AVR what input it is currently on, and I can change to any of the inputs. Looks like I can do that from the Plugin. I'll remove the Hello World Dialog, and this will all be silent in the background.

So far so good.

Questions: it seems a plugin is executed in a new Python Interpreter process every time it is invoked from Keymap. Seems to take half a second, sometimes more, like 2-3 seconds. Is there a way to have the plugin stay resident and not require launching a new Python Interpreter every time? What is the standard way to keep persistent variables? Using "global" wont work if the program is a new process instance every time.

In keymap.xml and the Kodi Info page, it says you can use "RunScript(plugin, [,args])". When I run it, the Kodi.log says this is deprecated. Should I have the plugin itself load in a different place? I'm using the exact same "<extension>" values as the original example. Here is the log entry:

11:52:13 T:1969582080 DEBUG: OnKey: shift-alt-b (0x6f042) pressed, action is RunScript(plugin.program.hello.world, "alt-B", "apple")
11:52:13 T:1969582080 WARNING: RunScript called for a non-script addon 'plugin.program.hello.world'. This behaviour is deprecated.


It appears I can run either "RunScript" or "RunPlugin". Both seem to work, though the RunPlugin does not send the arguments in. Just sends "-1". Any guidance in which I should use?

Thanks in advance!


Re: Your First Add-On: Hello World! - nickr - 2015-06-07

For an addon to run all the time in the background it needs to be a 'service'.


RE: Your First Add-On: Hello World! - cayfordb - 2015-06-07

Thanks. Does the keymap.xml "runscript" stay the same? How does the code structure of the plugin itself have to change? Seems that just changing the example Hello World to a service would have the program exit as soon as the user hits the "OK". A different code structure would be needed to stay alive, in some kind of event loop.


RE: Your First Add-On: Hello World! - nickr - 2015-06-08

I suspect it wouldn't be very much like the Hello World example at all.

You perhaps need to cruise around the wiki documentation a bit, eg

http://kodi.wiki/view/Service_Add-ons


RE: Your First Add-On: Hello World! - cayfordb - 2015-06-08

I gathered that from the Sevice Addon wiki. If I do that, I need a hook from keymap.xml to send a message to the service when it sees a certain keystroke. Something that is not yet another script like hello world.

Is there something available from keymap.xml that can execute a library function, written in C?


RE: Your First Add-On: Hello World! - cayfordb - 2015-06-15

So, my script is working well now. The time to start up the script when I press a remote button is about half a second, so the response time is OK. I am getting this error though:

16:18:33 T:1969336320 WARNING: RunScript called for a non-script addon 'plugin.program.hello.world'. This behaviour is deprecated.
16:18:33 T:1572860992 NOTICE: Thread LanguageInvoker start, auto delete: false
16:18:34 T:1572860992 NOTICE: -->Python Interpreter Initialized<--

From the keymap.xml, I can run "RunScript" or "RunPlugin". I'm using RunScript, because RunPlugin does not pass parameters.

A keymap.xml entry:
<r mod="alt,shift">RunScript(plugin.program.hello.world, "alt-R", "tivo1 home", "jump", "tivo") </r>

As it is working fine, I could leave it alone and call it done. But next release of Kodi might break the plugin it if it is truly deprecated. So, I'm guessing I need to convert the PLUGIN to a SCRIPT. How do I do that?

Thanks!


RE: Your First Add-On: Hello World! - phil65 - 2015-06-15

RunPlugin also passes parameters, but perhaps your plugin does not read them correctly. Check out your sys.argv value.


RE: Your First Add-On: Hello World! - cayfordb - 2015-06-15

From RunPlugin I get "-1" in sys.arvg[1]. I see that both in the debug log from my code, but also from the plugin Kodi code saying "about to call the plugin with -1".

I'm thinking I need to recast the Plugin as a Script, changing the pathname, ID, and a few other items in addon.xml to make it all consistent. AND change keymap.xml to point to the new plugin in. Prolly need to do that anyway as I just hijacked "hello.world".


RE: Your First Add-On: Hello World! - cayfordb - 2015-06-15

Also, I'm just amazed at how well Kodi works. With this little plugin, and the flirc, I can drive Kodi with the Tivo remote, I can drive the Tivo itself with the same remote, I click any of the Apple TV remote buttons and the TV jumps to the Apple input, push any of the BlueRay buttons and the TV jumps to the BlueRay. Only one I can't intercept is the Amazon FireStick, which is BlueRay and pretty well hidden from view. So, I poke the Red Thumbs Down on the Tivo and the TV jumps to the FireTV. Sooo slick.


RE: Your First Add-On: Hello World! - weedking12 - 2015-06-16

hi too all im finding trouble making addon any help


RE: Your First Add-On: Hello World! - superdave201 - 2015-07-05

Hi, absolute beginner here.

Thanks for this tutorial! I have a few questions:

1: In the xml file where it says <provides>executable</provides> What should I put there so it shows under the videos menu in kodi? I tried replacing executable with video but got an error message.

2: How would I add a menu with categories followed by sub categories?

3: Is it possible to add a background to the add on in kodi?

Sorry if these questions are stupid but hey, the level I'm on at the moment in regards to kodi is Sesame street.

Thanks!


RE: Your First Add-On: Hello World! - M2SLAM - 2015-07-19

Hi all!

I'm trying to create a little on screen messaging app that throws up a dialog box like the stock Hello Work but I would like it to contain a couple of stock message like Hello World, Almost bedtime and Someones at the door but also a blank variable that can receive a string from over http.

I'm currently triggering the app over http with json-rpc command from an Advanced Rest Client extension in google chrome, this is just for testing, I'll submit the command from a html form in the end.
Here is the json code

{ "id": 1, "jsonrpc": "2.0", "method": "Addons.ExecuteAddon","params":{ "addonid":"plugin.program.its.time"} }

Here's a screenshot to explain that bit better

http://imageshack.com/a/img538/5865/pLYO4m.png

This triggers the Hello World app just fine but I have no idea how I would send extra paremeters over the http post and have the app act on them,
e.g. have it choose from message 1, 2, or 3 or inject the text from the http command.

Example script:

import xbmcaddon
import xbmcgui

addon = xbmcaddon.Addon()
addonname = addon.getAddonInfo('name')

msg1 = "Hello World!"
msg2 = "Almost time for bed."
msg3 = "someones at the door."
openmsg = ""

xbmcgui.Dialog().ok(addonname, msg1 or msg2 or msg3 or openmsg)

A messaging app may have been done before but I haven't found one yet.

Any help is appreciated by my extreme noobism.

Thank guys.


RE: Your First Add-On: Hello World! - phil65 - 2015-07-20

'{"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.yourscript", "params": { "param1": "value"}}}'

your add-on will have that param available via sys.argv then.


RE: Your First Add-On: Hello World! - zag - 2015-07-20

Very cool thing to do Smile

Great idea for a messaging add on!

Don't forget the dialog can only have 3 lines max though

Make sure you post the full code when it's complete


RE: Your First Add-On: Hello World! - royle - 2015-07-29

Hi, I'm new at developing for kodi and I stumbled upon an annoyance that I'm not able to fix myself, so please help. The quick version of my question is this: How do you compress an add-on so kodi doesn't complain about "incorrect strucure" on install?

The longer version of my problem is here -> I created my own add-on (audio/video plugin) but kodi won't let me install it via zip folder, telling me that the file has an incorrect structure even though I'm quite sure I did everything correct. If I extract the code to add-on folder, it works, kodi just doesn't like the zip... I also tried the Hello world sample and it only installs if i download the original zip file and feed it to kodi. As soon as I unzip/re-zip those same Hello world files, it breaks for some reason. I tried different programs (winzip, winrar, 7zip), operating systems (win 7, linux) and even all kinds of compression types (no/low/high compression) with no success. What am I missing here?