示例#1
0
def login():
    username = addon.getSetting('username')
    password = addon.getSetting('password')
    subscription_type = [SubscriptionType.hifi, SubscriptionType.premium][int('0' + addon.getSetting('subscription_type'))]

    if not username or not password:
        # Ask for username/password
        dialog = xbmcgui.Dialog()
        username = dialog.input(_T(30008), username)
        if not username:
            return
        password = dialog.input(_T(30009), option=xbmcgui.ALPHANUM_HIDE_INPUT)
        if not password:
            return
        selected = dialog.select(_T(30010), [SubscriptionType.hifi, SubscriptionType.premium])
        if selected < 0:
            return
        subscription_type = [SubscriptionType.hifi, SubscriptionType.premium][selected]

    ok = session.login(username, password, subscription_type)
    if ok and (not addon.getSetting('username') or not addon.getSetting('password')):
        # Ask about remembering username/password
        dialog = xbmcgui.Dialog()
        if dialog.yesno(plugin.name, _T(30209)):
            addon.setSetting('username', username)
            addon.setSetting('password', password)
        else:
            addon.setSetting('password', '')
    if not ok:
        xbmcgui.Dialog().notification(plugin.name, _T(30253) , icon=xbmcgui.NOTIFICATION_ERROR)
    xbmc.executebuiltin('Container.Refresh()')
示例#2
0
def search_type(field):
    last_field = addon.getSetting('last_search_field')
    search_text = addon.getSetting('last_search_text')
    if last_field != field or not search_text:
        addon.setSetting('last_search_field', field)
        keyboard = xbmc.Keyboard('', _T(30206))
        keyboard.doModal()
        if keyboard.isConfirmed():
            search_text = keyboard.getText()
        else:
            search_text = ''
    addon.setSetting('last_search_text', search_text)
    if search_text:
        searchresults = session.search(field, search_text)
        add_items(searchresults.artists,
                  content=CONTENT_FOR_TYPE.get('files'),
                  end=False)
        add_items(searchresults.albums, end=False)
        add_items(searchresults.playlists, end=False)
        add_items(searchresults.tracks, end=False)
        add_items(searchresults.videos, end=True)
    else:
        #xbmcplugin.setContent(plugin.handle, content='files')
        xbmcplugin.endOfDirectory(plugin.handle,
                                  succeeded=False,
                                  updateListing=False)
示例#3
0
def user_playlists():
    items = session.user.playlists()
    # Find Default Playlists via title if ID is not available anymore
    all_ids = list(session.user.playlists_cache.keys())
    for what in ['track', 'album', 'video']:
        playlist_id = addon.getSetting('default_%splaylist_id' % what)
        playlist_title = addon.getSetting('default_%splaylist_title' % what)
        if playlist_id and playlist_title and playlist_id not in all_ids:
            for playlist_id in all_ids:
                if session.user.playlists_cache.get(playlist_id).get('title', '') == playlist_title:
                    addon.setSetting('default_%splaylist_id' % what, playlist_id)
                    addon.setSetting('default_%splaylist_title' % what, playlist_title)
                    break
    add_items(items, content=CONTENT_FOR_TYPE.get('albums'))
def user_playlist_toggle():
    if not session.is_logged_in:
        return
    url = xbmc.getInfoLabel("ListItem.FilenameandPath")
    if not _addon_id in url:
        return
    if 'play_track/' in url:
        item_type = 'track'
        userpl_id = addon.getSetting('default_trackplaylist_id').decode(
            'utf-8')
        userpl_name = addon.getSetting('default_trackplaylist_title').decode(
            'utf-8')
        item_id = url.split('play_track/')[1]
        item_id = item_id.split('/')[0]
        item = session.get_track(item_id)
    elif 'play_video/' in url:
        item_type = 'video'
        userpl_id = addon.getSetting('default_videoplaylist_id').decode(
            'utf-8')
        userpl_name = addon.getSetting('default_videoplaylist_title').decode(
            'utf-8')
        item_id = url.split('play_video/')[1]
        item_id = item_id.split('/')[0]
        item = session.get_video(item_id)
    elif 'album/' in url:
        item_type = 'album'
        userpl_id = addon.getSetting('default_albumplaylist_id').decode(
            'utf-8')
        userpl_name = addon.getSetting('default_albumplaylist_title').decode(
            'utf-8')
        item_id = url.split('album/')[1]
        item_id = int('0%s' % item_id.split('/')[0])
        item = session.get_album(item_id)
        if userpl_id:
            if item._userplaylists and userpl_id in item._userplaylists:
                user_playlist_remove_album(userpl_id, item.id, dialog=False)
                return
            tracks = session.get_album_items(item.id)
            for track in tracks:
                if track.available:
                    item.id = track.id  # Add First Track of Album
                    break
    else:
        return
    try:
        if not userpl_id:
            # Dialog Mode if default Playlist not set
            user_playlist_add_item(item_type, '%s' % item_id)
            return
        if item._userplaylists and userpl_id in item._userplaylists:
            session.show_busydialog(_T(30264), userpl_name)
            session.user.remove_playlist_entry(playlist=userpl_id,
                                               item_id=item.id)
        else:
            session.show_busydialog(_T(30263), userpl_name)
            session.user.add_playlist_entries(playlist=userpl_id,
                                              item_ids=['%s' % item.id])
    except Exception, e:
        log(str(e), level=xbmc.LOGERROR)
        traceback.print_exc()