def search(item): helper = SubsHelper() subtitles_list = helper.get_subtitle_list(item) 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&language=%s" % ( __scriptid__, it["link"], it["id"], it["filename"], it["language_flag"]) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=url, listitem=listitem, isFolder=False)
def download(id, sub_id, filename, language): subtitle_list = [] exts = [".srt", ".sub"] filename = os.path.join(__temp__, "%s.%s.srt" % (filename, language)) helper = SubsHelper() helper.download(id, sub_id, filename) for file in xbmcvfs.listdir(__temp__)[1]: full_path = os.path.join(__temp__, file) if os.path.splitext(full_path)[1] in exts: subtitle_list.append(full_path) return subtitle_list
item['episode'] = item['episode'][-1:] if item['file_original_path'].find("http") > -1: item['temp'] = True elif item['file_original_path'].find("rar://") > -1: item['rar'] = True item['file_original_path'] = os.path.dirname(item['file_original_path'][6:]) elif item['file_original_path'].find("stack://") > -1: stackPath = item['file_original_path'].split(" , ") item['file_original_path'] = stackPath[0][8:] log("%s" % item) search(item) elif params['action'] == 'download': ## we pickup all our arguments sent from def search() subs = download(params["id"], params["sub_id"], params["filename"], params["language"]) ## we can return more than one subtitle for multi CD versions, for now we are still working out how to handle that in XBMC core for sub in subs: listitem = xbmcgui.ListItem(label=sub) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=sub, listitem=listitem, isFolder=False) elif params['action'] == 'login': helper = SubsHelper() helper.login(True) __addon__.openSettings() xbmcplugin.endOfDirectory(int(sys.argv[1])) ## send end of directory to XBMC