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))
def search(item):
    best_match_id = None
    downloader = TorecSubtitlesDownloader()
    subtitles_options = None
    
    start_time = time.time()

    try:
        search_start_time = time.time()
        
        if (item['mansearch'] == False):
            if item['tvshow'] != "":
                subtitles_options = downloader.search_tvshow(item['tvshow'], item['season'], item['episode'])
            else:              
                title, year = xbmc.getCleanMovieTitle(item['title'])
                subtitles_options = downloader.search_movie(title)
        else:
            item['tvshow'], item['season'], item['episode'] = check_and_parse_if_title_is_TVshow(item['title'])
            if (item['tvshow'] == "NotTVShow"):
                item['title'] = item['title'].replace("%20", "%2b") # " " to "+"
                title, year = xbmc.getCleanMovieTitle(item['title'])
                subtitles_options = downloader.search_movie(title)
            else:
                subtitles_options = downloader.search_tvshow(item['tvshow'], int(item['season']), int(item['episode']))
                                    
        log(__name__, "search took %f" % (time.time() - search_start_time))
    except Exception as e:
        log(
            __name__,
            "failed to connect to service for subtitle search %s" % e
        )
        xbmc.executebuiltin(
            (u'Notification(%s,%s)' % (__scriptname__, __language__(32001))
             ).encode('utf-8'))
        return
    
    list_items = []
    if subtitles_options:
        best_match_option_id = downloader.get_best_match_id(
            os.path.basename(item['file_original_path']), subtitles_options
        )

        for item_data in subtitles_options:
            listitem = xbmcgui.ListItem(
                label="Hebrew", label2=item_data.name, iconImage="0",
                thumbnailImage="he"
            )
            url = (
                "plugin://%s/?action=download&sub_id=%s&option_id="
                "%s&filename=%s" % (
                    __scriptid__, item_data.sub_id, item_data.option_id, item_data.name
                )
            )

            if item_data.option_id == best_match_option_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))