Plugin help.
#1
I couldnt find any tutorial on how to create a plugin so i found a couple and tried to mimic the behavior but with the modified values of the site i was trying to access. if anyone could tell me whats wrong it would be much appiciated.

When i clicked the plugin it tells me it cannot connect to the server.

Code:
import urllib,urllib2,re,xbmcplugin,xbmcgui,socket,xbmc


            

def CATS():
        addDir('Action','http://www.thepiratecity.org/search.htm?cat=29&type=',1,"")
        addDir('Drama ','http://www.thepiratecity.org/search.htm?cat=33&type=',1,"")
        addDir('Family','http://www.thepiratecity.org/search.htm?cat=31&type=',1,"")
        addDir('Horror','http://www.thepiratecity.org/search.htm?cat=34&type=',1,"")
        addDir('Comedy','http://www.thepiratecity.org/search.htm?cat=32&type=',1,"")
        addDir('Sci-fi','http://www.thepiratecity.org/search.htm?cat=36&type=',1,"")
        addDir('Others','http://www.thepiratecity.org/search.htm?cat=37&type=',1,"")
        

def INDEX(data):
                req = urllib2.Request(data)
                req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
                lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
                url=re.compile('<a class="anc"  href="(.+?)\"').findall(response)
                #url=re.compile('<div onclick="window.location.href=\'(.+?)\'" onMouseOver="toggleDiv.+?"').findall(response)
                name=re.compile('_(.+?).htm').findall(str(url))
                #name=re.compile('/(.+?),.+?.html').findall(str(url))
                #thumb=re.compile('<img src="(.+?)" width=".+?" height=".+?" border="0">').findall(response)
                for n in range(0,len(url)):
                        addDir(name[n],'http://www.thepiratecity.org/'+url[n],2,"")
                        
def ExtractMediaUrl(data):
        if len(data) > 0:
            
            videoPath = ""
            storeMessage = ""
            alphabet = "abcdefghijklmnopqrstuvwxyz"
            randomAlpha = ""
            randomNumber = 0
            storeMessage = data
            switchOverDecoded = ""
            keyPosition = 0
            i = 0
            j = 0
            
            while i < 26:
                if data[0] == alphabet[i]:
                    keyPosition = i
                i = i + 1
                
            i = 0
            
            while i < 26:
                randomAlpha = randomAlpha + alphabet[keyPosition]
                keyPosition = keyPosition + 1
                if keyPosition == 26:
                    keyPosition = 0
                i = i + 1
                
            i = 0
            
            while i < len(storeMessage):
                if (storeMessage[i] > "`" and storeMessage[i] < "{"):
                    j = 0
                    while j < 26:
                        if (storeMessage[i] == randomAlpha[j]):
                            switchOverDecoded = switchOverDecoded + alphabet[j]
                        j = j + 1
                else:
                    switchOverDecoded = switchOverDecoded + storeMessage[i]
                i = i + 1
                
            storeMessage = switchOverDecoded[1:]
            randomAlpha = ""
            switchOverDecoded = ""
            videoPath = storeMessage
            
            return videoPath
            
        else:
            return ""
            
                        

def VIDEO(url,name):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
        vpageurl=re.compile('<iframe scrolling="no" frameborder="0" src="(.+?)\"').findall(response)
        
        req = urllib2.Request('http://www.thepiratecity.org/'+vpageurl[0])
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
        match=re.compile('\r\nflashvars="myURL=(.+?)"').findall(response)
        link=ExtractMediaUrl(match[0])
    
        addLink(name+'Flv',link,"")


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 addLink(name,url,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok


def addDir(name,url,mode,iconimage):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
        return ok
        
              
params=get_params()
url=None
name=None
mode=None
try:
        url=urllib.unquote_plus(params["url"])
except:
        pass
try:
        name=urllib.unquote_plus(params["name"])
except:
        pass
try:
        mode=int(params["mode"])
except:
        pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
if mode==None or url==None or len(url)<1:
        print "CATEGORY INDEX : "
        CATS()
elif mode==1:
        INDEX(url)
elif mode==2:
        VIDEO(url,name)



xbmcplugin.endOfDirectory(int(sys.argv[1]))
Reply
#2
it was just bad spacing. if anyone has any pointers to make it better let me know.
Reply
#3
Great job :->

Nicely coded.

Add some thumbs and description of each film, if you can`t be bothered to code it have my IMDB Search function.

Pass the name to the function it does the rest.

It returns genre,year,thumb,plot & rating

Code:
def IMDB(url):
    req = urllib2.Request('http://www.imdb.com/find?s=all&q='+urllib.quote(url))
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
    response = urllib2.urlopen(req).read()
    alt=re.compile('<b>Media from&nbsp;<a href="/title/(.+?)/">').findall(response)
    if len(alt)>0:
        req = urllib2.Request('http://imdb.com/title/'+alt[0])
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        response = urllib2.urlopen(req).read()
        genre=re.compile(r'<h5>Genre:</h5>\n<a href=".+?">(.+?)</a>').findall(response)
        year=re.compile(r'<a href="/Sections/Years/.+?/">(.+?)</a>').findall(response)
        image=re.compile(r'<img border="0" alt=".+?" title=".+?" src="(.+?)" /></a>').findall(response)
        rating=re.compile(r'<div class="meta">\n<b>(.+?)</b>').findall(response)
        req = urllib2.Request('http://www.imdb.com/title/'+alt[0]+'/plotsummary')
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        response = urllib2.urlopen(req).read()
        plot=re.compile('<p class="plotpar">\n(.+?)\n<i>\n').findall(response)
        try:
            if plot[0].find('div')>0:
                plot[0]='No Plot found on Imdb'
        except IndexError: pass
        if len(plot)<1:
            req = urllib2.Request('http://www.imdb.com/title/'+alt[0]+'/synopsis')
            req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
            plotter = urllib2.urlopen(req).read();clean=re.sub('\n','',plotter)
            plot=re.compile('<div id="swiki.2.1">(.+?)</div>').findall(clean)
            try:
                if plot[0].find('div')>0:
                    plot[0]='No Plot found on Imdb'
            except IndexError: pass
                
        return genre[0],year[0],image[0],rating[0],plot[0]
    else :
        genre=re.compile(r'<h5>Genre:</h5>\n<a href=".+?">(.+?)</a>').findall(response)
        year=re.compile(r'<a href="/Sections/Years/.+?/">(.+?)</a>').findall(response)
        image=re.compile(r'<img border="0" alt=".+?" title=".+?" src="(.+?)" /></a>').findall(response)
        rating=re.compile(r'<div class="meta">\n<b>(.+?)</b>').findall(response)
        bit=re.compile(r'<a class="tn15more inline" href="/title/(.+?)/plotsummary" onClick=".+?">.+?</a>').findall(response)
        req = urllib2.Request('http://www.imdb.com/title/'+bit[0]+'/plotsummary')
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        response = urllib2.urlopen(req).read()
        plot=re.compile('<p class="plotpar">\n(.+?)\n<i>\n').findall(response)
        try:
            if plot[0].find('div')>0:
                plot[0]='No Plot found on Imdb'
        except IndexError: pass
        if len(plot)<1:
            req = urllib2.Request('http://www.imdb.com/title/'+bit[0]+'/synopsis')
            req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
            plotter = urllib2.urlopen(req).read();clean=re.sub('\n','',plotter)
            plot=re.compile('<div id="swiki.2.1">(.+?)</div>').findall(clean)
            try:
                if plot[0].find('div')>0:
                    plot[0]='No Plot found on Imdb'
            except IndexError: pass
        return genre[0],year[0],image[0],rating[0],plot[0]
Reply
#4
Here's the code from the first post but with some spacing sorted out. I was able to start A Knight's Tale and saw all of Finish Line. Some movies didn't work, but I didn't check to see if they were working online. I was just trying to get the plugin to work and I was able to successfully watch a movie.
Just make a folder called PirateCity and copy the code into a text document and save it as default.py. Put the default.py into the PirateCity folder and put it into Video Plugins. Great plugin coolblaze03!

Code:
import urllib,urllib2,re,xbmcplugin,xbmcgui,socket,xbmc


            

def CATS():
        addDir('Action','http://www.thepiratecity.org/search.htm?cat=29&type=',1,"")
        addDir('Drama ','http://www.thepiratecity.org/search.htm?cat=33&type=',1,"")
        addDir('Family','http://www.thepiratecity.org/search.htm?cat=31&type=',1,"")
    addDir('Horror','http://www.thepiratecity.org/search.htm?cat=34&type=',1,"")
    addDir('Comedy','http://www.thepiratecity.org/search.htm?cat=32&type=',1,"")
    addDir('Sci-fi','http://www.thepiratecity.org/search.htm?cat=36&type=',1,"")
    addDir('Others','http://www.thepiratecity.org/search.htm?cat=37&type=',1,"")
        

def INDEX(data):
                req = urllib2.Request(data)
                req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
                lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
                url=re.compile('<a class="anc"  href="(.+?)\"').findall(response)
                #url=re.compile('<div onclick="window.location.href=\'(.+?)\'" onMouseOver="toggleDiv.+?"').findall(response)
                name=re.compile('_(.+?).htm').findall(str(url))
                #name=re.compile('/(.+?),.+?.html').findall(str(url))
                #thumb=re.compile('<img src="(.+?)" width=".+?" height=".+?" border="0">').findall(response)
                for n in range(0,len(url)):
                        addDir(name[n],'http://www.thepiratecity.org/'+url[n],2,"")
                        
def ExtractMediaUrl(data):
        if len(data) > 0:
            
            videoPath = ""
            storeMessage = ""
            alphabet = "abcdefghijklmnopqrstuvwxyz"
            randomAlpha = ""
            randomNumber = 0
            storeMessage = data
            switchOverDecoded = ""
            keyPosition = 0
            i = 0
            j = 0
            
            while i < 26:
                if data[0] == alphabet[i]:
                    keyPosition = i
                i = i + 1
                
            i = 0
            
            while i < 26:
                randomAlpha = randomAlpha + alphabet[keyPosition]
                keyPosition = keyPosition + 1
                if keyPosition == 26:
                    keyPosition = 0
                i = i + 1
                
            i = 0
            
            while i < len(storeMessage):
                if (storeMessage[i] > "`" and storeMessage[i] < "{"):
                    j = 0
                    while j < 26:
                        if (storeMessage[i] == randomAlpha[j]):
                            switchOverDecoded = switchOverDecoded + alphabet[j]
                        j = j + 1
                else:
                    switchOverDecoded = switchOverDecoded + storeMessage[i]
                i = i + 1
                
            storeMessage = switchOverDecoded[1:]
            randomAlpha = ""
            switchOverDecoded = ""
            videoPath = storeMessage
            
            return videoPath
            
        else:
            return ""
            
                        

def VIDEO(url,name):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
        vpageurl=re.compile('<iframe scrolling="no" frameborder="0" src="(.+?)\"').findall(response)
        
    req = urllib2.Request('http://www.thepiratecity.org/'+vpageurl[0])
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
        lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
        match=re.compile('\r\nflashvars="myURL=(.+?)"').findall(response)
    link=ExtractMediaUrl(match[0])
    
        addLink(name+'Flv',link,"")


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 addLink(name,url,iconimage):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
        return ok


def addDir(name,url,mode,iconimage):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
        return ok
        
              
params=get_params()
url=None
name=None
mode=None
try:
        url=urllib.unquote_plus(params["url"])
except:
        pass
try:
        name=urllib.unquote_plus(params["name"])
except:
        pass
try:
        mode=int(params["mode"])
except:
        pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
if mode==None or url==None or len(url)<1:
        print "CATEGORY INDEX : "
        CATS()
elif mode==1:
        INDEX(url)
elif mode==2:
        VIDEO(url,name)



xbmcplugin.endOfDirectory(int(sys.argv[1]))
Reply
#5
A full tab`d plugin is being hosted for coolblaze on my google code page.

If the movie doesn`t work exit and enter a few times - they all work after the address is changed to another mega server.
Reply
#6
Voinage, Thanks for the add on your googlecode page. should i create a google code page to post updates?
Reply
#7
Very good job and nice plugin, thanks a lot for that.
We are looking for your next creation Big Grin
Image
_____________________________

Repositories Installer: select and install unofficial repositories / TAC.TV: watch videos on TAC.TV
Installer Passion-XBMC: Download and Install Add-ons (pre-Dharma only)

Image
Reply
#8
No problem Coolblaze, some people cannot test and save raw python.

Why not create one for your own plugins, you are bound to create a few more - you have the bug now.

here is a little sugg to clean the names : instead or the_cat__monkey etc the cat monkey-2007.


Code:
def INDEX(data):
    req = urllib2.Request(data)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
    lemon = urllib2.urlopen(req);response=lemon.read();lemon.close()
    url=re.compile('<a class="anc"  href="(.+?)\"').findall(response)
    nameclean=re.compile('_(.+?).htm').findall(str(url))
    #Tidy names
    code=re.sub('_',' ',str(nameclean));code2=re.sub('  ','-',code)
    code3=re.sub(''','',code2);code4=re.sub('&amp;','&',code3);code5=re.sub('&eacute;','e',code4)
    name=re.compile("'(.+?)'").findall(code5)
    #small ammendment - Voinage.
    for n in range(0,len(url)):
        addDir(name[n],'http://www.thepiratecity.org/'+url[n],2,"")
Reply
#9
Thanks for that extra code. I am already started on my second plugin. I saw that megavideo has changed up there code so im writing a new plugin for it.
Reply
#10
Another plus for having your own googlecode is you get svn, and if you work on multiple computers like me it can help keep everything in sync (plus the benefits of subversion, which you prob don't need just for plugins)
Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
Reply
#11
Nice plug-in and just tested it, it let me watch 1 movie, then stopped working?

Code:
00:49:05 M: 38486016  NOTICE: -->Python Initialized<--
00:49:05 M: 38486016  NOTICE:
00:49:07 M: 35627008  NOTICE: Mode: 2
00:49:07 M: 35627008  NOTICE:
00:49:07 M: 35627008  NOTICE: URL: http://www.thepiratecity.org/1377_Harold_&amp;_Kumar_Go_to_White_Castle__2004.htm
00:49:07 M: 35627008  NOTICE:
00:49:07 M: 35627008  NOTICE: Name: Harold_&amp;_Kumar_Go_to_White_Castle__2004
00:49:07 M: 35627008  NOTICE:
00:49:09 M: 35713024  NOTICE:
00:49:09 M: 35713024  NOTICE:
00:49:15 M: 40861696   ERROR: Error creating player for item 6f2 (File doesn't exist?)
00:49:15 M: 40861696   ERROR: Playlist Player: skipping unplayable item: 0, path [6f2]
00:49:20 M: 40796160   ERROR: Error creating player for item 6f2 (File doesn't exist?)
00:49:20 M: 40796160   ERROR: Playlist Player: skipping unplayable item: 0, path [6f2]
00:49:24 M: 40939520   ERROR: Unable to load: Q:\plugins\video\Piratecity\resources\settings.xml, Line 0
                             Failed to open file

This was the first film I tried and it played OK but after trying a couple of others (Quantum of Solace and Bank Job) received same error, so I tried the one above again! the 2 other films play on-line (through site).

[T3CH XBMC 2008-11-13 8.10 on Xbox]
[PMIII (Default Settings except for Video Cache 8192kb and Unknown Type Cache - Internet 8192kb)]

Could it be something at my end ?

:confused2:
Reply
#12
Just exit and re-enter a few times.

Piratecity uses megaupload, which change and lockout server access when capacity is overloaded.

Enter & exit until the server changes - They will work.
Reply
#13
Thanks Voinage I know it was mentioned earlier and I did try it but it wouldn't play anything no matter how many times I tried, weird.

So after a fresh download from your google page and reinstall all seems fine now, most have played first time.

Out of curiosity, as it said:

"Unable to load: Q:\plugins\video\Piratecity\resources\settings.xml"

is there supposed to be a 'settings' file ? or is that called from XBMC itself and not the plug-in.

Cheers CB03 and Voinage for help and plug-in.
Reply
#14
@Sle7en

The settings.xml is an optional file for plugin settings.
To illustrate the usage , check my google video plugin.

press the black button to bring up menu, select plugin settings.

Cheers V
Reply
#15
wow great work guys, supernice plugin, I watched a full film , all worked splendid. Big Grin
Reply

Logout Mark Read Team Forum Stats Members Help
Plugin help.0