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 Download(id,url,format,stack=False): subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass" ] if stack: ## we only want XMLRPC download if movie is not in stack, ## you can only retreive multiple subs in zip result = False else: subtitle = os.path.join(__temp__, "%s.%s" %(str(uuid.uuid4()), format)) try: result = OSDBServer().download(id, subtitle) except: log( __name__, "failed to connect to service for subtitle download") return subtitle_list if not result: log( __name__,"Download Using HTTP") zip = os.path.join( __temp__, "OpenSubtitles.zip") f = urllib.urlopen(url) with open(zip, "wb") as subFile: subFile.write(f.read()) subFile.close() xbmc.sleep(500) xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % (zip,__temp__,)).encode('utf-8'), True) for file in xbmcvfs.listdir(zip)[1]: file = os.path.join(__temp__, file) if (os.path.splitext( file )[1] in exts): subtitle_list.append(file) else: subtitle_list.append(subtitle) if xbmcvfs.exists(subtitle_list[0]): return subtitle_list
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: for item_data in search_data: listitem = xbmcgui.ListItem(label=item_data["LanguageName"], label2=item_data["SubFileName"], iconImage=item_data["SubRating"], 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&filename=%s&format=%s&traducator=%s" % (__scriptid__, item_data["ZipDownloadLink"], item_data["SubFileName"], item_data["referer"], item_data["Traducator"] ) #f = open( '/storage/.kodi/temp/files2.py', 'w' ) #f.write( 'url = ' + repr(url) + '\n' ) #f.close() xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)
def Download(id, url, format, stack=False): subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] if stack: ## we only want XMLRPC download if movie is not in stack, ## you can only retreive multiple subs in zip result = False else: subtitle = os.path.join(__temp__, "%s.%s" % (str(uuid.uuid4()), format)) try: result = OSDBServer().download(id, subtitle) except: log(__name__, "failed to connect to service for subtitle download") return subtitle_list if not result: log(__name__, "Download Using HTTP") zip = os.path.join(__temp__, "OpenSubtitles.zip") f = urllib.urlopen(url) with open(zip, "wb") as subFile: subFile.write(f.read()) subFile.close() xbmc.sleep(500) xbmc.executebuiltin(('XBMC.Extract("%s","%s")' % ( zip, __temp__, )).encode('utf-8'), True) for file in xbmcvfs.listdir(zip)[1]: file = os.path.join(__temp__, file) if (os.path.splitext(file)[1] in exts): subtitle_list.append(file) else: subtitle_list.append(subtitle) if xbmcvfs.exists(subtitle_list[0]): return subtitle_list
def Search( item ): 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 subtitles_list = [] if search_data != None: for item_data in search_data: if item_data["ISO639"]: lang_index=0 for user_lang_id in item['3let_language']: if user_lang_id == item_data["ISO639"]: break lang_index+=1 if str(item_data["MatchedBy"]) == "moviehash": sync = True else: sync = False subtitles_list.append({'lang_index' : lang_index, 'filename' : item_data["SubFileName"], 'link' : item_data["ZipDownloadLink"], 'language_name' : item_data["LanguageName"], 'language_flag' : item_data["ISO639"], 'language_id' : item_data["SubLanguageID"], 'ID' : item_data["IDSubtitleFile"], 'rating' : str(int(round(float(item_data["SubRating"])/2))), 'format' : item_data["SubFormat"], 'sync' : sync, 'hearing_imp' : int(item_data["SubHearingImpaired"]) != 0 }) subtitles_list.sort(key=lambda x: [not x['sync'],x['language_name']]) if subtitles_list: for it in subtitles_list: listitem = xbmcgui.ListItem(label=it["language_name"], label2=it["filename"], iconImage=it["rating"], thumbnailImage=it["language_flag"] ) if it["sync"]: listitem.setProperty( "sync", "true" ) else: listitem.setProperty( "sync", "false" ) if it.get("hearing_imp", False): listitem.setProperty( "hearing_imp", "true" ) else: listitem.setProperty( "hearing_imp", "false" ) url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s" % (__scriptid__, it["link"], it["ID"],it["filename"]) 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 Download(link, url, referer, trdtr): subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] log(__name__, "Download Using HTTP") s = requests.Session() ua = 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1' headers = {'User-Agent': ua} referer = 'http://www.titrari.ro/index.php?page=cautare&z1=0&z2=' + referer + '&z3=1&z4=1' s.headers.update({'referer': referer}) link = 'http://www.titrari.ro/get.php?id=' + link file = s.get(link, headers=headers) contentType = file.headers['Content-Disposition'].split(';') Type = 'rar' if contentType[1][-5:] == '.rar"' else 'zip' fname = "%s.%s" % (os.path.join(__temp__, "subtitle"), Type) with open(fname, 'wb') as f: f.write(file.content) extractPath = os.path.join(__temp__, "Extracted") xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (fname, extractPath)) xbmc.sleep(1000) for root, dirs, files in os.walk(extractPath): for file in files: dirfile = os.path.join(root, file) dirfile_with_path_name = normalizeString(os.path.relpath(dirfile, extractPath)) dirname, basename = os.path.split(dirfile_with_path_name) dirname = re.sub(r"[/\\]{1,10}", "-", dirname) dirfile_with_path_name = "(%s) %s" % (dirname, basename) if len(dirname) else basename #new_dirfile = os.path.join(extractPath, safeFilename(dirfile_with_path_name)) if (os.path.splitext(file)[1] in exts): #extension = file[file.rfind('.') + 1:] subtitle_list.append(dirfile) #index += 1 selected = [] #f = open( '/storage/.kodi/temp/files2.py', 'w' ) #f.write( 'url = ' + repr(contentType) + '\n' ) #f.close() if xbmcvfs.exists(subtitle_list[0]): subtitle_list_s = natcasesort(subtitle_list) dialog = xbmcgui.Dialog() sel = dialog.select("%s\n%s" % ('Traducator: ', trdtr), [os.path.basename(x) for x in subtitle_list_s]) if sel >= 0: selected.append(subtitle_list_s[sel]) return selected else: return None else: return None
def Download(link, url, format, trdtr): #headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'} subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] log(__name__, "Download Using HTTP") ua = 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1' req = urllib2.Request(link) req.add_header('User-Agent', ua) a = urllib2.urlopen(link) contentType = a.info()['Content-Disposition'].split(';') b = a.read() Type = 'rar' if contentType[1][-4:] == '.rar' else 'zip' fname = "%s.%s" % (os.path.join(__temp__, "subtitle"), Type) with open(fname, 'wb') as f: f.write(b) extractPath = os.path.join(__temp__, "Extracted") xbmc.executebuiltin("XBMC.Extract(%s, %s)" % (fname, extractPath)) xbmc.sleep(1000) for root, dirs, files in os.walk(extractPath): for file in files: dirfile = os.path.join(root, file) dirfile_with_path_name = normalizeString(os.path.relpath(dirfile, extractPath)) dirname, basename = os.path.split(dirfile_with_path_name) dirname = re.sub(r"[/\\]{1,10}", "-", dirname) dirfile_with_path_name = "(%s) %s" % (dirname, basename) if len(dirname) else basename #new_dirfile = os.path.join(extractPath, safeFilename(dirfile_with_path_name)) if (os.path.splitext(file)[1] in exts): #extension = file[file.rfind('.') + 1:] subtitle_list.append(dirfile) #index += 1 selected = [] #f = open( '/storage/.kodi/temp/files2.py', 'w' ) #f.write( 'url = ' + repr(contentType) + '\n' ) #f.close() if xbmcvfs.exists(subtitle_list[0]): subtitle_list_s = sorted(subtitle_list, key=natural_key) dialog = xbmcgui.Dialog() sel = dialog.select("%s\n%s" % ('Traducator: ', trdtr), [os.path.basename(x) for x in subtitle_list_s]) if sel >= 0: selected.append(subtitle_list_s[sel]) return selected else: return None else: return None
def Download(link, url, format, stack=False): url = re.sub('download', 'descarca', url) url = re.sub('html', 'zip', url) subtitle_list = [] exts = [".srt", ".sub", ".txt", ".smi", ".ssa", ".ass"] log(__name__, "Download Using HTTP") s = requests.Session() ua = 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1' headers = {'User-Agent': ua} if ((__addon__.getSetting("OSuser") and __addon__.getSetting("OSpass"))): payload = { 'l_username': __addon__.getSetting("OSuser"), 'l_password': __addon__.getSetting("OSpass") } s.post('http://www.regielive.ro/membri/login.html', data=payload, headers=headers) else: s.post('http://www.regielive.ro', headers=headers) f = s.get(url, headers=headers) try: archive = ZipFile(StringIO(f.content), 'r') except: return subtitle_list files = archive.namelist() files.sort() index = 1 for file in files: contents = archive.read(file) if (os.path.splitext(file)[1] in exts): extension = file[file.rfind('.') + 1:] if len(files) == 1: dest = os.path.join(__temp__, "%s.%s" % (str(uuid.uuid4()), extension)) else: dest = os.path.join( __temp__, "%s.%d.%s" % (str(uuid.uuid4()), index, extension)) f = open(dest, 'wb') f.write(contents) f.close() subtitle_list.append(dest) index += 1 if xbmcvfs.exists(subtitle_list[0]): return subtitle_list
if (params[len(params)-1]=='/'): params=params[0:len(params)-2] pairsofparams=cleanedparams.split('&') param={} for i in range(len(pairsofparams)): splitparams={} splitparams=pairsofparams[i].split('=') if (len(splitparams))==2: param[splitparams[0]]=splitparams[1] return param params = get_params() if params['action'] == 'search': log( __name__, "action 'search' called") item = {} item['temp'] = False item['rar'] = False item['year'] = xbmc.getInfoLabel("VideoPlayer.Year") # Year item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season")) # Season item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode")) # Episode item['tvshow'] = normalizeString(xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) # Show item['title'] = normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle"))# try to get original title item['file_original_path'] = urllib.unquote(xbmc.Player().getPlayingFile().decode('utf-8'))# Full path of a playing file item['3let_language'] = [] #['scc','eng'] for lang in urllib.unquote(params['languages']).decode('utf-8').split(","): if lang == "Portuguese (Brazil)": lan = "pob" else:
params = params[0:len(params) - 2] pairsofparams = cleanedparams.split('&') param = {} for i in range(len(pairsofparams)): splitparams = {} splitparams = pairsofparams[i].split('=') if (len(splitparams)) == 2: param[splitparams[0]] = splitparams[1] return param params = get_params() if params['action'] == 'search' or params['action'] == 'manualsearch': log(__name__, "action '%s' called" % params['action']) item = {} item['temp'] = False item['rar'] = False item['mansearch'] = False item['year'] = xbmc.getInfoLabel("VideoPlayer.Year") # Year item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season")) # Season item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode")) # Episode item['tvshow'] = normalizeString( xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) # Show item['title'] = normalizeString( xbmc.getInfoLabel( "VideoPlayer.OriginalTitle")) # try to get original title item['file_original_path'] = urllib.unquote( xbmc.Player().getPlayingFile().decode( 'utf-8')) # Full path of a playing file
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)
if (params[len(params)-1]=='/'): params=params[0:len(params)-2] pairsofparams=cleanedparams.split('&') param={} for i in range(len(pairsofparams)): splitparams={} splitparams=pairsofparams[i].split('=') if (len(splitparams))==2: param[splitparams[0]]=splitparams[1] return param params = get_params() if params['action'] == 'search' or params['action'] == 'manualsearch': log( __name__, "action '%s' called" % params['action']) item = {} item['temp'] = False item['rar'] = False item['mansearch'] = False item['year'] = xbmc.getInfoLabel("VideoPlayer.Year") # Year item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season")) # Season item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode")) # Episode item['tvshow'] = normalizeString(xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) # Show item['title'] = normalizeString(xbmc.getInfoLabel("VideoPlayer.OriginalTitle"))# try to get original title item['file_original_path'] = xbmc.Player().getPlayingFile().decode('utf-8') # Full path of a playing file item['3let_language'] = [] #['scc','eng'] PreferredSub = params.get('preferredlanguage') if 'searchstring' in params: item['mansearch'] = True
params = params[0:len(params) - 2] pairsofparams = cleanedparams.split('&') param = {} for i in range(len(pairsofparams)): splitparams = {} splitparams = pairsofparams[i].split('=') if (len(splitparams)) == 2: param[splitparams[0]] = splitparams[1] return param params = get_params() if params['action'] == 'search': log(__name__, "action 'search' called") item = {} item['temp'] = False item['rar'] = False item['year'] = xbmc.getInfoLabel("VideoPlayer.Year") # Year item['season'] = str(xbmc.getInfoLabel("VideoPlayer.Season")) # Season item['episode'] = str(xbmc.getInfoLabel("VideoPlayer.Episode")) # Episode item['tvshow'] = normalizeString( xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) # Show item['title'] = normalizeString( xbmc.getInfoLabel( "VideoPlayer.OriginalTitle")) # try to get original title item['file_original_path'] = urllib.unquote( xbmc.Player().getPlayingFile().decode( 'utf-8')) # Full path of a playing file item['3let_language'] = [] #['scc','eng']
def Search(item): 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 subtitles_list = [] if search_data != None: for item_data in search_data: if item_data["ISO639"]: lang_index = 0 for user_lang_id in item['3let_language']: if user_lang_id == item_data["ISO639"]: break lang_index += 1 if str(item_data["MatchedBy"]) == "moviehash": sync = True else: sync = False subtitles_list.append({ 'lang_index': lang_index, 'filename': item_data["SubFileName"], 'link': item_data["ZipDownloadLink"], 'language_name': item_data["LanguageName"], 'language_flag': item_data["ISO639"], 'language_id': item_data["SubLanguageID"], 'ID': item_data["IDSubtitleFile"], 'rating': str(int(round(float(item_data["SubRating"]) / 2))), 'format': item_data["SubFormat"], 'sync': sync, 'hearing_imp': int(item_data["SubHearingImpaired"]) != 0 }) subtitles_list.sort(key=lambda x: [not x['sync'], x['language_name']]) if subtitles_list: for it in subtitles_list: listitem = xbmcgui.ListItem(label=it["language_name"], label2=it["filename"], iconImage=it["rating"], thumbnailImage=it["language_flag"]) if it["sync"]: listitem.setProperty("sync", "true") else: listitem.setProperty("sync", "false") if it.get("hearing_imp", False): listitem.setProperty("hearing_imp", "true") else: listitem.setProperty("hearing_imp", "false") url = "plugin://%s/?action=download&link=%s&ID=%s&filename=%s" % ( __scriptid__, it["link"], it["ID"], it["filename"]) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)