Changes to the python API for Kodi Leia

  Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #1
Below you'll find an up-to-date list of all changes made to the python API since the release of Kodi Krypton.



Please keep this thread clean. It should be an easy overview for python coders who are updating their addon for Kodi Krypton.
For discussions / feature requests / bugreports, please find (or create) the appropriate thread in the addon development forum.

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
(This post was last modified: 2017-01-09 06:36 by ronie.)
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #2
2017-01-04 DBID for music items

addons can now set & get the dbid for music items

Code:
listitem.setInfo('music', {'mediatype':'song', 'dbid':12345})

dbid = listitem.getMusicInfoTag().getDbId()



pull request: https://github.com/xbmc/xbmc/pull/10858

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #3
2017-01-04 WindowXML setContent

addons using WindowXML that are creating a media list using the built-in container,
can now set the content of the container:

Code:
self.setContent('movies')



pull request: https://github.com/xbmc/xbmc/pull/11258

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
(This post was last modified: 2017-02-26 14:40 by ronie.)
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #4
2017-01-05 mediatype for music items

addons can now get the mediatype for music items

Code:
mediatype = listitem.getMusicInfoTag().getMediaType()



pull request: https://github.com/xbmc/xbmc/pull/11110

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #5
2017-01-05 int/float support for slider controls

addons can now define a float or int range (instead if just a fixed 0-100%) range for slider controls

Code:
self.slider.setFloat(15.0, 10.0, 1.0, 20.0)
self.slider.getFloat()

self.slider.setInt(450, 200, 10, 900)
self.slider.getInt()

the params are: current value, min value, step size, max value


pull request: https://github.com/xbmc/xbmc/pull/11230

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
(This post was last modified: 2017-01-05 12:16 by ronie.)
find quote
gedisony Offline
Senior Member
Posts: 225
Joined: Mar 2015
Reputation: 13
Post: #6
(2017-01-04 22:55)ronie Wrote:  2017-01-04 WindowsXML setContent
addons using WindowsXML that are creating a media list using the built-in container,
can now set the content of the container:
Code:
self.setContent('movies')
pull request: https://github.com/xbmc/xbmc/pull/11258

I'm just curious,

setContent() lets the skin know how to list the directory items, what view types will be available and which infolabels to display.

Using windowsXML bypasses the skin system and can use setProperty/getProperty to pass values. Why use setContent() ?
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #7
it's only useful if you use the built-in container of the window, which 99.999999999% of the addons don't use ;-)

pretty much all addons define a container and add listitems to it:
Code:
self.getControl(1234).addItems(listitems)

but you can also add the listitems directly to the window:
Code:
self.addItems(listitems)

if you use that method, you can define multiple view types in the skin xml file of your addon,
and define which views (or other controls) are visible based on the content type.

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #8
2017-03-05 kodi language file changes

not a python related change, but it can potentially affect your addon..

as of PR#11039 the kodi language file no longer uses '%s' / '%i' string formatting.
in case your addon is using any of the affected strings from the kodi language file, please be aware this will no longer work:
Code:
xbmc.getLocalizedString(20464) % foo
xbmc.getLocalizedString(299) % count


pull request: https://github.com/xbmc/xbmc/pull/11039

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
find quote
Protocol-X Offline
Senior Member
Posts: 180
Joined: Aug 2016
Reputation: 4
Post: #9
(2017-03-08 18:57)ronie Wrote:  2017-03-05 kodi language file changes

not a python related change, but it can potentially affect your addon..

as of PR#11039 the kodi language file no longer uses '%s' / '%i' string formatting.
in case your addon is using any of the affected strings from the kodi language file, please be aware this will no longer work:
Code:
xbmc.getLocalizedString(20464) % foo
xbmc.getLocalizedString(299) % count


pull request: https://github.com/xbmc/xbmc/pull/11039

Ronie,

Is there an alternative? Removing the ability to have formatted strings in the language kind of goes against the developer rules about having to store text in a string file instead of hard coding it in a py file.
find quote
Roman_V_M Online
Team-Kodi Member
Posts: 1,116
Joined: Jun 2011
Reputation: 55
Location: Kyiv, Ukraine
Post: #10
(2017-03-09 03:50)Protocol-X Wrote:  [quote='ronie' pid='2544100' dateline='1488992258']
2017-03-05 kodi language file changes

not a python related change, but it can potentially affect your addon..

Ronie,

Is there an alternative? Removing the ability to have formatted strings in the language kind of goes against the developer rules about having to store text in a string file instead of hard coding it in a py file.

Ha, it got you too. Smile Read the post carefully, it concerns only re-using strings from the main language file that now will have different formatting.

Raspberry PI 2 + LibreELEC 8 (Kodi 17)
Samsung Galaxy Tab A 10.1 + Kodi 17 for Android
find quote
Protocol-X Offline
Senior Member
Posts: 180
Joined: Aug 2016
Reputation: 4
Post: #11
Doh !
find quote
ronie Offline
Team-Kodi Member
Posts: 13,167
Joined: Jan 2009
Reputation: 392
Post: #12
2017-03-17 WindowXML isMedia

addons using WindowXML that are creating a media list using the built-in container,
need to set the isMedia bool to True in the window constructor:

Code:
win = xbmcgui.WindowXML('script-globalsearch.xml', xbmcaddon.Addon().getAddonInfo('path').decode('utf-8'), 'default', '1080p', True)

this will allow you to reference the container in the skin xml without specifying the container id.

pull request: https://github.com/xbmc/xbmc/pull/11766

Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ and Search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
find quote
gedisony Offline
Senior Member
Posts: 225
Joined: Mar 2015
Reputation: 13
Post: #13
(2017-03-08 18:57)ronie Wrote:  2017-03-05 kodi language file changes

not a python related change, but it can potentially affect your addon..

as of PR#11039 the kodi language file no longer uses '%s' / '%i' string formatting.
in case your addon is using any of the affected strings from the kodi language file, please be aware this will no longer work:
Code:
xbmc.getLocalizedString(20464) % foo
xbmc.getLocalizedString(299) % count


pull request: https://github.com/xbmc/xbmc/pull/11039
should we convert to using .format()
or just construct the phrases by connecting them as words?
e.g.: xbmc.getLocalizedString(298)+' '+somethingvariable+' '+xbmc.getLocalizedString(299)
find quote