•  Previous
  • 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 14
  • Next 
 
Thread Rating:
  • 5 Vote(s) - 4.2 Average
Your 1st Add-On: Hello World!
#46
As this is a beginners thread, I think it might be worthwhile explaining something that confused me when I first started; the difference between an Addon, Plugin, and Service.

Service:
This an addon that runs when Kodi first starts. It can be created with an infinite loop so that it stays active until it is disabled by the user, or Kodi shuts down. Generally a service operates without the users intervention, and uses automatic messages from Kodi as inputs. The Monitor and Player classes track these automatic messages for the system (library updates, etc) and media playing respectively.

Addon:
This is an ordinary script that is run by the user. It runs through once, but pauses at various points to allow user input. Unlike a service, it doesnt leave anything running. The script doesnt end until the user closes the Addon.

Plugin:
This is a special kind of Addon that runs through completely, from start to finish, whenever it is called. It does not pause to wait for user input. It can be called with various arguments that change its behaviour. For instance, if it is called without any arguments, eg my_plugin_script, if may load a list of video categories. Clicking on one of those categories will call the script again but with an argument that will load a certain sub-category, eg my_plugin_script category1. The plugin check the arguments and then displays different categories or plays a stream or file.

Module:
This is a special category of addon that provides libraries for other addons to use. These additional libraries are ones that are not found in the standard python library.
Reply
#47
(2014-12-20, 23:37)Roman_V_M Wrote: Yes, debugging addons using Kodi logs is difficult...

I think the best practice to employ when writing your script is to set up logging of variable values throughout your script. This will actually help with support later on. Avoid dumping too much into the log, as it can slow your script down and use up the users valuable storage space.

A simple logging function in each script works best I reckon:
Code:
import xbmc

def log(data, label=""):

    logging_message = '%s --- %s :   %s' % ("Your addon name", str(label), str(data))

    xbmc.log( msg=logging_message, level=xbmc.LOGDEBUG )

Lets say you have a list that you are transforming. You can check the value before and after the transform by logging the values:
Code:
log(important_list, "list before transform")
important_list = [x for x in important_list if x == y]
log(important_list, "list after transform")

Something I keep meaning to do but havent yet is to have one function for on-going logging (that is, logging that will be in place when the addon is released) and development logging (an example of which you see above). The idea is to have a log function and a dlog function, and then simply find/replace dlog with #dlog before final release.
Reply
#48
(2014-12-21, 03:39)Karnagious Wrote: Service:
This an addon that runs when Kodi first starts. It can be created with an infinite loop so that it stays active until it is disabled by the user, or Kodi shuts down. Generally a service operates without the users intervention, and uses automatic messages from Kodi as inputs. The Monitor and Player classes track these automatic messages for the system (library updates, etc) and media playing respectively.

See HOW-TO:Automatically_start_addons_using_services (wiki) for details of how to set up services. The page looks to be up to date (unlike many that are Kodi XBMC related) as it refers to the difference between Gotham and Helix when calling scripts.
Easy Home Automation to Control your RF device within Kodi XBMC
Want to watch TV everywhere you go? Pop by the Want To Watch TV site.
Image
Reply
#49
(2014-12-21, 03:52)Karnagious Wrote:
(2014-12-20, 23:37)Roman_V_M Wrote: Yes, debugging addons using Kodi logs is difficult...

I think the best practice to employ when writing your script is to set up logging of variable values throughout your script. This will actually help with support later on. Avoid dumping too much into the log, as it can slow your script down and use up the users valuable storage space.

A simple logging function in each script works best I reckon:
Code:
import xbmc

def log(data, label=""):

    logging_message = '%s --- %s :   %s' % ("Your addon name", str(label), str(data))

    xbmc.log( msg=logging_message, level=xbmc.LOGDEBUG )

Lets say you have a list that you are transforming. You can check the value before and after the transform by logging the values:
Code:
log(important_list, "list before transform")
important_list = [x for x in important_list if x == y]
log(important_list, "list after transform")

Something I keep meaning to do but havent yet is to have one function for on-going logging (that is, logging that will be in place when the addon is released) and development logging (an example of which you see above). The idea is to have a log function and a dlog function, and then simply find/replace dlog with #dlog before final release.

It's not that simple if your language is not English. Here's my version of logger which works with Russian/Ukrainian:
https://github.com/romanvm/ex.ua.alterna.../logger.py
Raspberry PI 2 + LibreELEC 8 (Kodi 17)
Samsung Galaxy Tab A 10.1 + Kodi 17 for Android
Reply
#50
I see this thread becoming a go-to for beginner coders in future. it'll make up the Wiki
Yeah, Me, Myself, and I, The Three Musketeers
Image
Reply
#51
how can I set 15 items per page? normally it does showing 10items per page which will be large and annoying.
Reply
#52
I'm a bit late to this party... Anyway here's my eariler minimal example "hello" plugin: https://github.com/viljoviitanen/plugin.minimal.example to which I got some good help from the forum: http://forum.kodi.tv/showthread.php?tid=173542

The thing with my example plugin, compared to the official hello world addon is that mine is a "plugin" and it shows the idea of the "virtual directory" which a plugin creates, and kodi displays. Also, it has minimal settings.

(And regarding licenses, my example plugin is "unlicenced" (close to public domain), not GPL so if you want to base your proprietary plugin on this, go right ahead..)
Reply
#53
Unlicensed actually means no one can copy it. We can only copy your work if you license us to.
If I have helped you or increased your knowledge, click the 'thank user' button to give thanks :) (People with less than 20 posts won't see the "Thank you" button.)
Reply
#54
(2014-12-28, 12:50)nickr Wrote: Unlicensed actually means no one can copy it. We can only copy your work if you license us to.

http://unlicense.org/
Reply
#55
Just a reminder to everyone to please remember to keep this thread on topic. If you are asking questions then please relate them to the "hello world" add-on.

Even better, post some code modified from the original post.
Reply
#56
(2014-12-28, 14:04)viljoviitanen Wrote:
(2014-12-28, 12:50)nickr Wrote: Unlicensed actually means no one can copy it. We can only copy your work if you license us to.

http://unlicense.org/

Ahh I see, interesting.
If I have helped you or increased your knowledge, click the 'thank user' button to give thanks :) (People with less than 20 posts won't see the "Thank you" button.)
Reply
#57
I created an Addon a little while back that will turn my NAS(a separate machine) on and off. How would one go about using variables in this to get the username and password from Settings?

os.system('ssh username@ipaddress "sudo shutdown -h now"')

Or more specifically, do I have to do anything special, because the variables are quoted inside parentheses, and part of a shell command?
Reply
#58
Love it, thanks! When I reviewed the add-on development sections of the wiki a while ago I got too overwhelmed to actually try anything. Now this actually makes it easy to get started and learn add-on development from the ground up Smile
Reply
#59
(2015-01-15, 18:03)Dalton63841 Wrote: I created an Addon a little while back that will turn my NAS(a separate machine) on and off. How would one go about using variables in this to get the username and password from Settings?

os.system('ssh username@ipaddress "sudo shutdown -h now"')

Or more specifically, do I have to do anything special, because the variables are quoted inside parentheses, and part of a shell command?

Please start a new thread, this question has nothing to do with Hello World tutorial.
Reply
#60
There is no "Hello World" add-on in the (Helix) repository as the wiki says and a search for "hello" gave no results either. I've found it at github but I was a bit confused.
Reply
  •  Previous
  • 1
  • 2
  • 3
  • 4(current)
  • 5
  • 6
  • 14
  • Next 



Your 1st Add-On: Hello World!4.25