User Tools

Site Tools


doc:appunti:software:kodi_addon

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:software:kodi_addon [2019/09/12 18:52] – [Localization] niccolodoc:appunti:software:kodi_addon [2023/05/26 17:05] (current) – [How to start an external program from Kodi] niccolo
Line 140: Line 140:
 ===== Localization ===== ===== Localization =====
  
-Localization of a Kodi add-on takes place in several parts. First of all we can localize the **Information** item of the Context Menu, by just adding the relevant part into the **addon.xml** file:+Localization of a Kodi add-on takes place in several files. First of all we can localize the **Information item** of the Context Menu, by just adding the relevant part into the **addon.xml** file:
  
 <code xml> <code xml>
Line 151: Line 151:
 </code> </code>
  
-Besides the **%%<summary>%%** tag, you can localize also **%%<description>%%**, etc. The supported **language codes** are the //alpha-2// ISO-639 codes (two letters), and they are listed into the [[https://kodi.wiki/view/List_of_language_codes_(ISO-639:1988)|ISO-639:1988]] Kodi Wiki page.+Besides the **%%<summary>%%** tag, you can localize also **%%<description>%%**, etc. The supported **language codes** are the **//alpha-2// ISO-639 codes** (two letters), and they are listed into the [[https://kodi.wiki/view/List_of_language_codes_(ISO-639:1988)|ISO-639:1988]] Kodi Wiki page.
  
-Then you will need to localize **text strings** used into **Python code** and into **XML files** (e.g. addon.xml, settings.xml, etc.). For each language you intend to support, you have to prepare a file:+Then you will need to localize **text strings** used into **Python code** and into **XML files** (e.g. //addon.xml////settings.xml//, etc.). For each language you intend to support, you have to prepare a file:
  
-  * **resources/language/resource.language.en_us/strings.po**+  * **resources/language/resource.language.en_gb/strings.po**
   * **resources/language/resource.language.it_it/strings.po**   * **resources/language/resource.language.it_it/strings.po**
  
-**NOTICE**: Kodi documentation says to use here the **//alpha-4// ISO-639 codes** (four letters) as directory name suffix. FIXME It is not clear if we can use the simple two letters code.+**NOTICE**: Kodi documentation says to use here the **//alpha-4// ISO-639 codes** (four letters) as directory name suffix.
  
 Every file begins with a preamble: Every file begins with a preamble:
Line 198: Line 198:
 </file> </file>
  
-Notice that **msgid** is the original, untranslated English text. The **msgstr** is the localized version and **msgctxt** is an unique ID for that string.+Notice that **msgid** is the original, untranslated English text. The **msgstr** is the localized version and **msgctxt** is an unique ID for each string.
  
-The **english version will be used by default** (FIXME It is not clear what versionif **en_gb** or **en_us**) if a localization is missing, so the file will contains only the original text:+If a localization is missing, the **british english version will be used by default**, so the file for the **en_gb** regional must exists. That file contains only the original text, not the translation:
  
 <file> <file>
Line 218: Line 218:
 Beware of this: Beware of this:
  
-  * According to the page **[[https://kodi.wiki/view/Language_support#String_ID_range|Language_support]]**, in scripts we should use the range **32000** thru **32999** for string IDs. +  * If you **update a .po file** you have to **restart Kodi** to re-read it, restarting the add-on is not sufficient. 
-  * If a string contains a **double quote**, it must be escaped with a **backslash**. +  * For **scripts add-ons**, according to the page **[[https://kodi.wiki/view/Language_support#String_ID_range|Language support]]**,  we should use the range **32000** thru **32999** for string IDs. 
-  * FIXME If a string contains a newline? See [[https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html|PO-Files]].+  * If a string contains a **double quote**, it must be escaped with a **backslash**. Notice that //C syntax// is applied, so backslash is used as the escape character
 +  * For better reading **string can be split over several lines**. Just close the string with double quote and start a new line with a double quote too. No newline characters will be added automatically, you have to include the sequence **%%\n%%** explicitly. 
 +  * For more info see **[[https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html|PO-Files]]**.
  
 Finally we have to change the **Python code**, substituting the strings with a function call and the string ID: Finally we have to change the **Python code**, substituting the strings with a function call and the string ID:
Line 259: Line 261:
 </addon> </addon>
 </code> </code>
 +
 +===== Change Regional Settings =====
 +
 +Regional default for Kodi is **English**, which means **British English** (en_gb). Other English variants are labeled e.g. **English (US)**, which requires the **resource.language.en_us** add-on.
 +
 +When you **change regional settings** in Kodi (Settings => ...) - if the choosen set is not already installed - the system tries to download the appropriate archive. In our test case (**Kodi 17.6** on the **Raspberry Pi**, Debian Stretch 9.3) the download URL is something like this:
 +
 +<code>
 +http://mirrors.kodi.tv/addons/krypton/resource.language.en_us/resource.language.fr_fr-3.0.6.zip.md5
 +</code>
 +
 +Unfortunately the above md5 file does not exists, so the installation of the requested resource fails. You have to download the zip file manually and follow the procedure to install an add-on from a zip file. The installation will create the directory **/home/kodi/.kodi/addons/resource.language.fr_fr/**.
 +
 +===== Cannot execute a graphical external program =====
 +
 +After many hours of trying and failing, it turned out that **it is not possibile to start an external program** from Kodi and use the **graphic display**; at least it is not possible if Kodi is **running without a full windowing system** (e.g. X11).
 +
 +When Kodi is installed on the **Raspberry Pi** using the **RaspiOS** operating system (based on Debian GNU/Linux 11 Bullseye), the program is started by the binary program **%%kodi.bin%%** using the argument **%%--standalone%%**.
 +
 +**kodi-standalone** on the Raspberry Pi uses the GBM (Generic Buffer Management) windowing system to draw its graphics via the Mesa (an open source implementation of the OpenGL API). Other platforms supported by kodi-standalone are X11 and Wayland. You can see the following line into the **kodi.log**:
 +
 +<code>
 +INFO <general>: CApplication::CreateGUI - using the gbm windowing system
 +</code>
 +
 +GBM/KMS only supports one "DRM master". Other applications can only use the screen when going through this master. Kodi is launched through a wrapper that uses chvt to switch X away from being the DRM master and allow kodi to become it. Without kodi supporting relinquishing being the master when launching the app and reacquiring it afterwards then launching another gui app isn't possible.
 +
 +You can verify if it is possibile to lanuch a simple graphical program like **kmscube** (from the homonymous Debian package). Just execute the command:
 +
 +<code bash>
 +# /dev/dri/card0 is /dev/dri/by-path/platform-soc:gpu-card
 +kmscube -D /dev/dri/card0
 +</code>
 +
 +If Kodi is not running the kmscube runs nicely, but if Kodi is running (you can launch the program using ''xbmc.executescript()'' as explained below), you will get the following error:
 +
 +<code>
 +failed to set mode: Permission denied
 +</code>
 +
 +If you use ''strace'' to debug the error, you can see that the problem is with the ''/dev/dri/by-path/platform-soc:gpu-card'' device:
 +
 +<code>
 +ioctl(3, DRM_IOCTL_MODE_SETCRTC, 0x7e9e17f8) = -1 EACCES (Permission denied)
 +</code>
 +
 +==== How to start an external program from Kodi ====
 +
 +I tried (but failed) to start a Python graphical program from Kodi. Because there is not an X11 windowing system, I tried **Pygame** with the drivers **directfb**, **fbcon** or **svgalib**. No problem if Kodi is stopped, Permission denied on the display if Kodi is running. Using the Python3 OpenGL module I was able to create a graphical program only under the X11 environment (using the ''DISPLAY'' environment variable).
 +
 +To execute an external program from my add-on video plugin, I used the following two methods. The first one just starts an external Python script when the code is executed:
 +     
 +<code python>
 +# This works only for a Python script.
 +# Notice "special://home" is "/home/kodi/.kodi" on the Raspberry Pi.
 +xbmc.executescript('special://home/bin/run-script.py')
 +</code>
 +
 +This second method will add a context menu item to the add-on ''ListItem'', which will launch the external program when selected:
 +
 +<code python>
 +# Add a context menu item to the add-on xbmcgui.ListItem object.
 +# This works only for a Python script.
 +li.addContextMenuItems([('Photo Reframe', 'RunScript(special://home/bin/run-script.py,arg1)')])
 +</code>
 +
 +A third method should be the following, but I did not tried it:
 +
 +<code python>
 +xbmc.executebuiltin('XBMC.RunScript(special://home/bin/run-script.py)')
 +</code>
 +
 +Other non-tested code to execute plugins or scripts:
 +
 +<code python>
 +xbmc.executebuiltin('RunPlugin(plugin://plugin.video.youtube/?addon_id=plugin.video.example)')
 +xbmc.executebuiltin('RunPlugin("plugin.video.something")')
 +xbmc.executebuiltin('RunAddon("script.something")')
 +</code>
 +
 +  * **[[https://github.com/graysky2/kodi-standalone-service/blob/master/README.md|kodi-standalone-service]]**
 +  * **[[https://en.wikipedia.org/wiki/Mesa_(computer_graphics)|Mesa]]**
 +  * **[[https://en.wikipedia.org/wiki/OpenGL|OpenGL]]**
 +  * **[[https://forum.kodi.tv/showthread.php?tid=354687|Can RasPi Kodi use VLC for its player]]**
 +  * **[[https://kodi.wiki/view/External_players|Kodi External players]]**
 +  * **[[https://kodi.wiki/view/Settings/System/Display|Kodi: Settings, System, Display]]**
 +  * **[[https://stackoverflow.com/questions/54452592/how-to-start-another-addon-from-a-kodi-addon|How to start another addon from a kodi addon]]**
 +  * **[[https://stackoverflow.com/questions/46083182/kodi-python-how-to-call-another-addon-and-if-not-installed-but-present-in-rep|Kodi python - how to call another addon and, if not installed but present in repo, ask to install it]]**
  
 ===== Web References ===== ===== Web References =====
doc/appunti/software/kodi_addon.1568307165.txt.gz · Last modified: 2019/09/12 18:52 by niccolo