Assigning a Screen Saver to Kodi
The project is designed to create an
"Enchanting" screen saver with a minimal amount of source code in Python. The project is the simplest plugin for multimedia center Kodi.
The project shows how you can create a very beautiful screen saver based entirely on the work of the "OpenSource" community. The integration project is an example of writing two independent components, each of which takes about 80 lines of code. The first component is a content generator, shell script, the second component is a Kodi multimedia center plugin, which is responsible for displaying content.
And finally, if you are a programmer and use the Git version control system, you can visualize your work, write it to a video file and enjoy the result on a TV or computer screen, leaning back in your chair with a cup of coffee. And on cool autumn evenings, you can sleep soothingly under your screensaver, without forgetting to set the device off timer in Kodi.
Preamble
You can endlessly look at three things:
how fire burns, how water flows and how other people work.Since the plugin is written for the “Kodi Multimedia Center”, then I will visualize the work of the super team “Kodi Programmers”.
Using plugins in Kodi
The Kodi Multimedia Center is a very powerful and flexible program, working in conjunction with the ffmpeg external library, for decoding audio and video files.
To create a third-party application, Kodi uses the “addons” extension mechanism or simply plug-ins. To create my own plugin, I need some skills and a little knowledge of the Python programming language.
The Kodi plugin mechanism is extremely flexible and convenient. Python is an interpreted language, which means that I don’t need to compile anything, compile it into a separate software package, suffer with build files like “makefile”, etc.
For the final distribution of the Kodi plugin, just pack it in the Zip archive, observing some rules on the directory structure. Having the final Zip archive on hand, it can be installed on any device that Kodi runs on: a computer, tablet, and finally a TV (meaning a bunch of TV + single-plate), specifying the archive as a plug-in source.
Kodi plugin structure
└── screensaver.kodi.universe
├── README.md
├── addon.xml
├── changelog.txt
├── create.sh
├── fanart.jpg
├── icon.png
├── resources
│ ├── language
│ │ ├── English
│ │ │ └── strings.po
│ │ └── Russian
│ │ └── strings.po
│ ├── settings.xml
│ └── skins
│ └── default
│ ├── 720p
│ │ └── kodi-universe.xml
│ ├── 1080i
│ │ └── kodi-universe.xml
│ └── media
│ ├── black.jpg
│ ├── buran.jpg
│ └── kodi-universe.mkv
└── screensaver.py
- README.md - optional file, contains a description of the project for github.com
- addon.xml - a file with a description of the plugin; it contains the plugin type, encoding, version, dependencies, author name, etc.
- changelog.txt - an optional file with a list of project changes
- create.sh is an optional file, a bash script is designed to create a Zip archive screensaver (a) and generate a video file from Git history using the Gource tool, the file does not have a relation to the Kodi plugin, it is necessary for convenient distribution of the plugin. It is fully autonomous, i.e. having only this file, you can always create a complete Zip archive of the plugin (if you have an Internet connection).
- fanart.jpg - plugin background image
- icon.png - the main icon
- resources - directory with plugin resources
- screensaver.py - the main file of the plugin, contains all the source code of the plugin in Python, the file name can be anything, the main thing is that this name is written in the addon.xml file
Description of plugin resources
The resources directory contains the following files:
- language / English / strings.po - original plugin interface strings in English
- language / Russian / strings.po - translation into Russian, the file is included in the Kodi standard mechanism for translating content into the national languages of countries, the beginning of the file contains a standard text header of several lines (an example can be found on the kodi.wiki website, plugins section) , then there are line feeds consisting of three fields:
- msgctxt - link to a unique line number
- msgid - original text string identifier in English
- msgstr - translation of the msgid value into the national language, in this case, into Russian (Russian directory)
- settings.xml - the main file of the plugin settings, describes a graphical menu of plugin properties, the string parameters of which can be changed, where:
- id - text resource identifier
- label - a unique numeric label for the text field (corresponds to the msgctxt field in the strings.po file of translations)
- type - a predefined resource type (all possible types are described on the kodi.wiki website, plugins section)
- default - the default value of the parameter (you can reset the parameter to this value using the Kodi menu of the same name)
- resources / skins / default / 1080i / kodi-universe.xml - xml configuration file
- resources / skins / default / 720p / kodi-universe.xml - configuration xml file that describes the location of the plug-in controls (controls), their geometry, overall sizes, position of the elements, type of visibility, etc. The configuration name is determined depending on the mode of the video adapter (for example, 1080i or 720p)
contents of Russian / strings.po# Kodi Media Center language file # Addon Name: Screensaver Kodi Universe # Addon id: screensaver.kodi.universe # Addon Provider: berserktv msgid "" msgstr "" "Project-Id-Version: Kodi Addons\n" "Report-Msgid-Bugs-To: alanwww1@kodi.org\n" "POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Kodi Translation Team\n" "Language-Team: English \ (http://www.transifex.com/projects/p/xbmc-addons/language/en/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: en\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" msgctxt "#32001" msgid "Screensaver" msgstr " " msgctxt "#32002" msgid "Video file" msgstr "" msgctxt "#32003" msgid "Not Video" msgstr " "
contents of settings.xml <?xml version="1.0" encoding="utf-8" standalone="yes"?> <settings height="800"> <category label="32001"> <setting id="videofile" label="32002" type="video"/> <setting id="not-video" type="bool" \ label="32003" default="false"/> </category> </settings>
Media Resources Plugin:- resources / skins / default / media / black.jpg - black background that fills the screen before starting the video
- resources / skins / default / media / buran.jpg - futuristic image of the spaceship "Buran, on the wings of a Dream"
- resources / skins / default / media / kodi-universe.mkv - the main video file that is played cyclically by the plugin until the awakening event
Plugin root configuration file - addon.xml
Addon.xml - is the main configuration file for the plugin, from which Kodi takes all the necessary information to launch the plugin and integrate it into the multimedia center.
addon.xml content <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <addon id="screensaver.kodi.universe" name="Kodi Universe" \ version="0.1.2" provider-name="berserktv"> <requires> <import addon="xbmc.python" version="2.7"/> </requires> <extension point="xbmc.ui.screensaver" library="screensaver.py" /> <extension point="xbmc.addon.metadata"> <platform>all</platform> <source>https://github.com/berserktv/screensaver.kodi.universe </source> <summary lang="en">Kodi Universe</summary> <summary lang="ru"> </summary> <description lang="en">Screensaver - Kodi Universe </description> <description lang="ru"> - </description> <license>GNU GENERAL PUBLIC LICENSE. Version 2, June 1991</license> </extension> </addon>
The main parameters of the plugin are:
- Addon section
- id - unique text identifier of the plugin
- name - plugin name
- version - plugin version
- provider-name - name of the provider of the plugin
- Requires section - dependencies
in this section the modules on which the operation of this plug-in depends
- Extension section - extensions
in this section (there may be several), the type of the plugin is indicated,
main entry point to the plugin:
point = "xbmc.ui.screensaver" library = "screensaver.py"
in our case, the plugin is the “Screen Saver” to which it is transmitted
control by calling a python script called "screensaver.py"
point = “xbmc.addon.metadata” can also be specified in the extensions section
with the type of platform on which the plugin can work, the name and description of the plugin
in a particular language / languages, as well as the type of LICENSE plugin
The total amount of metadata that can be specified in this extension section can be
You can find enough large and more detailed information on the website
kodi.tv
Plugin implementation
Since the plugin should be extremely simple and straightforward, in its implementation I will limit myself to one main source file screensaver.py located in the root directory of screensaver (a)
In order for the python script to be called, I registered it in the addon.xml file, see the section above
The Python programming language is quite flexible, it allows you to perform the same action in several ways, and for clarity, I will use the object-oriented approach with classes.
class Screensaver (xbmcgui.WindowXMLDialog)
The main class of the screen saver
The Python Kodi API includes several core modules:
xbmc, xbmcgui, xbmcplugin, xbmcaddon, and xbmcvfs . To work with the Kodi GUI, I will use the xbmcgui module. This module contains classes responsible for different interface elements.
To create a plugin dialog box with its interface described in the xml configuration file, the
xbmcgui class is
used.WindowXMLDialogkodi-universe.xml content <?xml version="1.0" encoding="utf-8" standalone="yes"?> <window type="window"> <controls> <control type="image" id="1"> <description>Background image</description> <posx>0</posx> <posy>0</posy> <colordiffuse>FF555555</colordiffuse> <aspectratio scalediffuse="false" align="center" \ aligny="center">scale</aspectratio> <width>1920</width> <height>1080</height> <texture>buran.jpg</texture> </control> <control type="videowindow" id="2"> <description>VideoWindow</description> <posx>0</posx> <posy>0</posy> <width>1920</width> <height>1080</height> <visible>true</visible> </control> </controls> </window>
The configuration XML file describes two control elements:
The first one with identifier -
1 , is a background image - “Snowstorm, on the wings of a Dream”, of certain sizes, aligned to the center of the screen.
The second element with identifier -
2 , is a window for playing the Video, with a sign of visibility and certain geometric dimensions.
The Screensaver class inherits from the WindowXMLDialog class, and has three methods:
- The constructor __init__ method is called automatically when the object is created
- OnInit - graphical initialization method, called before the first window display
- The onAction method is an event processing method that is called when certain events occur, in this case, when an awakening event occurs, i.e. clicking the mouse button, keyboard, moving the mouse pointer or the arrival of any event from the control panel.
The Screensaver class uses two helper classes:
- Class BsPlayer - inherited from the standard XBMC video player class xbmc.Player , the class contains three methods:
- The constructor __init__ method is called automatically when the object is created
- Overriding the onPlayBackStarted video start method
- Overriding the onPlayBackStopped video end method
Note: since I redefined the method of stopping playback and it is empty,
then the rule will work: Don’t Stop Let's Go
- Class BsPlaylist - a list class designed to return an xbmc.PlayList object
the class contains two methods:
- The constructor __init__ method is called automatically when the object is created
- The getPlaylist method for defining a playlist using the standard XBMC list - xbmc.PlayList
The general algorithm of Screensaver (a) is as follows:
- When the Screensaver call event occurs (a) - the user’s inactivity for the specified number of minutes and the absence of active video / audio playback, Kodi transfers control to the screensaver.py script
- Based on the xml configuration file, the main graphic window of the plugin is created. When the graphical window is initialized, the string resources of the plugin settings are loaded (the menu is “settings”).
If the video file is not specified
__addon __. getSetting ("videofile")it is populated with a default parameter
video_url = def_video_url__addon __. setSetting ("videofile", video_url)if there is no flag - “disable video playback”
__addon __. getSetting ("not-video")the futuristic image “Snowstorm on the wings of the Dream” is shown for two seconds
xbmc.sleep (2000)further by the identifier of control 1, a black background image is set
self.getControl (1) .setImage ("black.jpg")and then the XBMC video player starts with a single-file playlist
self.player.play (self.vpl, windowed = True)The video file is played in a circle until the moment it comes
waking event i.e. any active user action
Creating visualizations for the Kodi plugin in Ubuntu
Note:
All the instructions described below I will run under the Linux operating system, namely the Ubuntu distributionIt is also possible to perform the following steps in a Debian compatible operating system - the main condition for launching will be the presence of the
Apt package manager in the system, i.e. a manager that allows you to install
Deb software in the system. Of course, you can perform the following steps on any Linux system, but this will require additional steps from you and possibly changing the sequence of some commands (as an example: installing RPM packages instead of Deb, etc.)
Gource is a very interesting and fascinating project.
Gource is named after source i.e. source code + G (Graphics). This application allows you to visualize the history of changes in the version control system. Gource natively understands Git, for other systems such as SVN, Mercurial there are converters that allow you to convert the storage base into Git Format.
Gource -
renders incredibly beautiful with OpenGL, and has a large number of parameters for its work. This incredibly powerful tool for generating "Enchanting" visualization I will use.
To create a visualization, I need some sequence of commands described in a
bash script
To generate the video, I need two main programs:
Gource - to create the source video file for the Git history of any specified project
FFmpeg - a library for encoding and decoding video and audio
Script to generate a plugin video file
The script should be run as a normal user, but during startup the script requires the installation of the following
git zip ffmpeg gource programsIf they are absent, the script will try to install them using the privilege escalation
command -
sudo .
In short, the script does the following:
Gource Options
- 01 --camera-mode track camera mode
(tracks current active users)
- 02 --stop-position 1.0 end position
(sets end position for playback, range from 0.0 to 1.0)
- 03 --seconds-per-day 1 number of days per second video
(the parameter determines how much work you will see in the interval of one second of the video)
- 04 --git-branch origin / master project work branch
- 05 --stop-at-end stop after git log is finished
- 06 --multi-sampling enable anti-aliasing
- 07 --hide-filenames remove file names
- 08 --highlight-users highlight user names
- 09 --file-idle-time 13 downtime for file
(the amount of time after which the file name is removed from the display)
- 10 --max-files 0 maximum number of files
(a value of 0 removes the limit on the number of displayed file names)
- 11 --hide date remove the date for which the current frame is displayed
- 12 - title Kodi the name that appears in the lower left corner of the video
- 13 --bloom-multiplier 1.0 control the effect of "light bloom" using the radius.
- 14 - bloom-intensity 1.0 control the effect of "light bloom" using intensity.
- 15 --output-framerate 30 output frames per second
- 16 --output-ppm-stream name the name of the output file in PPM format
note: some parameters may be mutually exclusive,
A complete list of parameters can be found
here .
Short video tutorial for Screensaver (a)
1) Download the project from github: git clone https://github.com/berserktv/screensaver.kodi.universe.git
2) Generate a video and create a Zip archive of the plugin: cd screensaver.kodi.universe chmod u+x create.sh ./create.sh
3) Video generation time and free disk space usage: . - 20 Gource (PPM) MKV FFmpeg. ( h.264) , Git XBMC (Kodi) 700 . PPM 10 ( FullHD, 30 ).
4) Install screensaver in Kodi "" Kodi ( ) Kodi - "" => " " => " Zip " , Kodi Universe Screensaver(), . Settings ( ) => " " => ""