def Search( item ): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log( __name__, "failed to connect to service for subtitle search") xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8')) return if search_data != None: search_data.sort(key=lambda x: [not x['MatchedBy'] == 'moviehash',x['LanguageName']]) for item_data in search_data: listitem = xbmcgui.ListItem(label = item_data["LanguageName"], label2 = item_data["SubFileName"], iconImage = str(int(round(float(item_data["SubRating"])/2))), thumbnailImage = item_data["ISO639"] ) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"] ) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0] ) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (__scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"] ) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
def Search( item ): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log( __name__, "failed to connect to service for subtitle search") xbmc.executebuiltin((u'Notification(%s,%s)' % (__scriptname__ , __language__(32001))).encode('utf-8')) return if search_data != None: search_data.sort(key=lambda x: [not x['MatchedBy'] == 'moviehash', not os.path.splitext(x['SubFileName'])[0] == os.path.splitext(os.path.basename(urllib.unquote(xbmc.Player().getPlayingFile().decode('utf-8'))))[0], not normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower() in x['SubFileName'].replace('.',' ').lower(), not x['LanguageName'] == PreferredSub]) for item_data in search_data: ## hack to work around issue where Brazilian is not found as language in XBMC if item_data["LanguageName"] == "Brazilian": item_data["LanguageName"] = "Portuguese (Brazil)" listitem = xbmcgui.ListItem(label = item_data["LanguageName"], label2 = item_data["SubFileName"], iconImage = str(int(round(float(item_data["SubRating"])/2))), thumbnailImage = item_data["ISO639"] ) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"] ) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0] ) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % (__scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"] ) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)
def Search(item): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log(__name__, "failed to connect to service for subtitle search") xbmc.executebuiltin( (u'Notification(%s,%s)' % (__scriptname__, __language__(32001))).encode('utf-8')) return if search_data != None: if isinstance(search_data, dict): log(__name__, "received data has a new format, convert it to list") search_data = [v for v in search_data.values()] search_data.sort(key=lambda x: [ not x['MatchedBy'] == 'moviehash', not os.path. splitext(x['SubFileName'])[0] == os.path.splitext( os.path.basename(urllib.unquote(item['file_original_path'])))[ 0], not normalizeString( xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower( ) in x['SubFileName'].replace('.', ' ').lower(), not x[ 'LanguageName'] == PreferredSub ]) for item_data in search_data: ## hack to work around issue where Brazilian is not found as language in XBMC if item_data["LanguageName"] == "Brazilian": item_data["LanguageName"] = "Portuguese (Brazil)" if ((item['season'] == item_data['SeriesSeason'] and item['episode'] == item_data['SeriesEpisode']) or (item['season'] == "" and item['episode'] == "" ) ## for file search, season and episode == "" ): listitem = xbmcgui.ListItem( label=item_data["LanguageName"], label2=item_data["SubFileName"], iconImage=str(int(round(float(item_data["SubRating"]) / 2))), thumbnailImage=item_data["ISO639"]) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"]) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0]) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % ( __scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"]) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)
def Search(item): search_data = [] try: search_data = OSDBServer().searchsubtitles(item) except: log(__name__, "failed to connect to service for subtitle search") xbmc.executebuiltin( (u'Notification(%s,%s)' % (__scriptname__, __language__(32001))).encode('utf-8')) return if search_data != None: search_data.sort(key=lambda x: [ not x['MatchedBy'] == 'moviehash', not os.path. splitext(x['SubFileName'])[0] == os.path.splitext( os.path.basename(urllib.unquote(item['file_original_path'])))[ 0], not normalizeString( xbmc.getInfoLabel("VideoPlayer.OriginalTitle")).lower( ) in x['SubFileName'].replace('.', ' ').lower(), not x[ 'LanguageName'] == PreferredSub ]) listitems = [] for item_data in search_data: ## hack to work around issue where Brazilian is not found as language in XBMC if item_data["LanguageName"] == "Brazilian": item_data["LanguageName"] = "Portuguese (Brazil)" if ((item['season'] == item_data['SeriesSeason'] and item['episode'] == item_data['SeriesEpisode']) or (item['season'] == "" and item['episode'] == "" ) ## for file search, season and episode == "" ): listitem = xbmcgui.ListItem( label=item_data["LanguageName"], label2=item_data["SubFileName"], iconImage=str(int(round(float(item_data["SubRating"]) / 2))), thumbnailImage=item_data["ISO639"]) listitem.setProperty( "sync", ("false", "true")[str(item_data["MatchedBy"]) == "moviehash"]) listitem.setProperty( "hearing_imp", ("false", "true")[int(item_data["SubHearingImpaired"]) != 0]) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s&format=%s" % ( __scriptid__, item_data["ZipDownloadLink"], item_data["IDSubtitleFile"], item_data["SubFileName"], item_data["SubFormat"]) listitems.append(listitem) if (__addon__.getSetting('dualsub_enable') != 'true'): xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False) if (__addon__.getSetting('dualsub_enable') == 'true'): dialog = xbmcgui.Dialog() ret = dialog.multiselect("Choose a subtitle", [i for i in listitems], useDetails=True) if ret and len(ret) > 0: subs = [] for sub in ret: subs.append({ 'ID': search_data[sub]['IDSubtitleFile'], 'link': search_data[sub]['ZipDownloadLink'], 'filename': search_data[sub]['SubFileName'], 'format': search_data[sub]['SubFormat'] }) payload = json.dumps(subs[:2]) payload = urllib.quote(payload) listitem = xbmcgui.ListItem(label2=__language__(32019)) url = "plugin://%s/?action=download&payload=%s" % ( __scriptid__, payload) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)