Archive:HOW-TO:Write plugins for XBMC

From Official Kodi Wiki
Revision as of 17:46, 3 January 2009 by >Voinage
Jump to navigation Jump to search

XBMC features a Python Engine and XBMC GUI interface have built-in 'Add-on' support for displaying content listings that present to that GUI interface.

Plugins, unlike scripts, do not really provide new functionality to XBMC, instead what they do do is provide an easy way to present content listings in XBMC through the native GUI interface. Content is usually online sources like Internet audio and video streams, (like Internet TV-channels, and radio-station, or Podcasts), or pictures from websites which as Flickr and Picasa Web.

Please feel free to add more samples of simple plugin functions with comments that you know or figure out while you are learning to write or edit plugins for XBMC. Adding anything at all no matter how basic, if its not already here add it! someone will more then likely benefit from it. The more difficult your snippet please heavily comment it with "#" don't be stingy on the comments you can never have too much information, what's simple to you may make no sense at all to someone else, also URLs that were helpful to what you were doing would be great to add to your snippet or to the bookmark section (python sites, chat rooms, etc).

This a placeholder that so far is just a copy of the beginning of HOW-TO write Python Scripts.

For end-user intruction on how to install plugins for XBMC please see HOW-TO install and use plugins in XBMC.

Note! As most plugins work by scraping a website they often stop working (partially or completely) when changes (redesign) are made to the website by the website owner. So if a third-party plugin do not work know that it is not usually do to a problem with XBMC but rather the website it scrapes have had changes done to it, meaning someone will have to manually edit the plugin code to account for the new changes, then you will have to get that updated version of the plugin.

Writing plugins in python for XBMC

Introduction.

Hello, I`m Voinage - Team XBMC Python Coder & Plugin Nutcase.

Python Plugin coding can be frustrating, but VERY rewarding. Imagine watching that episode of your favourite Tv show on your Tv, instead of on your laptop lcd or monitor - thinking about it ?

Good, let`s get started.

You will need :-

Yourself , Concentration , Determination.


Selecting a target, sounds easy.

I`ll just pick what I like, great.

Don`t release it, enjoy it yourself.

Just because you like Tropical fish videos doesn`t mean the Community will.


Also, search the XBMC forum for the name of the Plugin you are planning on creating. It may already exist. Don`t duplicate, what`s the point. You spend hours on a plugin only to find that one already exists and just needs fixing.

Have you checked the Threads & searched the Forum ?

Remember the 3 C`s :- Consider, Community, Content.

Install Python and find where you put the source code that came with this tutorial.

Right click on : - Default.py and select --> Edit with Idle.

Don`t be afraid, this is the fun part. Honestly, it is.

Plugin template : Breakdown.

This is just to familiarise yourself with the layout of the plugin template. It`s not in depth – we will delve deeper later.

Remember – it`s all about the Tabs.

Python is just like you and I, it has the ability to use information from other sources. If you don`t know anything about Python – you can read a book from a library and gain the knowledge. Therefore it`s the same with a Python & it`s libraries. A Python Library is a collection of useful functions that the main program can call upon and read then use the new knowledge in the main program.

To use them we need to import them, you will only use 5 at maximum for basic plugin creation.

import urllib,urllib2,re,xbmcplugin,xbmcgui

  • urllib – a collection of http routines.
  • urllib2 – a more advanced collection of http routines.
  • re – a collection of string manipulation routines.
  • xbmcplugin – specific Xbmc routines.
  • xbmcgui – specific Xbmc routines.

Without the above imports, python has no reference and the plugin will error and fail.

The next thing you will see is the (CATEGORIES () : ) function. This handy little function takes the stress out of XBMC Directory listing. It`s really the addDir() that lists & adds - but we are not in depth - YET.

def CATEGORIES():

       addDir("","",1,"")
       addDir( "","",1,"")
       addDir( "","",1,"")
       addDir("","",1,"")