A better plugin creation tutorial - Step 1

Eldorado

Moderator
Staff member
May 7, 2012
990
0
0
what the hell, this info would of helped alot in the beginning

did not know i can do this saved an extra line
Code:
for url,thumb,name in re.findall('<a rel="nofollow" class="teaser group" href="(.+?)"><div class=".+?"><img id=".+?" class="fit_img" src="(.+?)" alt="(.+?)">',link):
        print name

i did this so far, and i know jason was trying to tell me there is a faster way but did not understand
Code:
r = re.compile('<a rel="nofollow" class="teaser group" href="(.+?)"><div class=".+?"><img id=".+?" class="fit_img" src="(.+?)" alt="(.+?)">').findall(link)
for url,thumb,name in r:
        print name
With python you can get things really short.. BUT.. IMO it's not always good practice

Some will say by doing so you are just making your code more complex for no reason, makes it tougher for the next guy to understand it.. I don't think you will see any gains by doing stuff like this
 

jas0npc

Banned
May 5, 2012
2,449
0
0
UK
Nice

Code:
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
 

the-one

Banned
May 7, 2013
189
0
0
New Jersey, USA
Whats the update on this???

I would also like to add some tips and stuff to the tutorials website as well.

I have noticed some of the plugins not using t0mm0's Addon class to its full potential.

Utilizing t0mm0's Addon class:
Code:
from t0mm0.common.addon import Addon
addon = Addon('plugin.video.myaddon', sys.argv)
For e.g.:

Code:
#
# Instead of doing this:
#
def get_params():
        param=[]
        paramstring=sys.argv[2]
        if len(paramstring)>=2:
            params=sys.argv[2]
            cleanedparams=params.replace('?','')
            if (params[len(params)-1]=='/'):
                    params=params[0:len(params)-2]
            pairsofparams=cleanedparams.split('&')
            param={}
            for i in range(len(pairsofparams)):
                    splitparams={}
                    splitparams=pairsofparams[i].split('=')
                    if (len(splitparams))==2:
                            param[splitparams[0]]=splitparams[1]
        return param
params=get_params()
mode=''
try:
        mode=int(params["mode"])
except:
        pass

#
# You can do this
#
mode = int(addon.queries.get('mode', ''))

### So you got rid of the get_params function and the try catch block to get value of mode with one line.

And Also:
Code:
#
# Instead of doing this:
#
liz=xbmcgui.ListItem(label = name,iconImage="",thumbnailImage = image)
liz.setProperty('fanart_image', os.path.join(art,'xbmcback.png'))
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=sys.argv[0]+"?url=%s&mode=%s&name=%s"%(url,mode,name),isFolder=False,listitem=liz)


#
# You could do this
#
addon.add_directory({'mode': mode, 'url': url, 'name' : name}, {'title' : name }, img=image, fanart=os.path.join(art,'xbmcback.png'))


### Three lines of code used to add an item get replaced with one line.

TIP: Utilize t0mm0's Addon class to its full potential :)
 

the-one

Banned
May 7, 2013
189
0
0
New Jersey, USA
On my addons i'm trying use less t0mm0s and others modules. You'll get a faster addon. Trust me.
I dont agree. t0mm0's code is doing the same thing that you would directly write in your addon to add a directory (or do any other stuff). I am not sure how one extra function call or a couple of extra checks is going to slow it down. Kindly elaborate.
 

rw86

New member
Aug 19, 2013
131
0
0
Did anything ever come of this tutorial? I'm guessing not?

Does anyone know of any good video plugin tutorials? I'd love to get to grips with making plugins, but I'm more of a 'hands-on' type of learner, where I need to be doing it to learn, rather than just reading. At the moment, I've done a lot of reading, but not put anything to practice just yet as I'm still unsure on the basic make up of an addon.
 

mastafunk

New member
Jun 24, 2014
165
0
0
I'm with you ray, practical working examples will let me understand/fly better
Did anything ever come of this tutorial? I'm guessing not?

Does anyone know of any good video plugin tutorials? I'd love to get to grips with making plugins, but I'm more of a 'hands-on' type of learner, where I need to be doing it to learn, rather than just reading. At the moment, I've done a lot of reading, but not put anything to practice just yet as I'm still unsure on the basic make up of an addon.
You can do a git pull of your favorite addon and start getting your hands dirty...
 
Last edited:

rw86

New member
Aug 19, 2013
131
0
0
You can do a git pull of your favorite addon and start getting your hands dirty...
I know I can do this, and I have tried, but sometimes it's not as clear for a total novice as it is for those with a little more experience. Sometimes there's too much code, you need to start basic. Start with playing one stream/video, then how to make categories/menus, then scrapping sites, etc.

Don't get me wrong, the plugin I have in mind, I have a similar Addon downloaded that I am trying to figure out how it works, but it can be extremely overwhelming in regards to the fact I see certain lines of code and I have no idea what that does. Why is it there?

I'm not bashing anyone, and I understand I need to just keep on reading to learn, but there is a sever lack of practical options around with learning python for XBMC, and the practical that are there don't seem to be total beginner friendly.
 

Dr Peter OBoogie

New member
Jun 24, 2013
77
0
0
I know I can do this, and I have tried, but sometimes it's not as clear for a total novice as it is for those with a little more experience. Sometimes there's too much code, you need to start basic. Start with playing one stream/video, then how to make categories/menus, then scrapping sites, etc.

Don't get me wrong, the plugin I have in mind, I have a similar Addon downloaded that I am trying to figure out how it works, but it can be extremely overwhelming in regards to the fact I see certain lines of code and I have no idea what that does. Why is it there?

I'm not bashing anyone, and I understand I need to just keep on reading to learn, but there is a sever lack of practical options around with learning python for XBMC, and the practical that are there don't seem to be total beginner friendly.
I did a little bit of google research a few weeks back as had decided my ultimate goal is to produce an add on, but experienced a similar problem looking for tutorials. I have PM'd you a few links, some may be of use unless you have already found and explored - have not really had the time myself (my biggest enemy).
 

rw86

New member
Aug 19, 2013
131
0
0
I did a little bit of google research a few weeks back as had decided my ultimate goal is to produce an add on, but experienced a similar problem looking for tutorials. I have PM'd you a few links, some may be of use unless you have already found and explored - have not really had the time myself (my biggest enemy).
It's the biggest draw back to trying to learn, in my opinion. There are plenty of great things to read, but the lack of practical tasks to attempt means, at least for me, that I am unable to put to the test what I have read, in a way that I know will work. I like to think of it as when we did science experiments at school; you read how to do it, you read why you would do it, you read what the outcome(s) are, and then you follow a step by step guide while you do it practically, then you have that step by step guide taken away and have to do it yourself...

For me, without that process, I just struggle to get anything together.

Thanks for the PM, by the way, I'll look at it in a moment.
 

Capri

Banned
Jun 24, 2014
48
0
0
The easiest way is to just bite the bullet and give it a go. Yes there are few actual guides on how to produce an addon. But if you look at some simple ones and I think highway has an addon tutorial example in his repo, you should get a good idea on how it all works.
There are loads of python guides on the internet and various youtube videos showing the basics of python. Once you've got those mastered you can start looking at the various python modules for xbmc.
Python is the easy bit trust me. It's the poor documentation from .org which is the beast.
 

rw86

New member
Aug 19, 2013
131
0
0
The easiest way is to just bite the bullet and give it a go. Yes there are few actual guides on how to produce an addon. But if you look at some simple ones and I think highway has an addon tutorial example in his repo, you should get a good idea on how it all works.
There are loads of python guides on the internet and various youtube videos showing the basics of python. Once you've got those mastered you can start looking at the various python modules for xbmc.
Python is the easy bit trust me. It's the poor documentation from .org which is the beast.
The .org documents are a mess, in my opinion. They reference it being for 'beginners' but fail to go through certain steps and just assume that the reader already knows them. That's not beginner friendly, in my opinion.

I didn't know about Highway's tutorial addon, I will grab that later today.

Maybe it would be good if we had a list of 'simple' addons that would be good for beginners to look at and digest. Jonc's addons, for example, seem simple enough with just linking to a stream URL.
 

Capri

Banned
Jun 24, 2014
48
0
0
Highways addon should give you a good idea about creating listitems within xbmc (basically the list of movies etc you see).
In terms of simple addons maybe that's a project for a dev here. Create some basic addons so people can read. No disrespect to anyone but most addons at the mo are quite complicated for a beginner to read and understand, but only because the devs are getting better and exploring new ways of doing things.
What you would need is a "back to basics" addon structure.