Beispiel #1
0
def search(item):
    best_match_id = None
    downloader    = TorecSubtitlesDownloader()
    search_data   = None
    
    start_time = time.time()

    try:
        search_start_time = time.time()
        search_string     = build_search_string(item)
        search_data       = downloader.search(search_string)
        
        log(__name__, "search took %f" % (time.time() - search_start_time))
    except:
        log( __name__, "failed to connect to service for subtitle search")
        xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8'))
        return
    
    list_items = []
    if search_data:
      best_match_id = downloader.get_best_match_id(os.path.basename(item['file_original_path']), search_data)

      for item_data in search_data.options:
          listitem = xbmcgui.ListItem(label    = "Hebrew",
                                label2         = item_data.name,
                                iconImage      = "0",
                                thumbnailImage = "he",
                                )
                                

          url = "plugin://%s/?action=download&page_id=%s&subtitle_id=%s&filename=%s" % (__scriptid__,
                                                                      search_data.id,
                                                                      item_data.id,
                                                                      item_data.name
                                                                      )

          if best_match_id != None and item_data.id == best_match_id:
            log(__name__, "Found most relevant option to be : %s" % item_data.name)
            listitem.setProperty("sync", "true")
            list_items.insert(0, (url, listitem, False,))
          else:
            list_items.append((url, listitem, False,))
    
    xbmcplugin.addDirectoryItems(handle=int(sys.argv[1]), items=list_items)
    log(__name__, "Overall search took %f" % (time.time() - start_time))