WIP Unable to implement search functionality while developing an addon
#1
I am learning to develop an addon for Kodi and have completed the major part. BTW, the addon is for Voot.com The Shows & Movies functionality is working absolutely fine with some minor bugs for few streams that can be easily fixed.

I am unable to implement the search functionality in the addon. I have gone through the code of some of the addons like the Hotstar-Rain by YoColdRain to learn to implement the search functionality.

The search ListItem opens up a KeyboardDialog and accepts the search input and most probably processes that search term by calling the voot.com api but does not shows the results by addDirectoryItem. Below is the basic code for the search functionality, if anyone could help.

Code:
_url = sys.argv[0]
_handle = int(sys.argv[1])

def get_url(**kwargs):
  return '{0}?{1}'.format(_url, urlencode(kwargs))

def display_main_menu():
    list_item = xbmcgui.ListItem(label="Search")
    url = get_url(action='search')
    xbmcplugin.addDirectoryItem(_handle, url, list_item)

def perform_search(search_term):
    link = "api_url_here" + search_term

    r = requests.get(link)

    resp = json.loads(r.text)

    for result in resp:
        list_item = xbmcgui.ListItem(label=result["name"])
        list_item.setArt({'thumb': result["img"], 'icon' : result["img"], 'fanart' : result["img"]})
        url = '' #blank url for testing
        is_folder = True
        xbmcplugin.addDirectoryItem(_handle, url, list_item, is_folder)

    xbmcplugin.endOfDirectory(_handle)

def search():
  keyb = xbmc.Keyboard('',"Search for Videos", False)
  keyb.setDefault('')
  keyb.doModal()

  if (keyb.isConfirmed() and len(keyb.getText()) > 0):
    perform_search(keyb.getText())

def router(paramstring):
  params = dict(parse_qsl(paramstring))

  if params:
    if params['action'] == 'search':
        search()

    else:
        raise ValueError('Invalid paramstring: {0}!'.format(paramstring))

  else:
    display_main_menu()

if __name__ == '__main__':
  router(sys.argv[2][1:])
Reply

Logout Mark Read Team Forum Stats Members Help
Unable to implement search functionality while developing an addon0