def is_rar_enabled():
     q = '{"jsonrpc": "2.0", "method": "Addons.GetAddonDetails", "params": {"addonid": "vfs.rar", "properties": ["enabled"]}, "id": 0 }'
     r = json.loads(xbmc.executeJSONRPC(q))
     log(xbmc.executeJSONRPC(q))
     if "result" in r and "addon" in r["result"]:
         return r['result']["addon"]["enabled"]
     return True
def Search(item):  # standard input

    enable_rar()

    try:
        languages = []
        subtitles = LTV.Search(title=item['title'],
                               tvshow=item['tvshow'],
                               year=item['year'],
                               season=item['season'],
                               episode=item['episode'],
                               lang=item['languages'],
                               imdb=item['imdb'])
    except:
        import traceback
        log("\n%s" % traceback.format_exc(), "ERROR")
        return 1

    if subtitles:
        for it in subtitles:
            if it['type'] == "destaque":
                label = "[COLOR FFDE7B18]%s[/COLOR]" % it["filename"]
            else:
                label = it["filename"]

            listitem = xbmcgui.ListItem(
                label=it["language_name"],
                label2=label,
                iconImage=str(int(round(float(it["rating"]) / 2))),
                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")
            pack = "true" if it['type'] == "pack" else "false"
            url = "plugin://%s/?action=download&download_url=%s&filename=%s&pack=%s&lang=%s" % (
                __scriptid__, it["url"],
                os.path.basename(
                    item["file_original_path"]), pack, it["language_name"])

            xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                        url=url,
                                        listitem=listitem,
                                        isFolder=False)

    if item['original_title'] != "true":
        listitem = xbmcgui.ListItem(label="",
                                    label2=__language__(32011).encode("utf-8"),
                                    iconImage="",
                                    thumbnailImage="")
        searchstring = "&searchstring=%s" % item[
            'searchstring'] if "searchstring" in item else ""
        url = "plugin://%s/?action=search&original_title=true&languages=%s%s" % (
            __scriptid__, urllib.quote(",".join(
                item["languages"])), urllib.quote(searchstring))
        xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                    url=url,
                                    listitem=listitem,
                                    isFolder=False)
    if not is_rar_enabled():
        xbmc.executeJSONRPC(
            '{"jsonrpc": "2.0", "method": "Addons.SetAddonEnabled", "params": {"addonid": "vfs.rar", "enabled": true} }'
        )
        time.sleep(1)
        if not is_rar_enabled():
            dialog = xbmcgui.Dialog()
            ok = dialog.ok(
                __language__(32012).encode("utf-8"),
                __language__(32013).encode("utf-8"), " ",
                __language__(32014).encode("utf-8"))


params = get_params()
log("Version: %s" % __version__)
log("Action '%s' called" % params['action'])

if params['action'] == 'search' or params['action'] == 'manualsearch':
    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(