Python xbmc 模块,convertLanguage() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用xbmc.convertLanguage()

项目:service.subtitles.brokensubs    作者:iamninja    | 项目源码 | 文件源码
def get_languages(params, lang_format = 2):
    """
    Get the requested languages the user want to search (3 letter format)

    Args:
        params: The passed parameters dict.
        lang_format: 0 to get full language name
            1 to get two letter code (ISO 639-1)
            2 to get three letter code (ISO 639-2/T or ISO 639-2/B) (default)

    Returns:
        An array with the requested languages, e.g. ['scc','eng']
    """
    langs = []  # ['scc','eng']
    for lang in urllib.unquote(params['languages']).decode('utf-8').split(","):
        if lang_format == 0:
            # Full language name
            langs.append(lang)
        elif lang_format == 1:
            # 2 letter format
            langs.append(xbmc.convertLanguage(lang, xbmc.ISO_639_1))
        else:
            # 3 letter format
            langs.append(xbmc.convertLanguage(lang, xbmc.ISO_639_2))
    return langs
项目:service.subtitles.brokensubs    作者:iamninja    | 项目源码 | 文件源码
def append_subtitle(subname, lang_name, language, params, sync=False, h_impaired=False):
    """Add the subtitle to the list of subtitles to show"""
    listitem = xbmcgui.ListItem(
        # Languange name to display under the lang logo (for example english)
        label=lang_name,
        # Subtitle name (for example 'Lost 1x01 720p')
        label2=subname,
        # Languange 2 letter name (for example en)
        thumbnailImage=xbmc.convertLanguage(language, xbmc.ISO_639_1))

    # Subtitles synced with the video
    listitem.setProperty("sync", 'true' if sync else 'false')
    # Hearing impaired subs
    listitem.setProperty("hearing_imp", 'true' if h_impaired else 'false')

    # Create the url to the plugin that will handle the subtitle download
    url = "plugin://{url}/?{params}".format(
        url=SCRIPT_ID, params=urllib.urlencode(params))
    # Add the subtitle to the list
    xbmcplugin.addDirectoryItem(
        handle=HANDLE, url=url, listitem=listitem, isFolder=False)
项目:service.subtitles.brokensubs    作者:iamninja    | 项目源码 | 文件源码
def search(info, languages):
    """Add subtitles to the list using information gathered with get_info and get_languages"""
    logging.debug("---TUCAN---")
    logging.debug(info)
    url = addictedutils.build_show_url(
        addictedutils.get_show_id(info['tvshow']),
        info['season'],
        addictedutils.build_language_code_string(languages))
    logging.debug(url)
    subs = addictedutils.subs_array(url, info)
    #logging.debug(subs)
    for sub in subs:
        sub_name = sub['showTitle'] + " " + sub['season'] + "x" + sub['episode'] + " " + sub['version']
        sub_params = {
            "action": "download-addicted",
            "link": sub['link'],
            "name": sub_name
        }
        append_subtitle(
            sub_name,
            sub['lang'],
            xbmc.convertLanguage(sub['lang'], xbmc.ISO_639_2),
            sub_params,
            sub['sync'],
            sub['himp'])

    #addictedutils.get_details_from_player()
项目:service.subtitles.brokensubs    作者:iamninja    | 项目源码 | 文件源码
def create_subs_list(subs):
  for sub in subs:
    filename = "[" + str(sub["version"].encode('utf8')) + "]" + str(sub["showTitle"].encode('utf8')) + " - " + str(sub["episodeTitle"].encode('utf8')) + " " + "S" + str(sub["season"]) + "E" + str(format(int(sub["episode"]), "02d"))
    listitem = xbmcgui.ListItem(label = sub["lang"],
                                label2  = filename,
                                iconImage = "",
                                thumbnailImage = xbmc.convertLanguage(sub['lang'], xbmc.ISO_639_1))
    listitem.setProperty("hearing_imp", sub["hi"])
    url = u'plugin://' + __scriptid__ + u'/?action=download&link=' + sub["link"] + u'&filename=' + filename.decode('utf8')
    # url = u'plugin://%s/?action=download&link=%s&filename=%s' % (__scriptid__.encode('utf8'), sub["link"].encode('utf8'), str(filename.encode('utf8')))
    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=listitem,isFolder=False)