2013-08-26, 10:43
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:
this is the section that i am having trouble with:
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:
any tips please?
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?