addLink

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
laxtrappa Offline
Junior Member
Posts: 9
Joined: Aug 2012
Reputation: 0
Post: #1
I'm new to xbmc addon development, so far I'm
just copy/pasting other addons.
can't get the following code to do anything.
can anyone give me some hints?

the links show up but nothing happends when i click them.
they are .mp3 extended and work fine if i put them in an .strm file

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

def addLink(name,mode,url,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="Audio", infoLabels={ "Title": name } )
    ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
    return ok

base_url = 'myurl.url'
list_url=base_url+'/cgi-bin/list'

req = urllib2.Request(list_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('<a href="(stream[^"]+)">.+&nbsp;([^<]+)<br>').findall(link)

for item in match:
    addLink(item[1],1,base_url+"/cgi-bin/"+item[0],'')

xbmcplugin.endOfDirectory(int(sys.argv[1]))
(This post was last modified: 2012-08-17 12:30 by laxtrappa.)
find quote
laxtrappa Offline
Junior Member
Posts: 9
Joined: Aug 2012
Reputation: 0
Post: #2
i got the links to work now. the updated addLink function is now:

Code:
def addLink(name,url,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="Audio", infoLabels={ "Title": name } )
    ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz,isFolder=False)
    return ok

what happens now is that xbmc hangs at "Loading directory" (100%) "Retrieved x items"
this behaviour happens only when i DON'T use
Code:
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
but insert the url directly. i cant figure out whats going on here.. can someone?
(This post was last modified: 2012-08-19 17:15 by laxtrappa.)
find quote
laxtrappa Offline
Junior Member
Posts: 9
Joined: Aug 2012
Reputation: 0
Post: #3
ok.. some more progress. it wont work unless i use
the "u=sys.argv[0]+"?url="+urllib......" line.
it generates links like this one:

plugin://plugin.audio.apa/?url=http://%3A%2F%2Fmyurl.com....

when i click these links i can erad in the log:
11:57:15 T:2980821872 ERROR: AddItem - called with an invalid handle.
11:57:15 T:2980821872 ERROR: EndOfDirectory - called with an invalid handle.

how are these links supposed to be formatted to work?
(This post was last modified: 2012-08-20 11:59 by laxtrappa.)
find quote
jeanwilly Offline
Member
Posts: 75
Joined: Mar 2012
Reputation: 1
Post: #4
what for a url ?

Regards Skatulskijean
find quote
laxtrappa Offline
Junior Member
Posts: 9
Joined: Aug 2012
Reputation: 0
Post: #5
I'll rather not paste the url. it's links to albums on my private server and i dont want
that indexed by google Smile
i believe the links are fine though. they are in the format:

http://xxx.xxx.xxx.xxx/cgi-bin/stream/album_name.mp3
find quote
laxtrappa Offline
Junior Member
Posts: 9
Joined: Aug 2012
Reputation: 0
Post: #6
i also get in the logs:

12:36:23 T:2909252464 ERROR: EndOfDirectory - called with an invalid handle.

which makes me suspect that something is wrong in the way the addon is called.
sys.argv[0] containts:
plugin://plugin.audio.apa/
and sys.argv[1]:
0

is this correct?
I'm talking to myself here ... Smile
(This post was last modified: 2012-08-20 12:41 by laxtrappa.)
find quote
Bstrdsmkr Offline
Fan
Posts: 651
Joined: Oct 2010
Reputation: 12
Post: #7
Ok this is a little hard to explain. The problem is in the PREVIOUS call to addlink(). In the call before this one, the isFolder parameter was set to False (since it's static in your function), so xbmc didn't pass in a valid handle assuming that you wouldn't need one. Once you call with isFolder=False, you can't add any more "sub-levels" to the directory system. If you use isFolder=False, all the items in that list need to be directly playable
find quote
laxtrappa Offline
Junior Member
Posts: 9
Joined: Aug 2012
Reputation: 0
Post: #8
thanks for your reply. it made me think in a new direction: here is my currect code. it got rid of the errors in the log file
but still wont play

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

items = []

def addLink(name,mode,url,iconimage):
    u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
    ok=True
    liz=xbmcgui.ListItem(name+"("+u+")", iconImage="DefaultFolder.png", thumbnailImage=iconimage)
    liz.setInfo( type="Audio", infoLabels={ "Title": name } )
#    ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
    t=u,liz,False
    items.append(t)
    return ok

base_url = 'http://www.Xxxxxx.se'
list_url=base_url+'/cgi-bin/list'

req = urllib2.Request(list_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('<a href="(stream[^"]+)">.+&nbsp;([^<]+)<br>').findall(link)

cnt = 0
for item in match:
    addLink(item[1],1,base_url+"/cgi-bin/"+item[0],'')
    cnt=cnt+1

xbmcplugin.addDirectoryItems(handle=int(sys.argv[1]), items=items, totalItems=cnt)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
(This post was last modified: 2012-08-21 13:40 by laxtrappa.)
find quote
tuxen Offline
Fan
Posts: 537
Joined: May 2011
Reputation: 4
Post: #9
Hey laxtrappa, maybe move your post to where we talked about in the python section. Because of US laws XBMC.org has changed their policy to be rather strict on plugins and links. Sad
(This post was last modified: 2012-08-21 00:02 by tuxen.)
find quote
Bstrdsmkr Offline
Fan
Posts: 651
Joined: Oct 2010
Reputation: 12
Post: #10
@laxtrappa, Have you tried manually adding a single item to make sure you can stream from your server? Hit me up here or at xbmchub and let me know what happens when you try to play it
find quote
Post Reply