How to write my own python codes?
#1
Hi every body,

I am new in Kodi... I wanna learn it and use it for my own streaming project. I've started since while ago. I learned the requiered basics of python, and also I had a look on all classes and methods provided by different modules in this link:

http://romanvm.github.io/xbmcstubs/docs/

However, I am really confused and don't know how to implement all thses information in my mind from this forum, wiki and other websites. I wish I could learn working and developing Kodi using Python step by step, but I didn't find any good reference to do it. I just gathered some sparsed inforamtion Smile

Now, I wonder if any body can guide me how to learn developing Kodi. Would you mind introducing me any good reference?

I need some example codes to do the following tasks:

At first creating an addon file to show some movies. I know that it needs an XML file besides python file, and I think I have learned making XML file. However, in the python code, how I can add a list of movies in such a way by clicking on each of them, after showing the metadata information, I can play it?

Any help, tips or suggestion is appreciated... Smile

Sincerely,
Zeinab
Reply
#2
http://kodi.wiki/view/Add-on_development
Reply
#3
(2015-09-20, 11:04)curti Wrote: http://kodi.wiki/view/Add-on_development


Dear Friend,

Thanks for your help. Actually, I have read almost all the pages in this link. But, I can not still run my own code to show a movie! Any other tips?

Sincerely,
Zeinab
Reply
#4
here's a simple 'hello world' example of a video plugin:
Audio/video_add-on_tutorial (wiki)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
(2015-09-20, 11:51)ronie Wrote: here's a simple 'hello world' example of a video plugin:
Audio/video_add-on_tutorial (wiki)

Dear friend,

Thanks for your help again. I had read this file before, and tried to run it. So, I made an addon and copied this code in the python file:

Code:
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin

base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, 'movies')

def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

mode = args.get('mode', None)

if mode is None:
    url = build_url({'mode': 'folder', 'foldername': 'Folder One'})
    li = xbmcgui.ListItem('Folder One', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    url = build_url({'mode': 'folder', 'foldername': 'Folder Two'})
    li = xbmcgui.ListItem('Folder Two', iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url,
                                listitem=li, isFolder=True)

    xbmcplugin.endOfDirectory(addon_handle)

elif mode[0] == 'folder':
    foldername = args['foldername'][0]
    url = 'http://localhost/some_video.mkv'
    li = xbmcgui.ListItem(foldername + ' Video', iconImage='DefaultVideo.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li)
    xbmcplugin.endOfDirectory(addon_handle)

Pycharm gave me some errors with these two line:
Code:
args = urlparse.parse_qs(sys.argv[2][1:])
  return base_url + '?' + urllib.urlencode(query)

So, with help of python site, I changed these two lines as below:
Code:
args = urllib.parse.parse_qs(sys.argv[2][1:])
  return base_url + '?' + urllib.parse.urlencode(query)

Then I created the zip file, installed it on kodi. It was installed successfully, but when I wanted to run it. It didn't worked. A message was shown that it is not working and for more information check the log. At first, I don't know where is this log file, how can I check it? And what is wrong with this copied code?

I use Kodi ver 15.

Thanks for your help.

Sincerely,
Zeinab
Reply
#6
enable debug loggin in xbmc, run your plugin and check the logfile for errors.
see: Debug Log
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#7
(2015-09-20, 14:00)ronie Wrote: enable debug loggin in xbmc, run your plugin and check the logfile for errors.
see: Debug Log


Dear friend,

Many thanks for your help. I could generate the log file, here is the link:

http://xbmclogs.com/pxdfhvubi


Wowww, when I look at it with too much lines, I see some errors, but I don't know what is the problem and how can I solve it. I wonder if you would guide me to understand the origin of the errors and solve them?

Sincerely,
Zeinab
Reply
#8
Here I copied the XML file to see if there is problem in it.

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.test1" name="Video_addon_test1" version="1.0.0" provider-name="Zeinab Jafari">
    <requires>
        <import addon="xbmc.python" version="2.14.0"/>
    </requires>
    <extension point="xbmc.python.pluginsource" library="addon.py">
        <provides>executable</provides>
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary lang="en">Providing a list of movie and clip items</summary>
        <description lang="en">Example Plugin to practicing list of movies and videos</description>
        <license>GNU General Public License, v2</license>
        <language></language>
        <forum></forum>
        <source></source>
        <email>[email protected]</email>
    </extension>
</addon>

Thanks for dedication of your time.

Sincerely,
Zeinab
Reply
#9
(2015-09-20, 13:54)Zeinab Jafari Wrote: So, with help of python site, I changed these two lines as below:
Code:
args = urllib.parse.parse_qs(sys.argv[2][1:])
  return base_url + '?' + urllib.parse.urlencode(query)

that's not correct. urllib.parse is only valid in python3.
kodi uses python 2.x
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#10
(2015-09-21, 12:33)ronie Wrote:
(2015-09-20, 13:54)Zeinab Jafari Wrote: So, with help of python site, I changed these two lines as below:
Code:
args = urllib.parse.parse_qs(sys.argv[2][1:])
  return base_url + '?' + urllib.parse.urlencode(query)

that's not correct. urllib.parse is only valid in python3.
kodi uses python 2.x


Dear friend,

Thanks for your help. I changed the code to the original one that I copied from wiki. I mean I replaced urlib.parse.parse_qs with urllib.parse_qs. However, again I recieved the same errors:

http://xbmclogs.com/pc9zzga1k

I am really confused with this simple code! Smile Any help or tips would be really appreciated.

Sincerely,
Zeinab
Reply
#11
Dear friends,

Just one of errors is related to parse_qs. It mentions that the object has no attribute parse_qs (urlib.parse_qs). I checked python documentation for version 2.2 (as I imported this one in my XML file). I could not find parse_qs in urllib class! it seems that one of problems is this one. There are some other errors in log file that I couldn't figure them out!

Thanks again,
Zeinab
Reply
#12
no idea, your code runs fine on my end (tested on linux).

urlparse.parse_qs was added in python 2.6 and that's what kodi uses.
https://docs.python.org/2/library/urlpar...e.parse_qs
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#13
(2015-09-21, 14:57)ronie Wrote: no idea, your code runs fine on my end (tested on linux).

urlparse.parse_qs was added in python 2.6 and that's what kodi uses.
https://docs.python.org/2/library/urlpar...e.parse_qs

Thank you dear friend,

Now, I am almost sure that urllib.parse_qs is the problem. when ?I deleted this line it worked very well, without any error. I am really confused, and I do not know how to solve it.

Any other ideas my friends? Any help would be appreciated.

Sincerely,
Zeinab
Reply

Logout Mark Read Team Forum Stats Members Help
How to write my own python codes?0