Пример #1
0
gboolean get_username(gchar** username){
    if(sp_session_user(g_session)){
        *username = g_strdup((gchar*)sp_user_canonical_name(sp_session_user(g_session)));
        return TRUE;
    }
    else{
        *username = g_strdup("No user");
        return FALSE;
    }
}
Пример #2
0
const char* SxPlaylist::getOwnerName() {
    sp_user* user = sp_playlist_owner(m_spPlaylist);
    if (user != sp_session_user(Session::getInstance()->getSpSession())) {
        return sp_user_display_name(user);
    }
    return NULL;
}
Пример #3
0
void QSpotifySession::onLoggedIn()
{
    qDebug() << "Logged in";

    if (m_user)
        return;

    m_isLoggedIn = true;
    m_user = new QSpotifyUser(sp_session_user(m_sp_session));
    m_user->init();

    setScrobble(settings.value("scrobble", false).toBool());
    lfmLogin(settings.value("lfmUser", "").toString(), settings.value("lfmPass", "").toString());

    m_pending_connectionRequest = false;
    emit pendingConnectionRequestChanged();
    emit isLoggedInChanged();
    emit userChanged();

    if(!m_uriToOpen.isEmpty()) {
        handleUri(m_uriToOpen);
        m_uriToOpen = "";
    }

    sp_session_flush_caches(m_sp_session);
    checkNetworkAccess();
    qDebug() << "Done";
}
Пример #4
0
static PyObject *Session_user_is_loaded(Session *self) {
    sp_user *user;

    user = sp_session_user(self->_session);
    if(user == NULL)
        return NULL;
    bool loaded = sp_user_is_loaded(user);
    return Py_BuildValue("i", loaded);
};
Пример #5
0
static PyObject *Session_display_name(Session *self) {
    sp_user *user;

    user = sp_session_user(self->_session);
    if(user == NULL)
        return NULL;
    const char *username = sp_user_display_name(user);
    return PyString_FromString(username);
};
Пример #6
0
static PyObject *Session_username(Session *self) {
    sp_user *user;
    user = sp_session_user(self->_session);
    if(user == NULL) {
        PyErr_SetString(SpotifyError, "no user returned from session");
        return NULL;
    }
    const char *username = sp_user_canonical_name(user);
    return PyString_FromString(username);
};
Пример #7
0
static PyObject *
Session_user_is_loaded(PyObject *self)
{
    sp_user *user = sp_session_user(Session_SP_SESSION(self));
    if (user == NULL) {
        PyErr_SetString(SpotifyError, "Not logged in");
        return NULL;
    }
    return PyBool_FromLong(sp_user_is_loaded(user));
};
Пример #8
0
static PyObject *
Session_display_name(PyObject *self)
{
    sp_user *user = sp_session_user(Session_SP_SESSION(self));
    if (user == NULL) {
        PyErr_SetString(SpotifyError, "Not logged in");
        return NULL;
    }
    return PyUnicode_FromString(sp_user_display_name(user));
};
Пример #9
0
PHP_METHOD(Spotify, getUser)
{
        sp_user *user;
        zval temp;
        spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);

        user = sp_session_user(p->session);

        object_init_ex(return_value, spotifyuser_ce);
        SPOTIFY_METHOD2(SpotifyUser, __construct, &temp, return_value, getThis(), user);
}
/**
  credentialsBlobUpdated
  callback from login when we get the blob, used instead of plain password
  will send blob to application to storage
  @note its up the the application to store it
  @note2: it will be fired more than once, always store latest blob
  @note3: if user have no cache, it will fire once, if cache it will (maybe) update current blob
  **/
void SpotifySession::credentialsBlobUpdated(sp_session *session, const char *blob)
{

    SpotifySession* _session = reinterpret_cast<SpotifySession*>(sp_session_userdata(session));
#if SPOTIFY_API_VERSION >= 12
    const char* username = sp_session_user_name( session );
#else
    const char* username = sp_user_canonical_name( sp_session_user( session ) );
#endif
    _session->m_blob = QByteArray(blob);
    qDebug() << " ==== Got blob update for " << QString::fromUtf8(username, strlen(username) ) << " ==== ";
    emit _session->blobUpdated( username, QByteArray(blob).constData() );
}
Пример #11
0
static PyObject *
Session_display_name(Session * self)
{
    sp_user *user;

    user = sp_session_user(self->_session);
    if (user == NULL) {
        PyErr_SetString(SpotifyError, "Not logged in");
        return NULL;
    }
    const char *username = sp_user_display_name(user);

    return PyUnicode_FromString(username);
};
Пример #12
0
static PyObject *
Session_user_is_loaded(Session * self)
{
    sp_user *user;

    user = sp_session_user(self->_session);
    if (user == NULL) {
        PyErr_SetString(SpotifyError, "Not logged in");
        return NULL;
    }
    bool loaded = sp_user_is_loaded(user);

    return Py_BuildValue("i", loaded);
};
Пример #13
0
static void sess_cb_logged_in(sp_session *sess, sp_error err)
{
  if (err == SP_ERROR_OK) {
    g_session.state = SESS_ONLINE;
    log_append("Logged in as \"%s\"", sp_user_display_name(sp_session_user(sess)));
    ui_dirty(UI_FOOTER);
    ui_show(UI_SET_BROWSER);
  }
  else {
    g_session.state = SESS_ERROR;
    log_append(sp_error_message(err));
    ui_dirty(UI_FOOTER);
    ui_show(UI_SET_LOG);
  }
}
Пример #14
0
static void
spotify_cb_logged_in (sp_session *spotify_session, sp_error error)
{
  if (SP_ERROR_OK != error) {
    GST_CAT_ERROR_OBJECT (gst_spot_src_debug_cb, ugly_spot, "Failed to log in to Spotify: %s", sp_error_message (error));
    return;
  }

  sp_user *me = sp_session_user (spotify_session);
  const char *my_name = (sp_user_is_loaded (me) ?
                         sp_user_display_name (me) :
                         sp_user_canonical_name (me));
  GST_CAT_DEBUG_OBJECT (gst_spot_src_debug_cb, ugly_spot, "Logged_in callback, user=%s", my_name);
  /* set default bitrate to audiofility */
  sp_session_preferred_bitrate(spotify_session, SP_BITRATE_320k);
  GST_SPOT_SRC_LOGGED_IN (ugly_spot) = TRUE;
}
Пример #15
0
/**
 * This callback is called when an attempt to login has succeeded or failed.
 *
 * @sa sp_session_callbacks#logged_in
 */
static void logged_in(sp_session *session, sp_error error)
{
  sp_user *me;
  const char *my_name;

  if (SP_ERROR_OK != error) {
    fprintf(stderr, "failed to log in to Spotify: %s\n",
                    sp_error_message(error));
    sp_session_release(session);
    exit(4);
  }

  // Let us print the nice message...
  me = sp_session_user(session);
  my_name = (sp_user_is_loaded(me) ? sp_user_display_name(me) : sp_user_canonical_name(me));

  fprintf(stderr, "Logged in to Spotify as user %s\n", my_name);
}
Пример #16
0
/**
 * This callback is called when an attempt to login has succeeded or failed.
 *
 * @sa sp_session_callbacks#logged_in
 */
static void logged_in(sp_session *session, sp_error error)
{
	sp_user *me;
	const char *my_name;

	if (SP_ERROR_OK != error) {
		fprintf(stderr, "failed to log in to Spotify: %s\n",
		                sp_error_message(error));
		sp_session_release(session);
		exit(4);
	}

	// Let us print the nice message...
	me = sp_session_user(session);
	my_name = (sp_user_is_loaded(me) ? sp_user_display_name(me) : sp_user_canonical_name(me));

	fprintf(stderr, "Logged in to Spotify as user %s\n", my_name);
    sp_playlist *pl = sp_playlist_create(session, sp_link_create_from_string("spotify:user:devnevyn:playlist:44ZXlJstDZrwuQvWPOo7KX"));
    empty_callbacks.playlist_state_changed = foo;
    sp_playlist_add_callbacks(pl, &empty_callbacks, NULL);
}
Пример #17
0
/**********************
 * Session management *
 **********************/
void session_load(sp_track* track) {
    sp_error error;
    session_callback_data scbd;

    g_debug("Loading track.");
    
    if(!sp_session_user(g_session))
        return;
        
    error = sp_session_player_load(g_session, track);
    if (error != SP_ERROR_OK)
        g_error("Failed to load track: %s", sp_error_message(error));

    /* Queue some events management */
    cb_notify_main_thread(NULL);

    /* Then call callbacks */
    scbd.type = SPOP_SESSION_LOAD;
    scbd.data = track;
    g_list_foreach(g_session_callbacks, session_call_callback, &scbd);
}
Пример #18
0
static void sess_callback_logged_in(sp_session *session, sp_error error) {
	sp_user *user;

	if(error != SP_ERROR_OK) {
		syslog(LOG_ERR, "Session: Login failed with error: %s", sp_error_message(error));

		/* The logout callback is called automatically in libspotify 12 */
		return;
	}

	user = sp_session_user(session);
	if(user != NULL) {
		syslog(LOG_INFO, "Session: Successfully logged in as user %s <%s>",
			sp_user_display_name(user), sp_user_canonical_name(user));
	}

	/* No point in sharing usage from this program */
	syslog(LOG_DEBUG, "Session: enabling private listening mode");
	sp_session_set_private_session(session, 1);

	/* Notify app of login to hook up rootlist callbacks */
	app_post_event(APP_LOGGED_IN);
}
Пример #19
0
sp_error
sp_playlist_add_tracks(sp_playlist *playlist, sp_track *const *tracks, int num_tracks, int position, sp_session *session)
{
  int size = sp_playlist_num_tracks(playlist);
  int new_size = size + num_tracks;
  int i, j, k;
  sp_playlist_track_t *new_tracks = NULL;

  if (position < 0 || position > size)
  {
    return SP_ERROR_INVALID_INDATA;
  }

  new_tracks = ALLOC_N(sp_playlist_track_t, new_size);

  for (i = 0, j = 0, k = 0; i < new_size; ++i)
  {
    if (i >= position && j < num_tracks)
    {
      new_tracks[i].track = tracks[j++];
      new_tracks[i].create_time = (int) time(NULL); // let’s hope before year 2038 we fix this :)
      new_tracks[i].creator = sp_session_user(session);
      new_tracks[i].message = NULL;
      new_tracks[i].seen = true;
    }
    else
    {
      MEMCPY(&new_tracks[i], &playlist->tracks[k++], sp_playlist_track_t);
    }
  }

  free(playlist->tracks);
  playlist->tracks = new_tracks;
  playlist->num_tracks = new_size;

  return SP_ERROR_OK;
}
Пример #20
0
/**
 * This callback is called when an attempt to login has succeeded or failed.
 *
 * @sa sp_session_callbacks#logged_in
 */
static void logged_in(sp_session *session, sp_error error)
{
	sp_user *me;
	const char *my_name;

	if (SP_ERROR_OK != error) {
		fprintf(stderr, "failed to log in to Spotify: %s\n",
		                sp_error_message(error));
		exit(4);
	}

	// Let us print the nice message...
	me = sp_session_user(session);
	my_name = (sp_user_is_loaded(me) ? sp_user_display_name(me) : sp_user_canonical_name(me));

	fprintf(stderr, "Logged in to Spotify as user %s\n", my_name);


	// Below are parts related to the playlist manager
	// error == OK is true by now.
	logged_in_playlist(session);

	start_prompt();
}
Пример #21
0
JNIEXPORT jobject JNICALL Java_jahspotify_impl_JahSpotifyImpl_retrieveUser (JNIEnv *env, jobject obj)
{
    sp_user *user = sp_session_user(g_sess);
    const char *value = NULL;
    int country = 0;

    while (!sp_user_is_loaded(user))
    {
        fprintf ( stderr, "jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: waiting for user to load\n" );
        sleep(1);
    }

    jclass jClass = (*env)->FindClass(env, "jahspotify/media/User");
    if (jClass == NULL)
    {
        fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: could not load jahnotify.media.User\n");
        return NULL;
    }

    jobject userInstance = (*env)->AllocObject(env,jClass);
    if (!userInstance)
    {
        fprintf(stderr,"jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: could not create instance of jahspotify.media.User\n");
        return NULL;
    }

    while (!sp_user_is_loaded(user))
    {
        sleep(1);
    }

    if (sp_user_is_loaded(user))
    {
        fprintf ( stderr, "jahspotify::Java_jahspotify_impl_JahSpotifyImpl_retrieveUser: user is loaded\n" );
        value = sp_user_full_name(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"fullName",value);
        }
        value = sp_user_canonical_name(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"userName",value);
        }
        value = sp_user_display_name(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"displayName",value);
        }
        value = sp_user_picture(user);
        if (value)
        {
            setObjectStringField(env,userInstance,"imageURL",value);
        }

        // Country encoded in an integer 'SE' = 'S' << 8 | 'E'
        country = sp_session_user_country(g_sess);
        char countryStr[] = "  ";
        countryStr[0] = (byte)(country >> 8);
        countryStr[1] = (byte)country;
        setObjectStringField(env,userInstance,"country",countryStr);

        return userInstance;
    }

    return NULL;

}
Пример #22
0
//--------------------------------------------------------
//	init the session
//--------------------------------------------------------
bool TLSpotify::TSession::Initialise(TRef& ErrorRef)
{
	//	init session
	if ( !m_pSession )
	{
		sp_session_config config;
		
		config.api_version = SPOTIFY_API_VERSION;
		
		// The path of the directory to store the cache. This must be specified.
		// Please read the documentation on preferred values.
		config.cache_location = "tmp";
		
		// The path of the directory to store the settings. This must be specified.
		// Please read the documentation on preferred values.
		config.settings_location = "tmp";
		
		// The key of the application. They are generated by Spotify,
		// and are specific to each application using libspotify.
		config.application_key = m_Key.GetData();
		config.application_key_size = m_Key.GetSize();
		
		// This identifies the application using some
		// free-text string [1, 255] characters.
		TFixedArray<char,255> AgentString;
		m_AgentName.GetAnsi( AgentString );
		config.user_agent = AgentString.GetData();
		
		// Register the callbacks.
		config.callbacks = &g_Callbacks;
		
		//	https://developer.spotify.com/en/libspotify/docs/group__session.html
		//	In the future, this will be renamed to sp_session_create() and will have a corresponding sp_session_release() function.
		sp_error Error = sp_session_init( &config, &m_pSession );
		
		if ( Error != SP_ERROR_OK )
		{
			//sp_error_message(error));
			ErrorRef = "Init";
			Shutdown();
			return false;
		}
		
		//	where is the session?
		if ( !m_pSession )
		{
			ErrorRef = "NoSession";
			Shutdown();
			return false;
		}
	}
	
	//	log in session
	if ( !IsLoggedIn() )
	{
		TFixedArray<char,255> UserNameString;
		m_UserName.GetAnsi( UserNameString );
		TFixedArray<char,255> PasswordString;
		m_Password.GetAnsi( PasswordString );
		
		//	attempt login
		sp_error Error = sp_session_login( m_pSession, UserNameString.GetData(), PasswordString.GetData() );
		if ( Error != SP_ERROR_OK )
		{
			ErrorRef = "Login";
			Shutdown();
			return false;
		}
		
		//	logged in! fetch the user
		m_pUser = sp_session_user( m_pSession );
		if ( !m_pUser )
		{
			ErrorRef = "NoUser";
			//	set pointer to something so we attempt to logout, even though it's not valid
			m_pUser = (sp_user*)0xdeadf00d;
			Shutdown();
			return false;
		}
	}
	
	return true;
}