def daynightthemes(self, dayornight):
'''allow user to set a specific theme during day/night time'''
if dayornight not in ["day", "night"]:
log_msg("Invalid parameter for day/night theme - must be day or night")
return
# show listing with themes
listitems = self.get_skin_colorthemes()
listitems += self.get_user_colorthemes()
header = self.addon.getLocalizedString(32031)
curvalue = xbmc.getInfoLabel("Skin.String(SkinHelper.ColorTheme.%s.theme)" % dayornight).decode("utf-8")
dialog = DialogSelect("DialogSelect.xml", "", windowtitle=header,
richlayout=True, listing=listitems, autofocus=curvalue)
dialog.doModal()
result = dialog.result
del dialog
if result:
themefile = result.getfilename().decode("utf-8")
themename = result.getLabel().decode("utf-8")
self.set_day_night_theme(dayornight, themename, themefile)
python类getLocalizedString()的实例源码
def set_day_night_theme(self, dayornight, themename, themefile):
''' Sets a new daynight theme'''
currenttimevalue = xbmc.getInfoLabel("Skin.String(SkinHelper.ColorTheme.%s.time)" % dayornight)
if not currenttimevalue:
currenttimevalue = "20:00" if dayornight == "night" else "07:00"
timevalue = xbmcgui.Dialog().input(self.addon.getLocalizedString(32017),
currenttimevalue).decode("utf-8")
try:
# check if the time is valid
check_date = datetime(*(time.strptime(timevalue, "%H:%M")[0:6]))
del check_date
base_setting = "SkinHelper.ColorTheme.%s" % dayornight
xbmc.executebuiltin("Skin.SetString(%s.theme,%s)" % (base_setting, themename.encode("utf-8")))
xbmc.executebuiltin("Skin.SetString(%s.time,%s)" % (base_setting, timevalue))
label = "%s (%s %s)" % (themename.encode("utf-8"), self.addon.getLocalizedString(32019), timevalue)
xbmc.executebuiltin("Skin.SetString(%s.label,%s)" % (base_setting, label))
xbmc.executebuiltin("Skin.SetString(%s.file,%s)" % (base_setting, themefile.encode("utf-8")))
except Exception as exc:
log_exception(__name__, exc)
xbmcgui.Dialog().ok(xbmc.getLocalizedString(329), self.addon.getLocalizedString(32018))
def backup_theme(self, themename):
'''backup a colortheme to a zipfile'''
import zipfile
backup_path = xbmcgui.Dialog().browse(3, self.addon.getLocalizedString(32029), "files").decode("utf-8")
if backup_path:
xbmc.executebuiltin("ActivateWindow(busydialog)")
backup_name = u"%s ColorTheme - %s" % (get_skin_name().capitalize(), themename)
backupfile = os.path.join(backup_path, backup_name + u".zip")
zip_temp = u'special://temp/%s.zip' % backup_name
xbmcvfs.delete(zip_temp)
xbmcvfs.delete(backupfile)
zip_temp = xbmc.translatePath(zip_temp).decode("utf-8")
zip_file = zipfile.ZipFile(zip_temp, "w", zipfile.ZIP_DEFLATED)
abs_src = os.path.abspath(xbmc.translatePath(self.userthemes_path).decode("utf-8"))
for filename in xbmcvfs.listdir(self.userthemes_path)[1]:
if (filename.startswith("%s_" % themename) or
filename.replace(".theme", "").replace(".jpg", "") == themename):
filename = filename.decode("utf-8")
filepath = xbmc.translatePath(self.userthemes_path + filename).decode("utf-8")
absname = os.path.abspath(filepath)
arcname = absname[len(abs_src) + 1:]
zip_file.write(absname, arcname)
zip_file.close()
xbmcvfs.copy(zip_temp, backupfile)
xbmc.executebuiltin("Dialog.Close(busydialog)")
def get_user_colorthemes(self):
'''get all user stored color themes as listitems'''
listitems = []
for file in xbmcvfs.listdir(self.userthemes_path)[1]:
if file.endswith(".theme"):
file = file.decode("utf-8")
themefile = self.userthemes_path + file
label = file.replace(".theme", "")
icon = themefile.replace(".theme", ".jpg")
if not xbmcvfs.exists(icon):
icon = ""
desc = "user defined theme"
if label == self.get_activetheme():
desc = xbmc.getLocalizedString(461)
listitem = xbmcgui.ListItem(label, iconImage=icon)
listitem.setLabel2(desc)
listitem.setPath(themefile)
listitems.append(listitem)
return listitems
def restore_colortheme(self):
'''restore zipbackup of colortheme to colorthemes folder'''
zip_path = xbmcgui.Dialog().browse(1, self.addon.getLocalizedString(32030), "files", ".zip")
if zip_path and zip_path.endswith(".zip"):
# create temp path
temp_path = u'special://temp/skinbackup/'
temp_zip = u"special://temp/colortheme.zip"
if xbmcvfs.exists(temp_path):
recursive_delete_dir(temp_path)
xbmcvfs.mkdir(temp_path)
# unzip to temp
xbmcvfs.copy(zip_path, temp_zip)
unzip_fromfile(temp_zip, temp_path)
for filename in xbmcvfs.listdir(temp_path)[1]:
filename = filename.decode("utf-8")
sourcefile = os.path.join(temp_path, filename)
destfile = os.path.join(self.userthemes_path, filename)
xbmcvfs.copy(sourcefile, destfile)
# cleanup temp
xbmcvfs.delete(temp_zip)
recursive_delete_dir(temp_path)
xbmcgui.Dialog().ok(self.addon.getLocalizedString(32026), self.addon.getLocalizedString(32027))
def set_playback_device(self):
'''set the active playback device'''
deviceid = self.params["deviceid"][0]
if deviceid == "local":
self.addon.setSetting("playback_device", "local")
elif deviceid == "remote":
headertxt = self.addon.getLocalizedString(11039)
bodytxt = self.addon.getLocalizedString(11061)
dialog = xbmcgui.Dialog()
dialog.textviewer(headertxt, bodytxt)
result = dialog.input(self.addon.getLocalizedString(11062))
if result:
self.addon.setSetting("playback_device", "remote")
self.addon.setSetting("connect_id", result)
del dialog
elif deviceid == "squeezebox":
self.addon.setSetting("playback_device", "squeezebox")
else:
self.sp.transfer_playback(deviceid, False)
self.addon.setSetting("playback_device", "connect")
self.addon.setSetting("connect_id", deviceid)
xbmc.executebuiltin("Container.Refresh")
def search_artists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(133))
result = self.sp.search(
q="artist:%s" %
self.artistid,
type='artist',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
artists = self.prepare_artist_listitems(result['artists']['items'])
self.add_artist_listitems(artists)
self.add_next_button(result['artists']['total'])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def search_tracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(134))
result = self.sp.search(
q="track:%s" %
self.trackid,
type='track',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
tracks = self.prepare_track_listitems(tracks=result["tracks"]["items"])
self.add_track_listitems(tracks, True)
self.add_next_button(result['tracks']['total'])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def search_playlists(self):
xbmcplugin.setContent(self.addon_handle, "files")
result = self.sp.search(
q=self.playlistid,
type='playlist',
limit=self.limit,
offset=self.offset,
market=self.usercountry)
log_msg(result)
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(136))
playlists = self.prepare_playlist_listitems(result['playlists']['items'])
self.add_playlist_listitems(playlists)
self.add_next_button(result['playlists']['total'])
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_playlists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_playlists)
def add_next_button(self, listtotal):
# adds a next button if needed
params = self.params
if listtotal > self.offset + self.limit:
params["offset"] = self.offset + self.limit
url = "plugin://plugin.audio.spotify/"
for key, value in params.iteritems():
if key == "action":
url += "?%s=%s" % (key, value[0])
elif key == "offset":
url += "&%s=%s" % (key, value)
else:
url += "&%s=%s" % (key, value[0])
li = xbmcgui.ListItem(
xbmc.getLocalizedString(33078),
path=url,
iconImage="DefaultMusicAlbums.png"
)
li.setProperty('do_not_analyze', 'true')
li.setProperty('IsPlayable', 'false')
xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=True)
def music_artwork_options(self, artist, album, track, disc):
'''show options for music artwork'''
options = []
options.append(self._mutils.addon.getLocalizedString(32028)) # Refresh item (auto lookup)
options.append(self._mutils.addon.getLocalizedString(32036)) # Choose art
options.append(self._mutils.addon.getLocalizedString(32034)) # Open addon settings
header = self._mutils.addon.getLocalizedString(32015)
dialog = xbmcgui.Dialog()
ret = dialog.select(header, options)
del dialog
if ret == 0:
# Refresh item (auto lookup)
self.get_music_artwork(artist, album, track, disc, ignore_cache=True)
elif ret == 1:
# Choose art
self.get_music_artwork(artist, album, track, disc, ignore_cache=True, manual=True)
elif ret == 2:
# Open addon settings
xbmc.executebuiltin("Addon.OpenSettings(%s)" % ADDON_ID)
def localize(self, text_id, default_text=u''):
if isinstance(text_id, int):
"""
We want to use all localization strings!
Addons should only use the range 30000 thru 30999 (see: http://kodi.wiki/view/Language_support) but we
do it anyway. I want some of the localized strings for the views of a skin.
"""
if text_id >= 0 and (text_id < 30000 or text_id > 30999):
result = xbmc.getLocalizedString(text_id)
if result is not None and result:
return utils.to_unicode(result)
result = self._addon.getLocalizedString(int(text_id))
if result is not None and result:
return utils.to_unicode(result)
return utils.to_unicode(default_text)
def localize(self, text_id, default_text=u''):
if isinstance(text_id, int):
"""
We want to use all localization strings!
Addons should only use the range 30000 thru 30999 (see: http://kodi.wiki/view/Language_support) but we
do it anyway. I want some of the localized strings for the views of a skin.
"""
if text_id >= 0 and (text_id < 30000 or text_id > 30999):
result = xbmc.getLocalizedString(text_id)
if result is not None and result:
return utils.to_unicode(result)
pass
pass
result = self._addon.getLocalizedString(int(text_id))
if result is not None and result:
return utils.to_unicode(result)
return utils.to_unicode(default_text)
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 set_icon_for_theme(filename):
'''sets an icon for an existing theme'''
iconpath = filename.replace(".theme", ".jpg")
dialog = xbmcgui.Dialog()
custom_thumbnail = dialog.browse(2, xbmc.getLocalizedString(1030), 'files')
if custom_thumbnail:
xbmcvfs.delete(iconpath)
xbmcvfs.copy(custom_thumbnail, iconpath)
dialogselect.py 文件源码
项目:script.skin.helper.skinbackup
作者: marcelveldt
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def set_cancel_button(self):
'''set cancel button if exists'''
try:
self.getControl(7).setLabel(xbmc.getLocalizedString(222))
self.getControl(7).setVisible(True)
self.getControl(7).setEnabled(True)
except Exception:
pass
def get_authkey(self):
'''get authentication key'''
auth_token = self.win.getProperty("spotify-token").decode("utf-8")
if not auth_token:
dialog = xbmcgui.Dialog()
header = self.addon.getAddonInfo("name")
msg = self.addon.getLocalizedString(11050)
dialog.ok(header, msg)
del dialog
xbmc.executebuiltin("Addon.OpenSettings(%s)" % ADDON_ID)
return auth_token
def switch_user(self):
'''switch the currently logged in user'''
usernames = []
count = 1
while True:
username = self.addon.getSetting("username%s" % count).decode("utf-8")
count += 1
if not username:
break
else:
display_name = ""
try:
display_name = self.sp.user(username)["display_name"]
except Exception:
pass
if not display_name:
display_name = username
usernames.append(display_name)
dialog = xbmcgui.Dialog()
ret = dialog.select(self.addon.getLocalizedString(11048), usernames)
del dialog
if ret != -1:
ret += 1
new_user = self.addon.getSetting("username%s" % ret)
new_pass = self.addon.getSetting("password%s" % ret)
self.addon.setSetting("username", new_user)
self.addon.setSetting("password", new_pass)
def browse_main(self):
# main listing
xbmcplugin.setContent(self.addon_handle, "files")
items = []
items.append(
(self.addon.getLocalizedString(11013),
"plugin://plugin.audio.spotify/?action=browse_main_library",
"DefaultMusicCompilations.png", True))
items.append(
(self.addon.getLocalizedString(11014),
"plugin://plugin.audio.spotify/?action=browse_main_explore",
"DefaultMusicGenres.png", True))
items.append(
(xbmc.getLocalizedString(137),
"plugin://plugin.audio.spotify/?action=search",
"DefaultMusicSearch.png", True))
items.append(
("%s: %s" % (self.addon.getLocalizedString(11039), self.playername),
"plugin://plugin.audio.spotify/?action=browse_playback_devices",
"DefaultMusicPlugins.png", True))
if self.addon.getSetting("multi_account") == "true":
cur_user_label = self.sp.me()["display_name"]
if not cur_user_label:
cur_user_label = self.sp.me()["id"]
label = "%s: %s" % (self.addon.getLocalizedString(11047), cur_user_label)
items.append(
(label,
"plugin://plugin.audio.spotify/?action=switch_user",
"DefaultActor.png", False))
for item in items:
li = xbmcgui.ListItem(
item[0],
path=item[1],
iconImage=item[2]
)
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=item[3])
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
def browse_main_explore(self):
# explore nodes
xbmcplugin.setContent(self.addon_handle, "files")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11014))
items = []
items.append(
(self.addon.getLocalizedString(11015),
"plugin://plugin.audio.spotify/?action=browse_playlists&applyfilter=featured",
"DefaultMusicPlaylists.png"))
items.append(
(self.addon.getLocalizedString(11016),
"plugin://plugin.audio.spotify/?action=browse_newreleases",
"DefaultMusicAlbums.png"))
# add categories
items += self.get_explore_categories()
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)
def artist_toptracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11011))
tracks = self.sp.artist_top_tracks(self.artistid, country=self.usercountry)
tracks = self.prepare_track_listitems(tracks=tracks["tracks"])
self.add_track_listitems(tracks)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TRACKNUM)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_SONG_RATING)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def related_artists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11012))
cachestr = "spotify.relatedartists.%s" % self.artistid
checksum = self.cache_checksum()
artists = self.cache.get(cachestr, checksum=checksum)
if not artists:
artists = self.sp.artist_related_artists(self.artistid)
artists = self.prepare_artist_listitems(artists['artists'])
self.cache.set(cachestr, artists, checksum=checksum)
self.add_artist_listitems(artists)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def add_track_to_playlist(self):
xbmc.executebuiltin("ActivateWindow(busydialog)")
if not self.trackid and xbmc.getInfoLabel("MusicPlayer.(1).Property(spotifytrackid)"):
self.trackid = xbmc.getInfoLabel("MusicPlayer.(1).Property(spotifytrackid)")
playlists = self.sp.user_playlists(self.userid, limit=50, offset=0)
ownplaylists = []
ownplaylistnames = []
for playlist in playlists['items']:
if playlist["owner"]["id"] == self.userid:
ownplaylists.append(playlist)
ownplaylistnames.append(playlist["name"])
ownplaylistnames.append(xbmc.getLocalizedString(525))
xbmc.executebuiltin("Dialog.Close(busydialog)")
select = xbmcgui.Dialog().select(xbmc.getLocalizedString(524), ownplaylistnames)
if select != -1 and ownplaylistnames[select] == xbmc.getLocalizedString(525):
# create new playlist...
kb = xbmc.Keyboard('', xbmc.getLocalizedString(21381))
kb.setHiddenInput(False)
kb.doModal()
if kb.isConfirmed():
name = kb.getText()
playlist = self.sp.user_playlist_create(self.userid, name, False)
self.sp.user_playlist_add_tracks(self.userid, playlist["id"], [self.trackid])
elif select != -1:
playlist = ownplaylists[select]
self.sp.user_playlist_add_tracks(self.userid, playlist["id"], [self.trackid])
def browse_newreleases(self):
xbmcplugin.setContent(self.addon_handle, "albums")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', self.addon.getLocalizedString(11005))
albums = self.get_newreleases()
self.add_album_listitems(albums)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_albums:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_albums)
def prepare_playlist_listitems(self, playlists):
playlists2 = []
followed_playlists = self.get_curuser_playlistids()
for item in playlists:
if item.get("images"):
item["thumb"] = item["images"][0]['url']
else:
item["thumb"] = "DefaultMusicAlbums.png"
item['url'] = self.build_url(
{'action': 'browse_playlist', 'playlistid': item['id'],
'ownerid': item['owner']['id']})
contextitems = []
# play
contextitems.append(
(xbmc.getLocalizedString(208),
"RunPlugin(plugin://plugin.audio.spotify/?action=play_playlist&playlistid=%s&ownerid=%s)" %
(item["id"], item['owner']['id'])))
if item['owner']['id'] != self.userid and item['id'] in followed_playlists:
# unfollow playlist
contextitems.append(
(self.addon.getLocalizedString(11010),
"RunPlugin(plugin://plugin.audio.spotify/?action=unfollow_playlist&playlistid=%s&ownerid=%s)" %
(item['id'],
item['owner']['id'])))
elif item['owner']['id'] != self.userid:
# follow playlist
contextitems.append(
(self.addon.getLocalizedString(11009),
"RunPlugin(plugin://plugin.audio.spotify/?action=follow_playlist&playlistid=%s&ownerid=%s)" %
(item['id'],
item['owner']['id'])))
contextitems.append((self.addon.getLocalizedString(11027),
"RunPlugin(plugin://plugin.audio.spotify/?action=refresh_listing)"))
item["contextitems"] = contextitems
playlists2.append(item)
return playlists2
def browse_artistalbums(self):
xbmcplugin.setContent(self.addon_handle, "albums")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(132))
artist = self.sp.artist(self.artistid)
artistalbums = self.sp.artist_albums(
self.artistid,
limit=50,
offset=0,
market=self.usercountry,
album_type='album,single,compilation')
count = len(artistalbums['items'])
albumids = []
while artistalbums['total'] > count:
artistalbums['items'] += self.sp.artist_albums(self.artistid,
limit=50,
offset=count,
market=self.usercountry,
album_type='album,single,compilation')['items']
count += 50
for album in artistalbums['items']:
albumids.append(album["id"])
albums = self.prepare_album_listitems(albumids)
self.add_album_listitems(albums)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_ALBUM_IGNORE_THE)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_SONG_RATING)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_albums:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_albums)
def browse_savedtracks(self):
xbmcplugin.setContent(self.addon_handle, "songs")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(134))
tracks = self.get_saved_tracks()
self.add_track_listitems(tracks, True)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_UNSORTED)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_songs:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_songs)
def browse_savedartists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(133))
artists = self.get_savedartists()
self.add_artist_listitems(artists)
xbmcplugin.addSortMethod(self.addon_handle, xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def browse_followedartists(self):
xbmcplugin.setContent(self.addon_handle, "artists")
xbmcplugin.setProperty(self.addon_handle, 'FolderName', xbmc.getLocalizedString(133))
artists = self.get_followedartists()
self.add_artist_listitems(artists)
xbmcplugin.endOfDirectory(handle=self.addon_handle)
if self.defaultview_artists:
xbmc.executebuiltin('Container.SetViewMode(%s)' % self.defaultview_artists)
def execute(self, data=''):
# evaluate input argument and depends on run add-on event/action
if data.startswith('Location'):
keyboard = xbmc.Keyboard('', xbmc.getLocalizedString(14024), False)
keyboard.doModal()
if keyboard.isConfirmed() and keyboard.getText() != '':
text = keyboard.getText()
locationNames, locationIds = self.provider.location(text)
dialog = xbmcgui.Dialog()
if locationNames != []:
selected = dialog.select(xbmc.getLocalizedString(396), locationNames)
if selected != -1:
commons.setSetting('Enabled', 'true')
commons.setSetting(data, locationNames[selected])
commons.debug('Selected location: %s' % locationNames[selected])
commons.setSetting(data + 'id', locationIds[selected])
commons.debug('Selected location id: %s' % locationIds[selected])
else:
dialog.ok(commons.AddonName(), commons.translate(284))
elif commons.setting('Enabled'):
location = commons.setting('Location%s' % data)
locationid = commons.setting('Location%sid' % data)
if (locationid == '') and (data != '1'):
location = commons.setting('Location1')
locationid = commons.setting('Location1id')
commons.debug('Trying first location instead: %s (%s)' % (location, locationid))
if locationid == '':
commons.debug('Fallback to GeoIP')
location, locationid = self.provider.geoip()
if not locationid == '':
commons.debug('Call forecast for location %s (%s)' % (location, locationid))
self.provider.forecast(location, locationid)
else:
commons.debug('No location found')
self.provider.clear()
self.provider.refresh()
else:
commons.debug('You need to enable weather retrieval in the weather underground add-on settings')
self.provider.clear()