def createSuggestionsList(params):
  module = params['module']
  url = 'http://www.uitzendinggemist.nl/kijktips'
  request = common.fetchPage({"link": url, "cookie": "site_cookie_consent=yes"})
  if request["status"] == 200:
    page = request["content"].encode('utf-8')
    episodes = common.parseDOM(page, 'div', attrs = { 'class': 'kijktip' })
    for episode in episodes:
      title = common.parseDOM(episode, 'h3')
      videourl = "http://www.uitzendinggemist.nl%s" % common.parseDOM(title, 'a', ret = 'href')[0]
      title = common.parseDOM(title, 'a')[0]
      subtitle = common.parseDOM(episode, 'h2')
      subtitle = common.parseDOM(subtitle, 'a')[0]
      plot = common.parseDOM(episode, 'p')[0]
      title = "%s - %s" % (title, subtitle)
      videourl = urllib.quote_plus(videourl)
      videourl = sys.argv[0]+"?module="+module+"&action=find_video"+"&url="+videourl
      thumb = utils.parseDataImages(common.parseDOM(episode, 'img', attrs = { 'class': 'thumbnail' }, ret = 'data-images')[0])
      utils.addLink(title, videourl, thumb, info={'plot': plot})
  xbmcplugin.endOfDirectory(int(sys.argv[1]))
def find_episodes(params):
  baseurl = 'http://www.uitzendinggemist.nl/top50/'
  period = params['period']
  module = params['module']
  
  url = baseurl + period
  request = common.fetchPage({"link": url, "cookie": "site_cookie_consent=yes"})
  if request["status"] == 200:
    page = request["content"].encode('utf-8')
    page = common.parseDOM(page, 'tbody')
    episodes = common.parseDOM(page, 'tr')
    for i, episode in enumerate(episodes):
      title = common.parseDOM(episode, 'h2')
      subtitle = common.parseDOM(episode, 'h3')
      title = "%i. %s, %s" % (i+1, common.parseDOM(subtitle, 'a', ret='title')[0], common.parseDOM(title, 'a', ret='title')[0])
      videourl = "http://www.uitzendinggemist.nl%s" % common.parseDOM(episode, 'a', attrs = { 'class': 'episode active episode-image' }, ret = 'href')[0]
      videourl = urllib.quote_plus(videourl)
      videourl = sys.argv[0]+"?module="+module+"&action=find_video"+"&url="+videourl
      thumb = utils.parseDataImages(common.parseDOM(episode, 'img', attrs = { 'class': 'thumbnail' }, ret = 'data-images')[0])
      utils.addLink(title, videourl, thumb)

  xbmcplugin.endOfDirectory(int(sys.argv[1]))
def find_programs(params):
  baseurl = 'http://www.uitzendinggemist.nl/programmas/'
  letter = urllib.unquote(params['letter'])
  module = params['module']
  page = ""
  pagecount = 1
  while pagecount<15:
    url = baseurl + letter + "?display_mode=images&_pjax=true&page=" + str(pagecount)
    request = common.fetchPage({"link": url, "cookie": "site_cookie_consent=yes"})
    if request["status"] == 200:
      page = request["content"].encode('utf-8')
      programs = re.findall(r"<a href=\"(.*?)\".*?class=\"series series-image\".*?title=\"(.*?)\">.*?data-images=\"(.*?)\".*?</a>", page)
      if len(programs)==0:
        break
      for program in programs:
        title = common.replaceHTMLCodes(program[1])
        programurl = program[0]
        programurl = sys.argv[0]+"?module="+module+"&action=find_episodes"+"&url=" + programurl
        thumb = utils.parseDataImages(program[2])
        utils.addDir(title, programurl, thumb)
    pagecount = pagecount+1
  xbmcplugin.endOfDirectory(int(sys.argv[1]))