mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-07 13:15:45 -04:00
[spotify] Add function spotify_login_user
This commit is contained in:
parent
29c0264444
commit
a832e40bea
@ -1890,20 +1890,28 @@ spotify_status_info_get(struct spotify_status_info *info)
|
|||||||
CHECK_ERR(L_REMOTE, pthread_mutex_unlock(&status_lck));
|
CHECK_ERR(L_REMOTE, pthread_mutex_unlock(&status_lck));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Thread: library */
|
/* Thread: library, httpd */
|
||||||
void
|
int
|
||||||
spotify_login(char **arglist)
|
spotify_login_user(const char *user, const char *password, char **errmsg)
|
||||||
{
|
{
|
||||||
sp_error err;
|
sp_error err;
|
||||||
|
|
||||||
if (!g_sess)
|
if (!g_sess)
|
||||||
{
|
{
|
||||||
if (!g_libhandle)
|
if (!g_libhandle)
|
||||||
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Can't login! - could not find libspotify\n");
|
DPRINTF(E_LOG, L_SPOTIFY, "Can't login! - could not find libspotify\n");
|
||||||
|
if (errmsg)
|
||||||
|
*errmsg = safe_asprintf("Could not find libspotify");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Can't login! - no valid Spotify session\n");
|
DPRINTF(E_LOG, L_SPOTIFY, "Can't login! - no valid Spotify session\n");
|
||||||
|
if (errmsg)
|
||||||
|
*errmsg = safe_asprintf("No valid Spotify session");
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SP_CONNECTION_STATE_LOGGED_IN == fptr_sp_session_connectionstate(g_sess))
|
if (SP_CONNECTION_STATE_LOGGED_IN == fptr_sp_session_connectionstate(g_sess))
|
||||||
@ -1918,18 +1926,21 @@ spotify_login(char **arglist)
|
|||||||
if (SP_ERROR_OK != err)
|
if (SP_ERROR_OK != err)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not logout of Spotify: %s\n", fptr_sp_error_message(err));
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not logout of Spotify: %s\n", fptr_sp_error_message(err));
|
||||||
|
if (errmsg)
|
||||||
|
*errmsg = safe_asprintf("Could not logout of Spotify: %s", fptr_sp_error_message(err));
|
||||||
|
|
||||||
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck));
|
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck));
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK_ERR(L_SPOTIFY, pthread_cond_wait(&login_cond, &login_lck));
|
CHECK_ERR(L_SPOTIFY, pthread_cond_wait(&login_cond, &login_lck));
|
||||||
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck));
|
CHECK_ERR(L_SPOTIFY, pthread_mutex_unlock(&login_lck));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arglist)
|
if (user && password)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Spotify credentials file OK, logging in with username %s\n", arglist[0]);
|
DPRINTF(E_LOG, L_SPOTIFY, "Spotify credentials file OK, logging in with username %s\n", user);
|
||||||
err = fptr_sp_session_login(g_sess, arglist[0], arglist[1], 1, NULL);
|
err = fptr_sp_session_login(g_sess, user, password, 1, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1940,8 +1951,22 @@ spotify_login(char **arglist)
|
|||||||
if (SP_ERROR_OK != err)
|
if (SP_ERROR_OK != err)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_SPOTIFY, "Could not login into Spotify: %s\n", fptr_sp_error_message(err));
|
DPRINTF(E_LOG, L_SPOTIFY, "Could not login into Spotify: %s\n", fptr_sp_error_message(err));
|
||||||
return;
|
if (errmsg)
|
||||||
|
*errmsg = safe_asprintf("Could not login into Spotify: %s", fptr_sp_error_message(err));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Thread: library */
|
||||||
|
void
|
||||||
|
spotify_login(char **arglist)
|
||||||
|
{
|
||||||
|
if (arglist)
|
||||||
|
spotify_login_user(arglist[0], arglist[1], NULL);
|
||||||
|
else
|
||||||
|
spotify_login_user(NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -48,6 +48,9 @@ spotify_oauth_interface(struct evbuffer *evbuf, const char *redirect_uri);
|
|||||||
void
|
void
|
||||||
spotify_oauth_callback(struct evbuffer *evbuf, struct evkeyvalq *param, const char *redirect_uri);
|
spotify_oauth_callback(struct evbuffer *evbuf, struct evkeyvalq *param, const char *redirect_uri);
|
||||||
|
|
||||||
|
int
|
||||||
|
spotify_login_user(const char *user, const char *password, char **errmsg);
|
||||||
|
|
||||||
void
|
void
|
||||||
spotify_login(char **arglist);
|
spotify_login(char **arglist);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user