def run(self, lItem):
     #loadLocal
     start = time.clock()
     log(str(mode))
     if mode == u'START':
         localParser.load_links(lItem)
         totalItems = len(localParser.links)
         tmp = {
             u'title': u' All Sites',
             u'type': u'rss',
             u'director': u'VideoDevil',
             u'icon': os.path.join(imgDir, u'face_devil_grin.png'),
             u'url': u'sites.list'
         }
         addListItem(mode.selectLinkMode(inheritInfos(tmp, lItem)), totalItems)
         for link in localParser.links:
             addListItem(mode.selectLinkMode(link), totalItems)
     elif mode == u'VIEW_RSS' or mode == u'VIEW_SEARCH' or mode == u'VIEW_RSS_DIRECTORY':
         localParser.load_site(lItem)
         self.sort.extend(localParser.site.sort)
         remoteParser.main(((localParser.site, lItem),))
         type_dict = {}
         for type, infos, items in remoteParser.items.files():
             if type == u'next' or (mode == u'VIEW_RSS_DIRECTORY' and type == lItem[u'type']):
                 log('type added = %s(%d)' % (type,len(items)))
                 addListItems(items, type, lItem)
             else:
                 create_list_and_listItem(cacheDir, type, items, infos, lItem)
         for type, infos, items in localParser.site.links.files():
             if type not in remoteParser.items:
                 for item in items:
                     addListItem(mode.selectLinkMode(item), 0)
     elif mode == u'VIEW_DIRECTORY':
         localParser.load_links(lItem)
         totalItems = len(localParser.links)
         for link in localParser.links:
             addListItem(mode.selectLinkMode(link), totalItems)
     elif mode == u'VIEWALL_RSS' or mode == u'VIEWALL_SEARCH':
         localParser.load_links_and_sites_in_list(lItem)
         remoteParser.main(localParser.sites)
         for type, infos, items in remoteParser.items.files():
             if u'cfg' in infos:
                 del infos[u'cfg']
             if type == u'next':
                 create_list_and_listItem(cacheDir, type, items, infos, lItem)
                 infos[u'title'] = infos[u'title'].strip(u' ')
                 addListItem(infos, 0)
             elif not os.path.isfile(os.path.join(allsitesDir, type + u'.list')):
                 create_list_and_listItem(allsitesDir, type, items, infos, lItem)
             else:
                 create_listItem(allsitesDir, type, infos)
         if u'category' not in remoteParser.items:
             item = lItem.copy()
             item[u'title'] = u'  ' + __language__(30100) + u'  '
             item[u'type'] = u'category'
             item[u'director'] = u'VideoDevil'
             item[u'icon'] = os.path.join(imgDir, u'face_devil_grin.png')
             item[u'url'] = os.path.join(allsitesDir, u'category.list')
             addListItem(mode.selectLinkMode(item), 0)
         if not os.path.isfile(os.path.join(allsitesDir, u'search.list')):
             tmp_items = []
             for site, item in localParser.sites:
                 for type, infos, items in site.links.files():
                     if type == u'search':
                         tmp_items.extend(items)
             infos = tmp_items[0].copy()
             if u'cfg' in infos:
                 del infos[u'cfg']
             create_list_and_listItem(allsitesDir, u'search', tmp_items, infos, lItem)
         else:
             item = lItem.copy()
             item[u'title'] = u'  ' + __language__(30102) + u'  '
             item[u'type'] = u'search'
             item[u'director'] = u'VideoDevil'
             item[u'icon'] = os.path.join(imgDir, u'search.png')
             item[u'url'] = os.path.join(allsitesDir, u'search.list')
             addListItem(mode.selectLinkMode(item), 0)
     elif mode == u'VIEWALL_DIRECTORY':
         fileDir = os.path.join(allsitesDir, lItem[u'type'])
         if not os.path.isdir(fileDir):
             os.mkdir(fileDir)
         if not os.listdir(fileDir):
             localParser.load_links_and_sites_not_in_list(lItem)
             remoteParser.main(localParser.sites)
             for type, infos, items in remoteParser.items.files():
                 if u'cfg' in infos:
                     del infos[u'cfg']
                 if type == lItem[u'type']:
                     self.createDirs(items + localParser.links)
                     dir_items = create_lists_and_listItems(fileDir, self.links, lItem) 
                     if dir_items:
                         saveList(allsitesDir, lItem[u'type'] + u'.list', lItem[u'title'], dir_items)
             addon.setSetting(lItem[u'type'] + '_all_sites_cache', str(time.time()))
         else:
             localParser.load_links(lItem)
             totalItems = len(localParser.links)
             for link in localParser.links:
                 addListItem(mode.selectLinkMode(link), totalItems)
     for sort_method in self.sort:
         xbmcplugin.addSortMethod(handle = self.handle, sortMethod = sort_dict[sort_method])
     log('time elapsed = %s' % (time.clock() - start))
     return 0
def create_listItem(directory, type, item, totalItems = 50):
    filename = type + u'.list'
    item[u'url'] = os.path.join(directory, filename)
    addListItem(mode.selectLinkMode(item), totalItems)
    return item