WIP Need help in simple audio plugin.
#1
Hi, I am creating a simple addon on frodo. it fetch all the item list from three level sub-pages but shows blank list at final songs list page.
This is where it shows empty list:
Code:
def songslist(url):
    link=OPEN_URL(url)
    link=link.split('<tbody>')[1]
    link=link.split('</tbody>')[0]
    match=re.compile('value="(.+?)".*?title=(.+?)"').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com/gurbani/audio/play/'+str(url),2,'','')
    return

url is http://www.sikhnet.com/gurbani/artist/7121/audio

log:
Code:
20:49:33 T:8440   DEBUG: Instantiating addon using automatically obtained id of "plugin.video.testaudio" dependent on version 2.0 of the xbmc.python api
20:49:33 T:8440  NOTICE: Mode: 11
20:49:33 T:8440  NOTICE: URL: http://www.sikhnet.com/gurbani/artist/7121/audio
20:49:33 T:8440  NOTICE: Name: Click OK for list
20:49:33 T:8440  NOTICE: IconImage: None
20:49:33 T:8440  NOTICE: http://www.sikhnet.com/gurbani/artist/7121/audio
20:49:33 T:16284   DEBUG: ------ Window Init (DialogBusy.xml) ------
20:49:34 T:8440    INFO: Scriptresult: Success
20:49:34 T:12744   DEBUG: XFILE::CPluginDirectory::WaitOnScriptResult- plugin returned successfully
20:49:34 T:11152  NOTICE: Thread Background Loader start, auto delete: false
20:49:34 T:8440    INFO: Python script stopped
20:49:34 T:8440   DEBUG: Thread XBPyThread 8440 terminating
20:49:34 T:16284   DEBUG: waiting for python thread 83 (C:\Users\EAI\AppData\Roaming\XBMC\addons\plugin.video.sikhnet\default.py) to stop
20:49:34 T:16284   DEBUG: python thread 83 (C:\Users\EAI\AppData\Roaming\XBMC\addons\plugin.video.sikhnet\default.py) destructed
20:49:34 T:11152   DEBUG: Thread Background Loader 11152 terminating
20:49:34 T:16284   DEBUG: ------ Window Deinit (DialogBusy.xml) ------
20:49:35 T:16284   DEBUG: Keyboard: scancode: 38, sym: 0134, unicode: 0000, modifier: 100
20:49:35 T:16284   DEBUG: CApplication::OnKey: alt-leftalt (4f0d4) pressed, action is
20:49:35 T:16284   DEBUG: CWinEventsWin32::WndProcWindow is active
20:49:35 T:16284   DEBUG: CWinEventsWin32::WndProc: Focus switched to process C:\Windows\explorer.exe
use +/- ⇓⇓⇓⇓⇓⇓⇓
Reply
#2
you are trying to have it list a http dir. the url you link is not a http dir, it's a web page.
Reply
#3
(2015-01-21, 11:23)ironic_monkey Wrote: you are trying to have it list a http dir. the url you link is not a http dir, it's a web page.

So what to do for web page. I can get lists of artist, but not the songs.
Here is what I have so for:
Code:
import urllib,urllib2,sys,re,xbmcplugin,xbmcgui,xbmcaddon,xbmc,os

icon = xbmc.translatePath(os.path.join('special://home/addons/plugin.video.sikhnet', 'icon.png'))

ADDON = xbmcaddon.Addon(id='plugin.video.sikhnet')



def Mainmenu():
    addDir('Katha Kirtan Artist A-B' ,'http://www.sikhnet.com/gurbani/artistdirectory' ,100,'','')
    addDir('Katha Kirtan Artist C-D' ,'http://www.sikhnet.com/gurbani/artistdirectory' ,101,'','')
    addDir('Katha Kirtan Artist E-G' ,'http://www.sikhnet.com/gurbani/artistdirectory' ,102,'','')
    addDir('Katha Kirtan Artist H-L' ,'http://www.sikhnet.com/gurbani/artistdirectory' ,103,'','')
    addDir('Katha Kirtan Artist M-R' ,'http://www.sikhnet.com/gurbani/artistdirectory' ,104,'','')
    addDir('Katha Kirtan Artist S-Y' ,'http://www.sikhnet.com/gurbani/artistdirectory' ,105,'','')

def songslist(url):
    link=OPEN_URL(url)
    link=link.split('<tbody>')[1]
    link=link.split('</tbody>')[0]
    match=re.compile('checkbox" value="(.+?)".*?<a href=".*?">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com/gurbani/audio/play/'+str(url),2,'','')
    return

def allsongs(url):
    link=OPEN_URL(url)
    match=re.compile('<a href="(.+?)">All').findall(link)
    for url in match:
        addDir('Click OK for list','http://www.sikhnet.com'+str(url),11,'','')
    return
        
def artistAB(url):
    link=OPEN_URL(url)
    link=link.split('<h2>A</h2></div>')[1]
    link=link.split('><h2>C</h2></div>')[0]
    match=re.compile('<a href="(.+?)">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com'+str(url),10,'','')
    return
def artistCD(url):
    link=OPEN_URL(url)
    link=link.split('<h2>C</h2></div>')[1]
    link=link.split('><h2>E</h2></div>')[0]
    match=re.compile('<a href="(.+?)">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com'+str(url),10,'','')
    return
def artistEG(url):
    link=OPEN_URL(url)
    link=link.split('<h2>E</h2></div>')[1]
    link=link.split('><h2>H</h2></div>')[0]
    match=re.compile('<a href="(.+?)">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com'+str(url),10,'','')
    return
def artistHL(url):
    link=OPEN_URL(url)
    link=link.split('<h2>H</h2></div>')[1]
    link=link.split('><h2>M</h2></div>')[0]
    match=re.compile('<a href="(.+?)">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com'+str(url),10,'','')
    return
def artistMR(url):
    link=OPEN_URL(url)
    link=link.split('<h2>M</h2></div>')[1]
    link=link.split('><h2>S</h2></div>')[0]
    match=re.compile('<a href="(.+?)">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com'+str(url),10,'','')
    return
def artistSY(url):
    link=OPEN_URL(url)
    link=link.split('<h2>S</h2></div>')[1]
    link=link.split('artist-column')[0]
    match=re.compile('<a href="(.+?)">(.+?)</a').findall(link)
    for url,name in match:
        addDir(name,'http://www.sikhnet.com'+str(url),10,'','')
    return
        
def playStream(url):        
    pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
    pl.clear()
    pl.add(url)
    xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(pl)
    return
    
def OPEN_URL(url):
    req = urllib2.Request(url)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36')
    response = urllib2.urlopen(req)
    link=response.read()
    response.close()
    link = str(link)
    return 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 addDir(name,url,mode,iconimage,description):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&iconimage="+urllib.quote_plus(iconimage)+"&description="+urllib.quote_plus(description)
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description} )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
        return ok

def addLink(name,url,iconimage,description):
        ok=True
        liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
        liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description } )
        liz.setProperty("IsPlayable","true")
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz,isFolder=False)
        return ok

        
def setView(content, viewType):
        if content:
                xbmcplugin.setContent(int(sys.argv[1]), content)
        if ADDON.getSetting('auto-view') == 'true':
                xbmc.executebuiltin("Container.SetViewMode(%s)" % ADDON.getSetting(viewType) )
                      
              
params=get_params()
url=None
name=None
mode=None
iconimage=None
description=None


try:
        url=urllib.unquote_plus(params["url"])
except:
        pass
try:
        name=urllib.unquote_plus(params["name"])
except:
        pass
try:
        iconimage=urllib.unquote_plus(params["iconimage"])
except:
        pass
try:        
        mode=int(params["mode"])
except:
        pass
try:        
        description=int(params["description"])
except:
        pass

print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
print "IconImage: "+str(iconimage)
  
        
if mode==None or url==None or len(url)<1:
        print ""
        Mainmenu()
      
elif mode==2:
        print ""+url
        playStream(url)
elif mode==10:
        print ""+url
        allsongs(url)
elif mode==11:
        print ""+url
        songslist(url)
elif mode==100:
        print ""+url
        artistAB(url)
elif mode==101:
        print ""+url
        artistCD(url)
elif mode==102:
        print ""+url
        artistEG(url)
elif mode==103:
        print ""+url
        artistHL(url)
elif mode==104:
        print ""+url
        artistMR(url)
elif mode==105:
        print ""+url
        artistSY(url)
        

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

Logout Mark Read Team Forum Stats Members Help
Need help in simple audio plugin.0