Sponsored Links:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
6. Creating A Directory Structure.
#1
This weeks guide is probably the most complex so far. We learn how to create directories from scratch.

The sys.argv command is also covered here.

Please only use this thread for support with any of the subjects covered in this particular episode, thank you.




[Image: nansig_arb.png]
  Reply
Sponsored Links:
#2
When your saying the dir_type when ur calling the function if u don't want it to be a folder just an item to click what do you do?
  Reply
#3
Sorry just heading out but thought I'd quickly answer this before I forget. If I remember rightly I only had the if statement check for 'folder' so anything other than that should be fine. I usually just send through an empty ''.
WANT TO SHOW YOUR APPRECIATION?
A thank you is really all that's needed but if you want to buy me a drink then who am I to argue!

[Image: 11i3ihd.jpg]
  Reply
#4
(07-23-2016, 07:04 PM)whufclee Wrote: Sorry just heading out but thought I'd quickly answer this before I forget. If I remember rightly I only had the if statement check for 'folder' so anything other than that should be fine. I usually just send through an empty ''.

whufclee is correct just pass an empty with two single quotes ''.

@whufclee, I believe for this tutorial you had the if statement check that dir_type not equal to empty (if dir_type != ''Smile.
  Reply
#5
Hi there,
i have been trying to make my own playlist addon, and saw your videos and kinda mixed your code with code from another tutorial video. My addon "kinda" works but there is somthing i would like to optimize. So my question is, if it is ok for me to post my code here and ask my question?

also sorry for my not perfect english, i hope you understand me.

Regards Palle
  Reply
#6
Hi Palle,

Yes that is fine but if posting code can you please make sure you use forum code tags so it doesn't clutter up the forum with lots of long text. Thanks.
WANT TO SHOW YOUR APPRECIATION?
A thank you is really all that's needed but if you want to buy me a drink then who am I to argue!

[Image: 11i3ihd.jpg]
  Reply
#7
Thanks.

Code:
import xbmcaddon,os,requests,xbmc,xbmcgui,urllib,urllib2,re,xbmcplugin

addon_handle = int(sys.argv[1])
#xbmc.log(sys.argv[1])

def CATEGORIES():
   addDir('[color=#000000][b]Version 2.0.3 - [i]klik her for at opdater listen[/i][/b][/color]','','','')
   req = requests.get('http://192.168.0.133/nikolu/xbmc/playlister/list.txt')
   match = re.compile('<name="(.+?)" ico="(.+?)" url="(.+?)">').findall(req.content)
   for name,ico,url in match:
       addDir(name,url,3,ico)

def LISTMORE(url):
   count = 0
   req = requests.get(url)
   match = re.compile('<name="(.+?)" ico="(.+?)" url="(.+?)">').findall(req.content)
   for name,ico,url in match:
       count = count + 1
       addDir2('[color=#000000]%s[/color] - [color=#000000]%s[/color]'%(count,name),url,50,ico)

def play(url, name):
   listitem = xbmcgui.ListItem(path=url, thumbnailImage=iconimage)
   listitem.setInfo(type="Video", infoLabels={ "Title": name })
   xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=listitem, isFolder=False)

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    

def addDir(name,url,mode,iconimage):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
        listitem=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        listitem.setInfo( type="Video", infoLabels={ "Title": name } )
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=u, listitem=listitem, isFolder=True)


def addDir2(name,url,mode,iconimage):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&iconimage="+urllib.quote_plus(iconimage)
        listitem=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        listitem.setInfo( type="Video", infoLabels={ "Title": name } )
        listitem.setProperty( "Fanart_Image", fanart )
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=u, listitem=listitem, isFolder=True)

params=get_params()
url=None
name=None
mode=None
iconimage=None
fanart=None
description=None

try:
        url=urllib.unquote_plus(params["url"])
except:
        pass
try:
        name=urllib.unquote_plus(params["name"])
except:
        pass
try:
        iconimage=urllib.unquote_plus(params["iconimage"])
except:
        pass
try:        
        mode=int(params["mode"])
except:
        pass
try:        
        fanart=urllib.unquote_plus(params["fanart"])
except:
        pass
try:        
        description=urllib.unquote_plus(params["description"])
except:
        pass
   
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)

if mode==None or url==None or len(url)<1:
        CATEGORIES()
elif mode==1:
        OPEN_URL(url)
elif mode==3:
        LISTMORE(url)
elif mode==50:
        play(url, name)

xbmcplugin.endOfDirectory(addon_handle)

think thats all of it .. oki so my question is where am i messing it up!

my problem is that when i click one of my links in a sub dir (addDir2) it opens another sub dir with no tekst but an icon/thumb on the link. but i can play it if i click it. i did try to set isFolder to False but if i do that it then i can't play the link.....  

or is my problem with the "def play" ?

do you even understand my problem :Big Grin if not ill try to explain it bether ... if i can 

Regards Palle

ps i know i dont use like mode 1 and so on just haven gotten around to remove everything i dont need untill my addons works like i want to.
  Reply
#8
The play function doesn't look right to me, I would suggest watching the Python Koding episode where we cover how to play videos. I think that was episode 3.

For the names not appearing it's hard to diagnose as I don't have a copy of the source file you're trying to grab the data from but it sounds like there is something wrong with your regex and it's not picking up the name.

Best way to check is just add the following in your for loop:

xbmc.log('#### name: %s' % name)

Then you can look in the log to see if it's picking up the name or not. If it isn't you know your regex is wrong. If you can't work out the regex please post a sample of your source page and we should be able to work out the regex required.
WANT TO SHOW YOUR APPRECIATION?
A thank you is really all that's needed but if you want to buy me a drink then who am I to argue!

[Image: 11i3ihd.jpg]
  Reply
#9
if you dont mind you can chek the whole addon yourself here http://nikolu.dk/nikolu/xbmc/plugin.vide...u.iptv.zip

and i did open access to my webserver on my router so everything should work for you so you might bether understand my problem
  Reply
#10
(10-24-2016, 11:23 PM)Palle Grønbæk Wrote: if you dont mind you can chek the whole addon yourself here http://nikolu.dk/nikolu/xbmc/plugin.vide...u.iptv.zip

and i did open access to my webserver on my router so everything should work for you so you might bether understand my problem
Ohhh i messed that up!
wrong folder
this is the right addon! http://nikolu.dk/nikolu/xbmc/plugin.vide...u-iptv.zip

(10-24-2016, 11:06 PM)whufclee Wrote: The play function doesn't look right to me, I would suggest watching the Python Koding episode where we cover how to play videos. I think that was episode 3.

Also if i do the same thing you did in your "video 3":
Code:
def play(url, name):
#    listitem = xbmcgui.ListItem(path=url, thumbnailImage=iconimage)
#    listitem.setInfo(type="Video", infoLabels={ "Title": name })
#    xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=listitem, isFolder=False)
   xbmc.Player().play(url)

you cant stop the video from playing if you stop it it just autostarts again and you need to "alt+f4" to stop it

// Palle

Wait wait wait........ THANKS!.... all i had to do was change the play like you said and then change " isFolder=False" ind addDir2 and now it works.!

Thanks again!

Regards Palle
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  1. Terminology & Structure whufclee 18 2,638 05-23-2017, 09:58 PM
Last Post: mikesnow
  4. Creating playable video links whufclee 2 113 05-08-2017, 04:13 PM
Last Post: whufclee

Forum Jump:


Users browsing this thread: 1 Guest(s)