def videolist(self, query, page='0'):
    api = NetworkTenVideo(self.plugin.cached(TTL=config.CACHE_TTL))
    if query == 'featured':
      homepage = api.get_homepage()
      videoIds = []
      for item in homepage:
        videoIds.append(item['brightcoveid'])
      videos = api.find_videos_by_ids(video_ids = videoIds)
    else:
      querystring = query
      query = urlparse.parse_qs(query)
      query['page_number'] = page
      videos = api.search_videos(**query)

    fanart_url = None
    if 'fanart' in self.request.args:
      fanart_url = self.request.args['fanart'][0]

    update_listing = False
    if 'update' in self.request.args and self.request.args['update'][0]:
      update_listing = True

    videoItems = []
    for video in videos.items:
      item = ListItem.from_dict(
        label=htmlparser.unescape(video.name),
        thumbnail=video.videoStillURL,
        is_playable=True,
        path=self.url_for('play.play', explicit=True, videoId=video.id)
      )
      item.set_info( "video", self.get_item_info(video))
      item.add_stream_info('video', {
        'codec': 'h264',
        'width': 944,
        'height': 528,
        'duration': float(video.length / 1000)
      })
      item.add_stream_info('audio', {
        'codec': 'aac',
        'language': 'en',
        'channels': 2
      })

      if fanart_url:
        item.set_property('fanart_image', fanart_url)
      videoItems.append(item)

    if videos.total_count > (videos.page_size * (int(page) + 1)):
      item = ListItem.from_dict(
        label='Next >>',
        path=self.url_for('videolist.videolist', query=querystring, page=str(int(page) + 1), fanart=fanart_url, update=True)
      )
      if fanart_url:
        item.set_property('fanart_image', fanart_url)
      videoItems.insert(0, item)

    if int(page) > 0:
      item = ListItem.from_dict(
        label='<< Previous',
        path=self.url_for('videolist.videolist', query=querystring, page=str(int(page) - 1), fanart=fanart_url, update=True)
      )
      if fanart_url:
        item.set_property('fanart_image', fanart_url)
      videoItems.insert(0, item)

    self.set_content('episodes')
    self.plugin.finish(
      items=videoItems,
      update_listing=update_listing,
      sort_methods=[SortMethod.UNSORTED, SortMethod.EPISODE, SortMethod.VIDEO_TITLE, SortMethod.VIDEO_RUNTIME])
class APICache:
  def __init__(self, plugin=None):
    self.api = NetworkTenVideo()
    self.log = plugin.log
    self.log.debug('Cache TTL set to %d minutes', config.CACHE_TTL)
    self.cache = plugin.get_storage('showlist', TTL=config.CACHE_TTL)
    print repr(self.cache)

  def get_show(self, show, bypassCache=False):
    if not bypassCache and 'showlist' in self.cache and show in self.cache['showlist']:
      self.log.debug('Retrieving show data for show "%s" from cache...', show)
      show_data = self.cache['showlist'][show]
    else:
      self.log.debug('Retrieving show data for show "%s" from api ...', show)
      show_data = self.api.get_show(show)
      if not 'showlist' in self.cache:
        self.cache['showlist'] = {}
      self.cache['showlist'][show_data.showName] = show_data
      self.cache.sync()

    self.log.debug('Show data: %s', repr(show_data))

    return show_data

  def get_shows(self, bypassCache=False):
    if not bypassCache and 'showlist' in self.cache:
      self.log.debug('Retrieving show list from cache...')
      shows = self.cache['showlist'].values()
    else:
      self.log.debug('Retrieving show list from api...')
      shows = self.api.get_shows().items
      if not 'showlist' in self.cache:
        self.cache['showlist'] = {}
      for show in shows:
        self.cache['showlist'][show.showName] = show
      self.cache.sync()

    self.log.debug('Shows: %s', repr(shows))

    return shows

  def get_playlists(self, show, bypassCache=False):
    if not bypassCache and 'showlist' in self.cache and show in self.cache['showlist'] and self.cache['showlist'][show].playlists and len(self.cache['showlist'][show].playlists) > 0:
      self.log.debug('Retrieving playlists for show "%s" from cache...', show)
      playlists = self.cache['showlist'][show].playlists
    else:
      self.log.debug('Retrieving playlists for show "%s" from api...', show)
      playlists = self.api.get_playlists_for_show(show).items
      if show in cache['showlist']:
        self.cache['showlist'][show].playlists = playlists
        self.cache.sync()

    self.log.debug('Playlists: %s', repr(playlists.items))

    return playlists

  def search_videos(self, bypassCache=False, **kwargs):
    key = json.dumps(kwargs)
    print repr(key)
    if not bypassCache and 'searches' in self.cache and key in self.cache['searches']:
      self.log.debug('Using search results from cache...')
      result = self.cache['searches'][key]
    else:
      self.log.debug('Using search results from api...')
      result = self.api.search_videos(**kwargs)
      if not 'searches' in self.cache:
        self.cache['searches'] = {}
      self.cache['searches'][key] = result
      self.cache.sync()
    return result