first plugin - help needed please
#1
ive been following a few guides ive found and have started to make a plugin. I've managed to get it working, but am getting errors on playback. The video plays but the way i have implemented it is not correct, i know that.

here is the default.py:
Code:
def CATEGORIES():
        addDir("videos","http://gotgame.com/category/videos/",1,"http://reggiebibbs.files.wordpress.com/2007/12/the-movies360-crop.jpg")
        #addDir( '','',1,'')
                      
def INDEX(url):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.compile('<img src="(.+?)" alt="" title="" />\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t</a>\r\r\n\t\t\t\t\t\t</div><!--archive-image-->\r\r\n\t\t\t\t\t\t<div class="archive-text">\r\r\n\t\t\t\t\t\t\t<h2><a href="(.+?)">(.+?)</a></h2>\r\r\n\t\t\t\t\t\t\t<span class="archive-byline').findall(link)
        for thumbnail,url,name in match:
                addDir(name,url,2,thumbnail)

def VIDEOLINKS(url,name):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.compile('<iframe title="YouTube video player" width="640" height="395" src="http://www.youtube.com/embed/(.+?)?rel=0"').findall(link)
        match=("plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid="+match[0])
        addLink(name,xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(match),'')
              

                
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 ""
        CATEGORIES()
      
elif mode==1:
        print ""+url
        INDEX(url)
        
elif mode==2:
        print ""+url
        VIDEOLINKS(url,name)
        
        
        


xbmcplugin.endOfDirectory(int(sys.argv[1]))

this is the section that i am having trouble with:
Code:
def VIDEOLINKS(url,name):
        req = urllib2.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        link=response.read()
        response.close()
        match=re.compile('<iframe title="YouTube video player" width="640" height="395" src="http://www.youtube.com/embed/(.+?)?rel=0"').findall(link)
        match=("plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid="+match[0])
        addLink(name,xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(match),'')

if i call xbmc player without using addLink the video will repeat continuosly, if i leave it as it is above then it plays but i get an error in the log:
Quote:09:34:30 T:2936 ERROR: EXCEPTION: argument "url" for method "XBMCAddon::xbmcplugin::addDirectoryItem" must be unicode or str
09:34:30 T:2936 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.TypeError'>
Error Contents: argument "url" for method "XBMCAddon::xbmcplugin::addDirectoryItem" must be unicode or str
Traceback (most recent call last):
File "C:\Users\ebay\AppData\Roaming\XBMC\addons\plugin.video.gotgame-0.0.1\Default.py", line 104, in <module>
VIDEOLINKS(url,name)
File "C:\Users\ebay\AppData\Roaming\XBMC\addons\plugin.video.gotgame-0.0.1\Default.py", line 27, in VIDEOLINKS
addLink(name,xbmc.Player(xbmc.PLAYER_CORE_MPLAYER).play(match),'')
File "C:\Users\ebay\AppData\Roaming\XBMC\addons\plugin.video.gotgame-0.0.1\Default.py", line 59, in addLink
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
TypeError: argument "url" for method "XBMCAddon::xbmcplugin::addDirectoryItem" must be unicode or str
-->End of Python script error report<--
09:34:30 T:2172 ERROR: XFILE::CDirectory::GetDirectory - Error getting plugin://plugin.video.france24.fr/?mode=2&name=Hard%204%20Shadows%20of%20The%20Empire%20%26%238211%3b%20N64&url=http%3a%2f%2fgotgame.com%2f2013%2f08%2f24%2fhard-4-shadows-of-the-empire-n64%2f
09:34:30 T:2172 ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.france24.fr/?mode=2&name=Hard%204%20Shadows%20of%20The%20Empire%20%26%238211%3b%20N64&url=http%3a%2f%2fgotgame.com%2f2013%2f08%2f24%2fhard-4-shadows-of-the-empire-n64%2f) failed

any tips please?
Reply
#2
yes. stop thinking as if you are implementing a script. you are not.

you are implementing a virtual file system. you either list a directory or you open a file. you never open a player, that's xbmc's job. you just return an url.

in particular, when listing a dir of playable items, you mark them as such when you return the directorylisting, ie. item.setProperty('isPlayable','true')
when a user click an item in the gui, we then callback to your plugin. you are then tasked to return the playable url. you return this using setResolvedUrl().
Reply
#3
thank you, i'll take a fresh look at it now
Reply
#4
Shouldnt this:
Code:
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
    params=params[0:len(params)-2]

Be this?
Code:
if (params[len(params)-1]=='/'):
    params=params[0:len(params)-2]
cleanedparams=params.replace('?','')
Reply
#5
are there anymore tutorials apart from:
http://wiki.xbmc.org/index.php?title=HOW...s_for_XBMC

as that doesnt mention anything about setresolvedurl etc
Reply
#6
grab e.g. plugin.video.rbk.no (i know it uses it since i wrote it). monkey what you see.
Reply
#7
welly,


Beside what spiff has advised about your code, looking at your error log...

Quote:File "C:\Users\ebay\AppData\Roaming\XBMC\addons\plugin.video.gotgame-0.0.1\Default.py", line 59, in addLink
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
TypeError: argument "url" for method "XBMCAddon::xbmcplugin::addDirectoryItem" must be unicode or str

Your code:
Code:
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)

Corrected:
Code:
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=str(url),listitem=liz)

Right or wrong way not withstanding... that will resolve the error.
Reply
#8
I'm having problem with the video host i'm scraping. The structure goes like

1) List of Series, click to get (2) another site listing episodes. Clicking episode link will open different page where I can get video URL. I can't use isPlayable-property in stage two because i don't know video url yet. I have managed to program functions for scraping all needed URLS but the problem is that how I can start video from stage 2, the episode list?

E: nvm - figured it out myself, learned to understand whole directory system better :-)
Reply

Logout Mark Read Team Forum Stats Members Help
first plugin - help needed please0