My First Addon works sort of weee!!!
#1
I'm making an add on to view videos from a site called crazyshit. It already loads the first page of videos and I'm aple to play them but how can I add a directory item to load the next page? Is there an event or how does that work? I'm new to python and kodi but I will link to my zip and post my source code. I'm a prrogrammer but I'm very new to python and even newer to Kodi.

Zip File for the add on here

Code:
#!/usr/bin/env python

import sys
import xbmcgui
import xbmcplugin
import urllib
import urlparse
import re

url = "http://www.crazyshit.com/?show="
pagenum = 1
vidlinks = []
videos= []
piclinks = []
pictures = []
html = ''

def loadpage(page):
    try:
        html = urllib.urlopen(page).read()
        b = re.findall(r'<div class="contentCell">.*?<div class="clearBoth">', html, re.S)
        html = ''

        for e in b:
            html += e

        y = re.findall(r'<a[^>]*href="(.*?)"', html)
        for g in y:
            if '/cnt/' in g:

                if '/cnt/medias/' in g:
                    if  urlparse.urljoin(page,g) not in vidlinks:
                        vidlinks.append(urlparse.urljoin(page,g))

    except:
        pass
        
def main():
    loadpage(url + str(pagenum))
    
    addon_handle = int(sys.argv[1])
    xbmcplugin.setContent(addon_handle, 'movies')
    
    for x in vidlinks:
        html = urllib.urlopen(x).read()
        try:
            li = xbmcgui.ListItem(label = re.findall(r'<meta property="og:title" content="(.*?)"/>', html, re.S)[0])
            vid = re.findall(r'<source src="(.*?)" type=', html, re.S)[0]
            img = re.findall(r'<video.*?poster="(.*?)".*?data-setup', html, re.S)[0]
            li.setIconImage(img)
            plot = re.findall(r'<div id="content-text">(.*?)</div>', html, re.S)[0]
            plot = re.sub(r'<.*?>', '', plot)
            li.setInfo( type="Video", infoLabels={ "Plot" : plot })
            li.setArt({ "fanart" : img })
            xbmcplugin.addDirectoryItem(handle=addon_handle, url=vid,listitem=li,totalItems=len(vidlinks))

        except:
            pass        

    xbmcplugin.endOfDirectory(addon_handle)

main()
Reply
#2
A plugin is a virtual directory entry. You add a directory item pointing back to your plugin, but with an additional parameter to identify the page, e.g. url=sys.argv [0]+'?pagenum=2'. When the user clicks the item your plugin gets called again with the parameter you added earlier. Then you detect the parameter and process accordingly in your main method (params are in sys.argv [2]).
Reply
#3
Oh sweet simple enough, thanks ironic_monkey
Reply
#4
np. one more thing. if you don't want each page to be put in the directory history as a separate entry, use the 'updateListing' bool parameter in the endOfDirectory call.
Reply

Logout Mark Read Team Forum Stats Members Help
My First Addon works sort of weee!!!0