def get(version):
try:
import xbmc,xbmcgui,xbmcaddon,xbmcvfs
f = xbmcvfs.File(xbmcaddon.Addon().getAddonInfo('changelog'))
text = f.read() ; f.close()
label = '%s - %s' % (xbmc.getLocalizedString(24054), xbmcaddon.Addon().getAddonInfo('name'))
id = 10147
xbmc.executebuiltin('ActivateWindow(%d)' % id)
xbmc.sleep(100)
win = xbmcgui.Window(id)
retry = 50
while (retry > 0):
try:
xbmc.sleep(10)
win.getControl(1).setLabel(label)
win.getControl(5).setText(text)
retry = 0
except:
retry -= 1
return '1'
except:
return '1'
python类getLocalizedString()的实例源码
def get(version):
try:
import xbmc,xbmcgui,xbmcaddon,xbmcvfs
f = xbmcvfs.File(xbmcaddon.Addon().getAddonInfo('changelog'))
text = f.read() ; f.close()
label = '%s - %s' % (xbmc.getLocalizedString(24054), xbmcaddon.Addon().getAddonInfo('name'))
id = 10147
xbmc.executebuiltin('ActivateWindow(%d)' % id)
xbmc.sleep(100)
win = xbmcgui.Window(id)
retry = 50
while (retry > 0):
try:
xbmc.sleep(10)
win.getControl(1).setLabel(label)
win.getControl(5).setText(text)
retry = 0
except:
retry -= 1
return '1'
except:
return '1'
def get(version):
try:
import xbmc,xbmcgui,xbmcaddon,xbmcvfs
f = xbmcvfs.File(xbmcaddon.Addon().getAddonInfo('changelog'))
text = f.read() ; f.close()
label = '%s - %s' % (xbmc.getLocalizedString(24054), xbmcaddon.Addon().getAddonInfo('name'))
id = 10147
xbmc.executebuiltin('ActivateWindow(%d)' % id)
xbmc.sleep(100)
win = xbmcgui.Window(id)
retry = 50
while (retry > 0):
try:
xbmc.sleep(10)
win.getControl(1).setLabel(label)
win.getControl(5).setText(text)
retry = 0
except:
retry -= 1
return '1'
except:
return '1'
def render_video(self,item):
#util.debug("_render_video")
params = self.params()
params.update({'play':item['url'],'dtitle':item['title']})
#for k,v in item.iteritems():
# params.update({k: str(v)})
downparams = self.params()
if item.get('originaltitle_seo'):
downparams.update({'title':"%s%s" % (item['originaltitle_seo'], item['extension']), 'down':item['url']})
else:
downparams.update({'title':"%s.%s" % (item['title'], 'mp4'), 'down':item['url']})
title = item['title'] #'%s%s' % (item['title'],item['size'])
menuItems = {}
if "!download" not in self.provider.capabilities():
menuItems[xbmc.getLocalizedString(33003)] = downparams
if 'trailer' in item.keys() and item['trailer'] != '' and item['trailer'] is not None:
trailerparams = {'action-type': 'trailer', 'url': item['trailer']}
menuItems['Trailer'] = trailerparams
if 'menu' in item.keys():
for ctxtitle, value in item['menu'].iteritems():
if ctxtitle.find('$') == 0:
try:
ctxtitle = self.addon.getLocalizedString(int(ctxtitle[1:]))
except:
pass
menuItems[ctxtitle] = value
#util.debug("menuItems: %s" % str(menuItems))
self.add_video(title,
params,
item['img'],
infoLabels=item,
menuItems=menuItems
)
def getString(self, string_id):
return self.addon.getLocalizedString(string_id)
def set_list_control(self):
'''select correct list (3=small, 6=big with icons)'''
# set list id 6 if available for rich dialog
if self.richlayout:
self.list_control = self.getControl(6)
self.getControl(3).setVisible(False)
else:
self.list_control = self.getControl(3)
self.getControl(6).setVisible(False)
self.list_control.setEnabled(True)
self.list_control.setVisible(True)
# enable cancel button
self.set_cancel_button()
# show get more button
if self.getmorebutton:
util.debug("[SC] dialog 1")
self.getControl(5).setVisible(True)
self.getControl(5).setLabel(xbmc.getLocalizedString(21452))
elif not self.multiselect:
util.debug("[SC] dialog 2")
self.getControl(5).setLabel(xbmc.getLocalizedString(186))
self.getControl(5).setVisible(True)
else:
util.debug("[SC] dialog 3")
self.getControl(5).setVisible(True)
self.getControl(5).setEnabled(True)
def get(version):
try:
import xbmc,xbmcgui,xbmcaddon,xbmcvfs
f = xbmcvfs.File(xbmcaddon.Addon().getAddonInfo('changelog'))
text = f.read() ; f.close()
label = '%s - %s' % (xbmc.getLocalizedString(24054), xbmcaddon.Addon().getAddonInfo('name'))
id = 10147
xbmc.executebuiltin('ActivateWindow(%d)' % id)
xbmc.sleep(100)
win = xbmcgui.Window(id)
retry = 50
while (retry > 0):
try:
xbmc.sleep(10)
win.getControl(1).setLabel(label)
win.getControl(5).setText(text)
retry = 0
except:
retry -= 1
return '1'
except:
return '1'
def get_localized_string(code):
dev = xbmc.getLocalizedString(code)
try:
dev = dev.encode("utf-8")
except:
pass
return dev
def manual_set_music_artwork(self, details, mediatype):
'''manual override artwork options'''
from utils import manual_set_artwork
if mediatype == "artist" and "artist" in details:
header = "%s: %s" % (xbmc.getLocalizedString(13511), details["artist"])
else:
header = "%s: %s" % (xbmc.getLocalizedString(13511), xbmc.getLocalizedString(558))
changemade, artwork = manual_set_artwork(details["art"], mediatype, header)
# save results if any changes made
if changemade:
details["art"] = artwork
refresh_needed = False
download_art = self._mutils.addon.getSetting("music_art_download") == "true"
download_art_custom = self._mutils.addon.getSetting("music_art_download_custom") == "true"
# download artwork to music folder if needed
if details.get("diskpath") and download_art:
details["art"] = download_artwork(details["diskpath"], details["art"])
refresh_needed = True
# download artwork to custom folder if needed
if details.get("customartpath") and download_art_custom:
details["art"] = download_artwork(details["customartpath"], details["art"])
refresh_needed = True
# reload skin to make sure new artwork is visible
if refresh_needed:
xbmc.sleep(500)
xbmc.executebuiltin("ReloadSkin()")
# return endresult
return details
def select_art(items, manual_select=False, art_type=""):
'''select the preferred image from the list'''
image = None
if manual_select:
# show selectdialog to manually select the item
results_list = []
# add none and browse entries
listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(231), iconImage="DefaultAddonNone.png")
results_list.append(listitem)
listitem = xbmcgui.ListItem(label=xbmc.getLocalizedString(1030), iconImage="DefaultFolder.png")
results_list.append(listitem)
for item in items:
labels = [item["contributedby"], item["dateadded"], item["language"], item["source"]]
label = " / ".join(labels)
listitem = xbmcgui.ListItem(label=label, iconImage=item["thumb"])
results_list.append(listitem)
if manual_select and results_list:
dialog = DialogSelect("DialogSelect.xml", "", listing=results_list, window_title=art_type)
dialog.doModal()
selected_item = dialog.result
del dialog
if selected_item == 0:
image = ""
if selected_item == 1:
# browse for image
dialog = xbmcgui.Dialog()
image = dialog.browse(2, xbmc.getLocalizedString(1030), 'files', mask='.gif').decode("utf-8")
del dialog
elif selected_item > 1:
# user has selected an image from online results
image = items[selected_item - 2]["image"]
elif items:
# just grab the first item as best match
image = items[0]["image"]
return image
def pvr_proceed_lookup(self, title, channel, genre, recordingdetails):
'''perform some checks if we can proceed with the lookup'''
filters = []
if not title:
filters.append("Title is empty")
for item in self._mutils.addon.getSetting("pvr_art_ignore_titles").split("|"):
if item and item.lower() == title.lower():
filters.append("Title is in list of titles to ignore")
for item in self._mutils.addon.getSetting("pvr_art_ignore_channels").split("|"):
if item and item.lower() == channel.lower():
filters.append("Channel is in list of channels to ignore")
for item in self._mutils.addon.getSetting("pvr_art_ignore_genres").split("|"):
if genre and item and item.lower() in genre.lower():
filters.append("Genre is in list of genres to ignore")
if self._mutils.addon.getSetting("pvr_art_ignore_commongenre") == "true":
# skip common genres like sports, weather, news etc.
genre = genre.lower()
kodi_strings = [19516, 19517, 19518, 19520, 19548, 19549, 19551,
19552, 19553, 19554, 19555, 19556, 19557, 19558, 19559]
for kodi_string in kodi_strings:
kodi_string = xbmc.getLocalizedString(kodi_string).lower()
if (genre and (genre in kodi_string or kodi_string in genre)) or kodi_string in title:
filters.append("Common genres like weather/sports are set to be ignored")
if self._mutils.addon.getSetting("pvr_art_recordings_only") == "true" and not recordingdetails:
filters.append("PVR Artwork is enabled for recordings only")
if filters:
filterstr = " - ".join(filters)
log_msg("PVR artwork - filter active for title: %s - channel %s --> %s" % (title, channel, filterstr))
return filterstr
else:
return ""
def search_image(self, search_query, manual_select=False):
'''
search google images with the given query, returns first/best match
optional parameter: manual_select (bool), will show selectdialog to allow manual select by user
'''
image = ""
images_list = []
for img in self.get_data(search_query):
img = img.replace(" ", "%20") # fix for spaces in url
if xbmcvfs.exists(img):
if not manual_select:
# just return the first image found (assuming that will be the best match)
return img
else:
# manual lookup, list results and let user pick one
listitem = xbmcgui.ListItem(label=img, iconImage=img)
images_list.append(listitem)
if manual_select and images_list:
dialog = DialogSelect("DialogSelect.xml", "", listing=images_list, window_title="%s - Google"
% xbmc.getLocalizedString(283))
dialog.doModal()
selected_item = dialog.result
del dialog
if selected_item != -1:
selected_item = images_list[selected_item]
image = selected_item.getLabel().decode("utf-8")
return image
def get_duration(duration):
'''transform duration time in minutes to hours:minutes'''
if not duration:
return {}
if isinstance(duration, (unicode, str)):
duration.replace("min", "").replace("", "").replace(".", "")
try:
total_minutes = int(duration)
if total_minutes < 60:
hours = 0
else:
hours = total_minutes / 60
minutes = total_minutes - (hours * 60)
formatted_time = "%s:%s" % (hours, str(minutes).zfill(2))
except Exception as exc:
log_exception(__name__, exc)
return {}
return {
"Duration": formatted_time,
"Duration.Hours": hours,
"Duration.Minutes": minutes,
"Runtime": total_minutes,
"RuntimeExtended": "%s %s" % (total_minutes, xbmc.getLocalizedString(12391)),
"DurationAndRuntime": "%s (%s min.)" % (formatted_time, total_minutes),
"DurationAndRuntimeExtended": "%s (%s %s)" % (formatted_time, total_minutes, xbmc.getLocalizedString(12391))
}
def onInit(self):
'''called when the dialog is drawn'''
self.list_control = self.getControl(6)
self.getControl(1).setLabel(self.window_title)
self.getControl(3).setVisible(False)
try:
self.getControl(7).setLabel(xbmc.getLocalizedString(222))
except Exception:
pass
self.getControl(5).setVisible(False)
# add our items to the listing and focus the control
self.list_control.addItems(self.listing)
self.setFocus(self.list_control)
def getPlaybackInfo(url):
if addon.getSetting("framerate") == 'false':
return ''
Dialog.notification(xbmc.getLocalizedString(20186), '', xbmcgui.NOTIFICATION_INFO, 60000, False)
values = getFlashVars(url)
if not values:
return ''
data = getUrldata(mode='catalog/GetPlaybackResources',
values=values,
extra=True)
fr = getStreams(*data)
Dialog.notification(xbmc.getLocalizedString(20186), '', xbmcgui.NOTIFICATION_INFO, 10, False)
return fr
def get_string(t):
import xbmc, xbmcaddon
ADDON = xbmcaddon.Addon()
ADDON_ID = ADDON.getAddonInfo("id")
id = _strings.get(t.lower())
if not id:
xbmc.log("LANGUAGE: missing translation for '%s'" % t.lower())
return t
elif id in range(30000, 31000) and ADDON_ID.startswith("plugin"): return ADDON.getLocalizedString(id)
elif id in range(31000, 32000) and ADDON_ID.startswith("skin"): return ADDON.getLocalizedString(id)
elif id in range(32000, 33000) and ADDON_ID.startswith("script"): return ADDON.getLocalizedString(id)
elif not id in range(30000, 33000): return xbmc.getLocalizedString(id)
#setattr(__builtin__, "_", get_string)
# SYSTEM LANGUAGE STRINGS: Only the ones that are available AND unchanged in ["Helix", "Isengard", "Jarvis", "Krypton", "Leia"]
def get_string(t):
import xbmc, xbmcaddon
ADDON = xbmcaddon.Addon()
ADDON_ID = ADDON.getAddonInfo("id")
id = _strings.get(t.lower())
if not id:
xbmc.log("LANGUAGE: missing translation for '%s'" % t.lower())
return t
elif id in range(30000, 31000) and ADDON_ID.startswith("plugin"): return ADDON.getLocalizedString(id)
elif id in range(31000, 32000) and ADDON_ID.startswith("skin"): return ADDON.getLocalizedString(id)
elif id in range(32000, 33000) and ADDON_ID.startswith("script"): return ADDON.getLocalizedString(id)
elif not id in range(30000, 33000): return xbmc.getLocalizedString(id)
#setattr(__builtin__, "_", get_string)
# SYSTEM LANGUAGE STRINGS: Only the ones that are available AND unchanged in ["Helix", "Isengard", "Jarvis", "Krypton", "Leia"]
def colorthemes(self):
'''show dialog with all available color themes'''
listitems = []
# create item
listitem = xbmcgui.ListItem(label=self.addon.getLocalizedString(32035), iconImage="DefaultAddonSkin.png")
listitem.setLabel2(self.addon.getLocalizedString(32036))
listitem.setPath("add")
listitems.append(listitem)
# import item
listitem = xbmcgui.ListItem(label=self.addon.getLocalizedString(32037), iconImage="DefaultAddonSkin.png")
listitem.setLabel2(self.addon.getLocalizedString(32038))
listitem.setPath("import")
listitems.append(listitem)
# get all skin and user defined themes
listitems += self.get_skin_colorthemes()
listitems += self.get_user_colorthemes()
# show dialog and list options
header = self.addon.getLocalizedString(32020)
dialog = DialogSelect("DialogSelect.xml", "", windowtitle=header,
richlayout=True, listing=listitems)
dialog.doModal()
result = dialog.result
del dialog
if result:
themefile = result.getfilename().decode("utf-8")
themename = result.getLabel().decode("utf-8")
has_icon = xbmcvfs.exists(themefile.replace(".theme", ".jpg"))
if themefile == "add":
# create new colortheme
self.create_colortheme()
self.colorthemes()
elif themefile == "import":
# import theme file
self.restore_colortheme()
self.colorthemes()
elif self.skinthemes_path in themefile:
# load skin provided theme
self.load_colortheme(themefile)
else:
# show contextmenu for user custom theme
menuoptions = []
menuoptions.append(self.addon.getLocalizedString(32021))
menuoptions.append(xbmc.getLocalizedString(117))
if not has_icon:
menuoptions.append(xbmc.getLocalizedString(19285))
menuoptions.append(self.addon.getLocalizedString(32022))
ret = xbmcgui.Dialog().select(themename, menuoptions)
if ret == 0:
self.load_colortheme(themefile)
elif ret == 1:
self.remove_theme(themefile)
elif ret == 2 and not has_icon:
self.set_icon_for_theme(themefile)
elif ret == 3 or (ret == 2 and has_icon):
self.backup_theme(themename)
if not ret == 0:
# show selection dialog again
self.colorthemes()
def browse_playback_devices(self):
'''set the active playback device'''
xbmcplugin.setContent(self.addon_handle, "files")
items = []
if self.win.getProperty("spotify.supportsplayback"):
# local playback
label = self.addon.getLocalizedString(11037)
if self.local_playback:
label += " [%s]" % self.addon.getLocalizedString(11040)
url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=local"
li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png")
li.setProperty("isPlayable", "false")
li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg"})
li.addContextMenuItems([], True)
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)
else:
# local playback using a remote service
label = self.addon.getLocalizedString(11060)
if self.addon.getSetting("playback_device") == "remote":
label += " [%s]" % self.addon.getLocalizedString(11040)
url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=remote"
li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png")
li.setProperty("isPlayable", "false")
li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg"})
li.addContextMenuItems([], True)
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)
# connect devices
for device in self.sp.devices()["devices"]:
label = "Spotify Connect: %s" % device["name"]
if device["is_active"] and self.addon.getSetting("playback_device") == "connect":
label += " [%s]" % self.addon.getLocalizedString(11040)
url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=%s" % device["id"]
li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png")
li.setProperty("isPlayable", "false")
li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg"})
li.addContextMenuItems([], True)
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)
if xbmc.getCondVisibility("System.HasAddon(plugin.audio.squeezebox)"):
# LMS playback
label = xbmc.getInfoLabel("System.AddonTitle(plugin.audio.squeezebox)")
if self.addon.getSetting("playback_device") == "squeezebox":
label += " [%s]" % self.addon.getLocalizedString(11040)
url = "plugin://plugin.audio.spotify/?action=set_playback_device&deviceid=squeezebox"
li = xbmcgui.ListItem(label, iconImage="DefaultMusicCompilations.png")
li.setProperty("isPlayable", "false")
li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg"})
li.addContextMenuItems([], True)
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
def browse_main_library(self):
# library nodes
xbmcplugin.setContent(self.addon_handle, "files")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11013))
items = []
items.append(
(xbmc.getLocalizedString(136),
"plugin://plugin.audio.spotify/?action=browse_playlists&ownerid=%s" %
(self.userid),
"DefaultMusicPlaylists.png"))
items.append(
(xbmc.getLocalizedString(132),
"plugin://plugin.audio.spotify/?action=browse_savedalbums",
"DefaultMusicAlbums.png"))
items.append(
(xbmc.getLocalizedString(134),
"plugin://plugin.audio.spotify/?action=browse_savedtracks",
"DefaultMusicSongs.png"))
items.append(
(xbmc.getLocalizedString(133),
"plugin://plugin.audio.spotify/?action=browse_savedartists",
"DefaultMusicArtists.png"))
items.append(
(self.addon.getLocalizedString(11023),
"plugin://plugin.audio.spotify/?action=browse_topartists",
"DefaultMusicArtists.png"))
items.append(
(self.addon.getLocalizedString(11024),
"plugin://plugin.audio.spotify/?action=browse_toptracks",
"DefaultMusicSongs.png"))
for item in items:
li = xbmcgui.ListItem(
item[0],
path=item[1],
iconImage=item[2]
)
li.setProperty('do_not_analyze', 'true')
li.setProperty('IsPlayable', 'false')
li.setArt({"fanart": "special://home/addons/plugin.audio.spotify/fanart.jpg"})
li.addContextMenuItems([], True)
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=item[1], listitem=li, isFolder=True)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)