HOW-TO:Video addon
![]() |
![]() |
![]() |
![]() |
![]() |
Introduction
This tutorial will explain how to write your first Kodi/XBMC video plugin Add-on
Tools
Assuming you have already followed the Hello World Add-on you will have a text editor already setup. Since we are dealing with videos this time its probably a good idea to have a video player setup. We recommend another great open source project for this
- VLC http://www.videolan.org/vlc/
Installing
You can find the Add-on source code here:
https://github.com/romanvm/plugin.video.example
You need to download an installable zip from "Releases" section of the repo and install it from the Addons section of kodi GUI by clicking a "package" icon in the top left corner and selecting "Instal from ZIP".
Note that Kodi no longer supports "drop in" installing by copying addon files into addon sub-directory of the Kodi profile directory.
Testing
You can first give the add-on a test run by going to: System >> Add-Ons >> Enabled Add-Ons >> Video Add-Ons >> Example Kodi video Plugin. You should now be able to watch some test videos hosted from an internet web server.
Explanation
So whats happening in this add-on?
Basically the Add-on is checking a website for the hosted videos. In this example we are directly linking to the videos, but there are possibilities for dynamic content and scraping of just about any online source
Once the video link is sent to Kodi, our video player takes over and buffers, then plays the video just like any other media.
Structure
main.py <-- This is the actual python code for your Add-On
addon.xml <-- This is the Add-Ons metadata
icon.png <-- A PNG icon for the add-on. It can be 256x256 or 512x512 pixels big. Try to make it look nice!
Readme.md <-- The readme text file with a description of the Add-on and install instructions. This shows on the front of the GitHub page and helps users to understand your Add-on before downloading.
The Code
So now we come to the actual Add-On code, this is where most of your Add-on is written and is a simple text file containing python code.
Since this is a very simple Add-On, all its code are located in https://github.com/romanvm/plugin.video.example/blob/master/main.py file that is the Add-On entry point. Read the comments in the file that explain what each part of the code does.
More complex Add-Ons may include additional modules and packages. In this case a good practice is to put only minimal code in your Add-On entrypoint and keep the rest of the code in importable modueles.
Changing the code
Hopefully by now you have managed to run the Add-On, understand the structure and can see what the code can do. Now lets trying changing it a little!
Since we already have the Add-on installed we can go directly to the Kodi userdata folder and edit the python directly. You can also have Kodi open at this time ready to run the Add-on when required. Just switch between your text editor and Kodi any time.
Note that all the data for video strams are located in movies.json file. This allows to separate media information from the actual Python code.
Try changing some of the links to another jpeg file or hosted online video. Also try to change the genre and see how that effects the view in Kodi.
Click save on your text editor and now try running the Add-On inside Kodi. You should see the new video links and navigation right away.
Congratulations! you've just played an online video from your very own Video Add-on
Streaming Video
In addition to this guide, here are some comments from an experienced developer who has worked with streaming video sites:
The docs will help you a lot, way more than any wiki.
https://xbmc.github.io/docs.kodi.tv/master/kodi-base/index.html
Speaking of docs, the ListItem reference will be most useful, time and time again.
https://xbmc.github.io/docs.kodi.tv/master/kodi-base/d8/d29/group__python__xbmcgui__listitem.html
Since you're relying on a streaming platform you won't need to do anything particular yourself, you can get away with fetching the data and posting an item with the URL of the video. InputStream.Adaptive configuration might be needed, especially if the videos need DRM.
You can get a lot done with the requests module, depending on the data you're processing. It's fully supported in Kodi, cookie and sessions included. In short, it's really simple, you:
- get the information you need off the internet (title/URL could suffice for a start);
- you generate items that Kodi will treat as video sources (see xbmcplugin.addDirectoryItem() and xbmcgui.ListItem());
You could also read the sources of plugins such as AsciiDisco's Netflix or Sandmann79's Amazon/AmazonVOD addons.
You can read more in this thread https://forum.kodi.tv/showthread.php?tid=348328
Final Thoughts
Writing a Video Add-on is actually pretty simple once you get the basic structure correct. You can scrape most online sources with Regex, or host your own videos on the web. You can also play youtube clips or vevo videos using some additional easy to use modules.
If you have any questions about this tutorial, feel free to discuss it on our forums here: http://forum.kodi.tv/showthread.php?tid=248774
Extra info
Just a reminder... IMPORTANT!!!!!!! Do not mix tabs and spaces in python