本文整理汇总了Python中meta.utils.text.to_utf8函数的典型用法代码示例。如果您正苦于以下问题:Python to_utf8函数的具体用法?Python to_utf8怎么用?Python to_utf8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_utf8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: people_list_show_people
def people_list_show_people(id, source, fanart):
items = []
try:
if source == "imdb":
people = trakt.get_show_people(id)
else:
xbmcgui.Dialog().ok("Error", "No cast info found")
return plugin.finish(items=[])
except:
xbmcgui.Dialog().ok("Error", "No cast info found")
return plugin.finish(items=[])
if "cast" in people:
for actor in people["cast"]:
context_menu = [
(
"Convert to bob_xml",
"RunPlugin({0})".format(
plugin.url_for("bob_convert_person_to_xml", trakt_id=actor["person"]["ids"]["trakt"]))
)
]
image = get_person_artwork(actor)
label = "{0} ({1})".format(to_utf8(actor["person"]["name"]), to_utf8(actor["character"]))
info = actor["person"]["biography"]
items.append({'label': label,
'path': plugin.url_for("people_list_person_select", id=actor["person"]["ids"]["trakt"],
name=to_utf8(actor["person"]["name"])),
'info': info,
'thumbnail': image,
'poster': image,
'context_menu': context_menu,
'icon': "DefaultVideo.png",
'properties': {'fanart_image': fanart},
})
return plugin.finish(items=items)
示例2: get_episode_parameters
def get_episode_parameters(show, season, episode):
import_tmdb()
if season in show and episode in show[season]:
season_obj = show[season]
episode_obj = show[season][episode]
else:
return
# Get parameters
parameters = {'id': show['id'], 'season': season, 'episode': episode}
show_info = get_tvshow_metadata_tvdb(show, banners=True)
network = show.get('network', '')
parameters['network'] = network
if network:
parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip()
else:
parameters['network_clean'] = network
parameters['showname'] = show['seriesname']
parameters['clearname'] = re.sub("(\(.*?\))", "", show['seriesname']).strip()
parameters['urlname'] = urllib.quote(to_utf8(parameters['clearname']))
articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the ']
parameters['sortname'] = parameters['clearname']
for article in articles:
if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'')
parameters['shortname'] = parameters['clearname'][1:-1]
try:
parameters['absolute_number'] = int(episode_obj.get('absolute_number'))
except:
parameters['absolute_number'] = "na"
parameters['title'] = episode_obj.get('episodename', str(episode))
parameters['urltitle'] = urllib.quote(to_utf8(parameters['title']))
parameters['firstaired'] = episode_obj.get('firstaired')
parameters['year'] = show.get('year', 0)
parameters['imdb'] = show.get('imdb_id', '')
parameters['epid'] = episode_obj.get('id')
# parameters['score'] = show['rating']
# parameters['vote_count'] = show['ratingcount']
# parameters['runtime'] = show['runtime']
# parameters['duration'] = int(show['runtime']) * 60
# parameters['plot'] = show['overview']
# parameters['banner'] = "http://thetvdb.com/banners/graphical/" + str(show['id']) + "-g2.jpg"
parameters['poster'] = "http://thetvdb.com/banners/posters/" + str(show['id']) + "-2.jpg"
parameters['fanart'] = "http://thetvdb.com/banners/fanart/original/" + str(show['id']) + "-2.jpg"
parameters['thumbnail'] = "http://thetvdb.com/banners/episodes/" + str(show['id']) + "/" + str(parameters['epid']) + ".jpg"
# parameters['trailer'] = "plugin://script.extendedinfo/?info=playtvtrailer&tvdb_id=" + str(show['id'])
try:
genre = [x for x in show['genre'].split('|') if not x == '']
except:
genre = []
parameters['genre'] = " / ".join(genre)
is_anime = False
if parameters['absolute_number'] and parameters['absolute_number'] != '0' and "animation" in parameters['genre'].lower():
tmdb_results = tmdb.Find(show['id']).info(external_source="tvdb_id") or {}
for tmdb_show in tmdb_results.get("tv_results", []):
if "JP" in tmdb_show['origin_country']:
is_anime = True
if is_anime:
parameters['name'] = u'{showname} {absolute_number}'.format(**parameters)
else:
parameters['name'] = u'{showname} S{season:02d}E{episode:02d}'.format(**parameters)
return parameters
示例3: tv_play_by_name_only
def tv_play_by_name_only(name, lang):
tvdb_id = get_tvdb_id_from_name(name, lang)
if tvdb_id:
season = None
episode = None
show = tv_tvshow(tvdb_id)
while season is None or episode is None: # don't exit completely if pressing back from episode selector
selection = dialogs.select(_("Choose season"), [item["label"] for item in show])
if selection != -1:
season = show[selection]["info"]["season"]
season = int(season)
else:
return
items = []
episodes = tv_season(tvdb_id, season)
for item in episodes:
label = "S{0}E{1} - {2}".format(item["info"]["season"], item["info"]["episode"],
to_utf8(item["info"]["title"]))
if item["info"]["plot"] is not None:
label += " - {0}".format(to_utf8(item["info"]["plot"]))
items.append(label)
selection = dialogs.select(_("Choose episode"), items)
if selection != -1:
episode = episodes[selection]["info"]["episode"]
episode = int(episode)
tv_play(tvdb_id, season, episode, "default")
示例4: music_add_artist_to_library
def music_add_artist_to_library(artist_name):
import math
library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER))
album_results = lastfm.get_artist_top_albums(artist_name)
total_albums = len(album_results)
index = 0
pDialog = xbmcgui.DialogProgress()
pDialog.create(
"[COLOR ff0084ff]M[/COLOR]etalli[COLOR ff0084ff]Q[/COLOR]",
_("{0} {1} {2}").format(_("Adding"), artist_name, _("to library")),
)
for album in album_results["album"]:
album_name = to_utf8(album["name"])
percent_done = int(math.floor((float(index) / total_albums) * 100))
pDialog.update(
percent_done, _("{0} {1} - {2} {3}").format(_("Adding"), artist_name, album_name, _("to library"))
)
track_results = lastfm.get_album_info(artist_name, album_name)
for track in track_results["tracks"]["track"]:
if pDialog.iscanceled():
pDialog.update(0)
return
track_name = to_utf8(track["name"])
add_music_to_library(library_folder, artist_name, album_name, track_name)
index += 1
pDialog.update(0)
scan_library(type="music")
示例5: get_movie_parameters
def get_movie_parameters(movie):
parameters = {}
parameters['date'] = movie['release_date']
parameters['year'] = parse_year(movie['release_date'])
parameters['id'] = movie['id']
parameters['imdb'] = movie['imdb_id']
parameters['title'] = movie['title']
parameters['urltitle'] = urllib.quote(to_utf8(parameters['title']))
parameters['sorttitle'] = parameters['title']
articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the ']
for article in articles:
if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'')
parameters['shorttitle'] = parameters['title'][1:-1]
if "movie" in str(parameters['sorttitle']).lower(): parameters['sortesttitle'] = str(parameters['sorttitle']).lower().replace(' movie','')
elif "movi" in str(parameters['sorttitle']).lower(): parameters['sortesttitle'] = str(parameters['sorttitle']).lower().replace(' movi','')
else: parameters['sortesttitle'] = parameters['sorttitle']
parameters['original_title'] = movie['original_title']
parameters['name'] = u'%s (%s)' % (parameters['title'], parameters['year'])
parameters['urlname'] = urllib.quote(to_utf8(parameters['name']))
# parameters['score'] = movie['vote_average']
# parameters['votes'] = movie['vote_count']
# parameters['runtime'] = movie['runtime']
# parameters['duration'] = int(movie['runtime']) * 60
# parameters['plot'] = movie['overview']
parameters['poster'] = "https://image.tmdb.org/t/p/original/" + str(movie['poster_path'])
parameters['fanart'] = "https://image.tmdb.org/t/p/original/" + str(movie['backdrop_path'])
# parameters['trailer'] = "plugin://script.extendedinfo/?info=playtrailer&id=" + str(movie['imdb_id'])
return parameters
示例6: music_artist_tracks
def music_artist_tracks(artist_name, page):
artist_name = to_utf8(artist_name)
results = lastfm.get_artist_top_tracks(artist_name, page)
items = []
for track in results["track"]:
large_image = track["image"][-1]["#text"]
track_name = to_utf8(track["name"])
context_menu = [
(
_("Context player"),
"PlayMedia({0})".format(
plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context")
),
),
(
_("Add to library"),
"RunPlugin({0})".format(
plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name)
),
),
(
_("Musicvideo"),
"PlayMedia({0})".format(
plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode="default")
),
),
]
if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE) == "audio":
item = {
"label": track_name,
"path": plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name),
"thumbnail": large_image,
"icon": "DefaultMusic.png",
"poster": large_image,
"info_type": "music",
"context_menu": context_menu,
}
else:
item = {
"label": track_name,
"path": plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name),
"thumbnail": large_image,
"icon": "DefaultMusicVideo.png",
"poster": large_image,
"info_type": "music",
"context_menu": context_menu,
}
items.append(item)
if results["@attr"]["totalPages"] > page:
items.append(
{
"label": _("Next >>"),
"icon": get_icon_path("item_next"),
"path": plugin.url_for(music_artist_tracks, artist_name=artist_name, page=int(page) + 1),
}
)
return items
示例7: music_artist_album_tracks
def music_artist_album_tracks(artist_name, album_name):
artist_name = to_utf8(artist_name)
album_name = to_utf8(album_name)
results = lastfm.get_album_info(artist_name, album_name)
items = []
for track in results["tracks"]["track"]:
track_name = to_utf8(track["name"])
track_number = track["@attr"]["rank"]
image = results["image"][-1]["#text"]
context_menu = [
(
_("Context player"),
"PlayMedia({0})".format(
plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context")
),
),
(
_("Add to library"),
"RunPlugin({0})".format(
plugin.url_for(
"music_add_to_library", artist_name=artist_name, track_name=track_name, album_name=album_name
)
),
),
(
_("Musicvideo"),
"RunPlugin({0})".format(
plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode="default")
),
),
]
if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE) == "audio":
item = {
"label": "{0}. {1}".format(track_number, track_name),
"path": plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name),
"thumbnail": image,
"icon": "DefaultMusic.png",
"poster": image,
"info_type": "music",
"context_menu": context_menu,
}
else:
item = {
"label": "{0}. {1}".format(track_number, track_name),
"path": plugin.url_for(
"music_play_video", artist_name=artist_name, album_name=album_name, track_name=track_name
),
"thumbnail": image,
"icon": "DefaultMusicVideo.png",
"poster": image,
"info_type": "music",
"context_menu": context_menu,
}
items.append(item)
return items
示例8: music_artist_tracks
def music_artist_tracks(artist_name, page):
artist_name = to_utf8(artist_name)
results = lastfm.get_artist_top_tracks(artist_name, page)
items = []
for track in results["track"]:
large_image = track["image"][-1]["#text"]
track_name = to_utf8(track["name"])
context_menu = [
(
_("Context player"),
"PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name,
track_name=track_name, mode='context'))
),
(
_("Scan item to library"),
"RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name,
track_name=track_name))
),
(
_("Musicvideo"),
"PlayMedia({0})".format(plugin.url_for("music_play_video", artist_name=artist_name,
track_name=track_name, mode='default'))
)
]
if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE, unicode) == "audio":
item = {
'label': track_name,
'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name),
'thumbnail': large_image,
'icon': "DefaultMusic.png",
'poster': large_image,
'info_type': 'music',
'context_menu': context_menu,
}
else:
item = {
'label': track_name,
'path': plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name),
'thumbnail': large_image,
'icon': "DefaultMusicVideo.png",
'poster': large_image,
'info_type': 'music',
'context_menu': context_menu,
}
items.append(item)
if results["@attr"]["totalPages"] > page:
items.append({
'label': _("Next >>"),
'icon': get_icon_path("item_next"),
'path': plugin.url_for("music_artist_tracks", artist_name=artist_name, page=int(page) + 1)
})
if FORCE == True: plugin.set_view_mode(VIEW); return items
else: return items
示例9: music_search_track_term
def music_search_track_term(term, page):
search_results = lastfm.search_track(term, page)
tracks = search_results["trackmatches"]["track"]
items_per_page = search_results["opensearch:itemsPerPage"]
start_index = search_results["opensearch:startIndex"]
total_results = search_results["opensearch:totalResults"]
items = []
for track in tracks:
large_image = track["image"][-1]["#text"]
track_name = to_utf8(track["name"])
artist_name = to_utf8(track["artist"])
context_menu = [
(
_("Context player"),
"PlayMedia({0})".format(
plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name, mode="context")
),
),
(
_("Add to library"),
"RunPlugin({0})".format(
plugin.url_for("music_add_to_library", artist_name=artist_name, track_name=track_name)
),
),
(
_("Musicvideo"),
"RunPlugin({0})".format(
plugin.url_for("music_play_video", artist_name=artist_name, track_name=track_name, mode="context")
),
),
]
item = {
"label": "{0} - {1}".format(artist_name, track_name),
"path": plugin.url_for(music_play_audio, artist_name=artist_name, track_name=track_name),
"thumbnail": large_image,
"icon": "DefaultMusic.png",
"poster": large_image,
"info": {"artist": artist_name},
"info_type": "music",
"context_menu": context_menu,
}
items.append(item)
if start_index + items_per_page < total_results:
items.append(
{
"label": _("Next >>"),
"icon": get_icon_path("item_next"),
"path": plugin.url_for(music_search_track_term, term=term, page=int(page) + 1),
}
)
return items
示例10: music_search_track_term
def music_search_track_term(term, page):
search_results = lastfm.search_track(term, page)
tracks = search_results["trackmatches"]["track"]
items_per_page = search_results["opensearch:itemsPerPage"]
start_index = search_results["opensearch:startIndex"]
total_results = search_results["opensearch:totalResults"]
items = []
for track in tracks:
large_image = track["image"][-1]["#text"]
track_name = to_utf8(track["name"])
artist_name = to_utf8(track["artist"])
context_menu = [
(
"{0} {1} {2}...".format(_("Select"), _("Audio").lower(), _("Stream").lower()),
"PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name,
track_name=track_name, mode='context'))
),
(
_("Scan item to library"),
"RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name,
track_name=track_name))
),
(
"{0} {1} {2}...".format(_("Select"), _("Video").lower(), _("Stream").lower()),
"RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name,
track_name=track_name, mode='context'))
)
]
item = {
'label': "{0} - {1}".format(artist_name, track_name),
'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name),
'thumbnail': large_image,
'icon': "DefaultMusic.png",
'poster': large_image,
'info': {
'artist': artist_name,
},
'info_type': 'music',
'context_menu': context_menu
}
items.append(item)
if start_index + items_per_page < total_results:
items.append({
'label': _("Next >>"),
'icon': get_icon_path("item_next"),
'path': plugin.url_for("music_search_track_term", term=term, page=int(page) + 1)
})
if FORCE == True: plugin.set_view_mode(VIEW); return items
else: return items
示例11: music_artist_album_tracks
def music_artist_album_tracks(artist_name, album_name):
artist_name = to_utf8(artist_name)
album_name = to_utf8(album_name)
results = lastfm.get_album_info(artist_name, album_name)
items = []
for track in results["tracks"]["track"]:
track_name = to_utf8(track["name"])
track_number = track["@attr"]["rank"]
image = results["image"][-1]["#text"]
context_menu = [
(
"{0} {1} {2}...".format(_("Select"), _("Audio").lower(), _("Stream").lower()),
"PlayMedia({0})".format(plugin.url_for("music_play_audio", artist_name=artist_name,
track_name=track_name, mode='context'))
),
(
_("Scan item to library"),
"RunPlugin({0})".format(plugin.url_for("music_add_to_library", artist_name=artist_name,
track_name=track_name, album_name=album_name))
),
(
"{0} {1} {2}...".format(_("Select"), _("Video").lower(), _("Stream").lower()),
"RunPlugin({0})".format(plugin.url_for("music_play_video", artist_name=artist_name,
track_name=track_name, mode='default'))
)
]
if plugin.get_setting(SETTING_PREFERRED_MUSIC_TYPE, unicode) == "audio":
item = {
'label': "{0}. {1}".format(track_number, track_name),
'path': plugin.url_for("music_play_audio", artist_name=artist_name, track_name=track_name),
'thumbnail': image,
'icon': "DefaultMusic.png",
'poster': image,
'info_type': 'music',
'context_menu': context_menu,
}
else:
item = {
'label': "{0}. {1}".format(track_number, track_name),
'path': plugin.url_for("music_play_video", artist_name=artist_name, album_name=album_name, track_name=track_name),
'thumbnail': image,
'icon': "DefaultMusicVideo.png",
'poster': image,
'info_type': 'music',
'context_menu': context_menu,
}
items.append(item)
if FORCE == True: plugin.set_view_mode(VIEW); return items
else: return items
示例12: lists_search_for_lists_term
def lists_search_for_lists_term(term, page):
lists, pages = trakt.search_for_list(term, page)
page = int(page)
pages = int(pages)
items = []
for list in lists:
if "list" in list:
list_info = list["list"]
else:
continue
name = list_info["name"]
user = list_info["username"]
slug = list_info["ids"]["slug"]
total = list_info["item_count"]
info = {}
info['title'] = name
if "description" in list_info: info["plot"] = list_info["description"]
else: info["plot"] = _("No description available")
if user != None and total != None and total != 0:
items.append({
'label': "{0} - {1} ({2})".format(to_utf8(name), to_utf8(user), total),
'path': plugin.url_for("lists_trakt_show_list", user=user, slug=slug),
'context_menu': [
(
_("Scan item to library"),
"RunPlugin({0})".format(plugin.url_for("lists_trakt_add_all_to_library", user=user, slug=slug))
),
(
"{0} ({1})".format(_("Play"), _("Random").lower()),
"RunPlugin({0})".format(plugin.url_for("lists_trakt_play_random", user=user, slug=slug))
)
],
'info': info,
'icon': get_icon_path("traktlikedlists"),
'thumbnail': get_icon_path("traktlikedlists"),
})
fanart = plugin.addon.getAddonInfo('fanart')
for item in items:
item['properties'] = {'fanart_image' : get_background_path()}
if pages > page:
items.append({
'label': _("Next page").format() + " >> (%s/%s)" % (page + 1, pages),
'path': plugin.url_for("lists_search_for_lists_term", term = term, page=page + 1),
'icon': get_icon_path("item_next"),
'thumbnail': get_icon_path("item_next"),
})
if FORCE == True: return plugin.finish(items=items, sort_methods=SORT, view_mode=VIEW)
else: return plugin.finish(items=items, sort_methods=SORT)
示例13: lists_search_for_lists_term
def lists_search_for_lists_term(term,page):
lists, pages = trakt.search_for_list(term, page)
page = int(page)
pages = int(pages)
items = []
for list in lists:
if "list" in list:
list_info = list["list"]
else:
continue
name = list_info["name"]
user = list_info["username"]
slug = list_info["ids"]["slug"]
info = {}
info['title'] = name
if "description" in list_info:
info["plot"] = list_info["description"]
else:
info["plot"] = _("No description available")
if user != None:
items.append({
'label': "{0} {1} {2}".format(to_utf8(name), _("by"), to_utf8(user)),
'path': plugin.url_for("lists_trakt_show_list", user=user, slug=slug),
'context_menu': [
(
_("Add list to library"),
"RunPlugin({0})".format(plugin.url_for("lists_trakt_add_all_to_library", user=user, slug=slug))
)
],
'info': info,
'icon': get_icon_path("traktlikedlists"),
})
fanart = plugin.addon.getAddonInfo('fanart')
for item in items:
item['properties'] = {'fanart_image' : get_background_path()}
if (len(items) < plugin.get_setting(SETTING_TRAKT_PER_PAGE, int) and pages > page):
page = page + 1
results = lists_search_for_lists_term(term, page)
return items + results
if pages > page:
items.append({
'label': _("Next page").format() + " >> (%s/%s)" % (page + 1, pages),
'path': plugin.url_for("lists_search_for_lists_term", term = term, page=page + 1),
'icon': get_icon_path("traktlikedlists"),
})
if FORCE == True: return plugin.finish(items=items, sort_methods=SORT, view_mode=VIEW)
else: return plugin.finish(items=items, sort_methods=SORT)
示例14: music_add_album_to_library
def music_add_album_to_library(artist_name, album_name):
library_folder = setup_library(plugin.get_setting(SETTING_MUSIC_LIBRARY_FOLDER, unicode))
results = lastfm.get_album_info(artist_name, album_name)
for track in results["tracks"]["track"]:
track_name = to_utf8(track["name"])
add_music_to_library(library_folder, artist_name, album_name, track_name)
scan_library(type="music")
示例15: music_top_artists_by_country
def music_top_artists_by_country(country, page):
results = lastfm.get_top_artists_by_country(country, page)
artists = results["topartists"]["artist"]
items = []
for artist in artists:
large_image = artist["image"][-1]["#text"]
name = to_utf8(artist["name"])
context_menu = [
(
_("Add to library"),
"RunPlugin({0})".format(plugin.url_for("music_add_artist_to_library", artist_name=name)),
)
]
item = {
"label": name,
"path": plugin.url_for(music_artist_albums, artist_name=name),
"thumbnail": large_image,
"icon": "DefaultMusic.png",
"poster": large_image,
"info": {"artist": name},
"info_type": "music",
"context_menu": context_menu,
}
items.append(item)
return items