mirror of
https://github.com/owntone/owntone-server.git
synced 2025-01-14 08:15:02 -05:00
[spotify] Additional cleanup of functionality only used with libspotify
- Remove playlist commands only used by libspotify: adding / removing playlist command was used by the callbacks from libspotify to receive incremental updates (did not work for some time) - Remove "login" web api endpoint: no login into libspotify is required any more. Spotify web api authorization follows the OAuth flow.
This commit is contained in:
parent
ccdcc0cbf9
commit
efb9ba7767
@ -867,9 +867,6 @@ jsonapi_reply_config(struct httpd_request *hreq)
|
||||
json_object_object_add(jreply, "allow_modifying_stored_playlists", json_object_new_boolean(allow_modifying_stored_playlists));
|
||||
safe_json_add_string(jreply, "default_playlist_directory", default_playlist_directory);
|
||||
|
||||
// libspotify is sunset, so always return false. TODO: remove this parameter.
|
||||
json_object_object_add(jreply, "use_libspotify", json_object_new_boolean(false));
|
||||
|
||||
CHECK_ERRNO(L_WEB, evbuffer_add_printf(hreq->reply, "%s", json_object_to_json_string(jreply)));
|
||||
|
||||
jparse_free(jreply);
|
||||
@ -1318,7 +1315,6 @@ jsonapi_reply_spotify(struct httpd_request *hreq)
|
||||
json_object_object_add(jreply, "spotify_installed", json_object_new_boolean(sp_status.installed));
|
||||
json_object_object_add(jreply, "spotify_logged_in", json_object_new_boolean(sp_status.logged_in));
|
||||
json_object_object_add(jreply, "has_podcast_support", json_object_new_boolean(sp_status.has_podcast_support));
|
||||
safe_json_add_string(jreply, "libspotify_user", sp_status.username);
|
||||
|
||||
spotifywebapi_status_info_get(&webapi_info);
|
||||
json_object_object_add(jreply, "webapi_token_valid", json_object_new_boolean(webapi_info.token_valid));
|
||||
@ -1342,73 +1338,6 @@ jsonapi_reply_spotify(struct httpd_request *hreq)
|
||||
return HTTP_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
jsonapi_reply_spotify_login(struct httpd_request *hreq)
|
||||
{
|
||||
#ifdef SPOTIFY
|
||||
struct evbuffer *in_evbuf;
|
||||
json_object* request;
|
||||
const char *user;
|
||||
const char *password;
|
||||
const char *errmsg;
|
||||
json_object* jreply;
|
||||
json_object* errors;
|
||||
int ret;
|
||||
|
||||
DPRINTF(E_DBG, L_WEB, "Received Spotify login request\n");
|
||||
|
||||
in_evbuf = evhttp_request_get_input_buffer(hreq->req);
|
||||
|
||||
request = jparse_obj_from_evbuffer(in_evbuf);
|
||||
if (!request)
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "Failed to parse incoming request\n");
|
||||
return HTTP_BADREQUEST;
|
||||
}
|
||||
|
||||
CHECK_NULL(L_WEB, jreply = json_object_new_object());
|
||||
|
||||
user = jparse_str_from_obj(request, "user");
|
||||
password = jparse_str_from_obj(request, "password");
|
||||
if (user && strlen(user) > 0 && password && strlen(password) > 0)
|
||||
{
|
||||
ret = spotify_login(user, password, &errmsg);
|
||||
if (ret < 0)
|
||||
{
|
||||
json_object_object_add(jreply, "success", json_object_new_boolean(false));
|
||||
errors = json_object_new_object();
|
||||
json_object_object_add(errors, "error", json_object_new_string(errmsg));
|
||||
json_object_object_add(jreply, "errors", errors);
|
||||
}
|
||||
else
|
||||
{
|
||||
json_object_object_add(jreply, "success", json_object_new_boolean(true));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DPRINTF(E_LOG, L_WEB, "No user or password in spotify login post request\n");
|
||||
|
||||
json_object_object_add(jreply, "success", json_object_new_boolean(false));
|
||||
errors = json_object_new_object();
|
||||
if (!user || strlen(user) == 0)
|
||||
json_object_object_add(errors, "user", json_object_new_string("Username is required"));
|
||||
if (!password || strlen(password) == 0)
|
||||
json_object_object_add(errors, "password", json_object_new_string("Password is required"));
|
||||
json_object_object_add(jreply, "errors", errors);
|
||||
}
|
||||
|
||||
CHECK_ERRNO(L_WEB, evbuffer_add_printf(hreq->reply, "%s", json_object_to_json_string(jreply)));
|
||||
|
||||
jparse_free(jreply);
|
||||
|
||||
#else
|
||||
DPRINTF(E_LOG, L_WEB, "Received spotify login request but was not compiled with enable-spotify\n");
|
||||
#endif
|
||||
|
||||
return HTTP_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
jsonapi_reply_spotify_logout(struct httpd_request *hreq)
|
||||
{
|
||||
@ -4716,7 +4645,6 @@ static struct httpd_uri_map adm_handlers[] =
|
||||
{ EVHTTP_REQ_GET |
|
||||
EVHTTP_REQ_PUT, "^/api/update$", jsonapi_reply_update },
|
||||
{ EVHTTP_REQ_PUT, "^/api/rescan$", jsonapi_reply_meta_rescan },
|
||||
{ EVHTTP_REQ_POST, "^/api/spotify-login$", jsonapi_reply_spotify_login },
|
||||
{ EVHTTP_REQ_GET, "^/api/spotify-logout$", jsonapi_reply_spotify_logout },
|
||||
{ EVHTTP_REQ_GET, "^/api/spotify$", jsonapi_reply_spotify },
|
||||
{ EVHTTP_REQ_GET, "^/api/pairing$", jsonapi_reply_pairing_get },
|
||||
|
@ -153,7 +153,6 @@ static const char *spotify_scope = "playlist-read-private playlist-read-
|
||||
static const char *spotify_auth_uri = "https://accounts.spotify.com/authorize";
|
||||
static const char *spotify_token_uri = "https://accounts.spotify.com/api/token";
|
||||
|
||||
static const char *spotify_playlist_uri = "https://api.spotify.com/v1/playlists/%s";
|
||||
static const char *spotify_track_uri = "https://api.spotify.com/v1/tracks/%s";
|
||||
static const char *spotify_me_uri = "https://api.spotify.com/v1/me";
|
||||
static const char *spotify_albums_uri = "https://api.spotify.com/v1/me/albums?limit=50";
|
||||
@ -893,27 +892,6 @@ get_id_from_uri(const char *uri, char **id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_playlist_endpoint_uri(const char *uri)
|
||||
{
|
||||
char *endpoint_uri = NULL;
|
||||
char *id = NULL;
|
||||
int ret;
|
||||
|
||||
ret = get_id_from_uri(uri, &id);
|
||||
if (ret < 0)
|
||||
{
|
||||
DPRINTF(E_LOG, L_SPOTIFY, "Error extracting owner and id from playlist uri '%s'\n", uri);
|
||||
goto out;
|
||||
}
|
||||
|
||||
endpoint_uri = safe_asprintf(spotify_playlist_uri, id);
|
||||
|
||||
out:
|
||||
free(id);
|
||||
return endpoint_uri;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_playlist_tracks_endpoint_uri(const char *uri)
|
||||
{
|
||||
@ -1488,42 +1466,6 @@ prepare_directories(const char *artist, const char *album)
|
||||
return dir_id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Purges all Spotify files from the library that are not in a playlist
|
||||
* (Note: all files from saved albums are in the spotify:savedtracks playlist)
|
||||
*/
|
||||
static int
|
||||
cleanup_spotify_files(void)
|
||||
{
|
||||
struct query_params qp;
|
||||
char *path;
|
||||
int ret;
|
||||
|
||||
memset(&qp, 0, sizeof(struct query_params));
|
||||
|
||||
qp.type = Q_BROWSE_PATH;
|
||||
qp.sort = S_NONE;
|
||||
qp.filter = "f.path LIKE 'spotify:%%' AND NOT f.path IN (SELECT filepath FROM playlistitems)";
|
||||
|
||||
ret = db_query_start(&qp);
|
||||
if (ret < 0)
|
||||
{
|
||||
db_query_end(&qp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (((ret = db_query_fetch_string(&path, &qp)) == 0) && (path))
|
||||
{
|
||||
cache_artwork_delete_by_path(path);
|
||||
}
|
||||
|
||||
db_query_end(&qp);
|
||||
|
||||
db_spotify_files_delete();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
map_track_to_mfi(struct media_file_info *mfi, const struct spotify_track *track, const struct spotify_album *album, const char *pl_name)
|
||||
{
|
||||
@ -2125,66 +2067,6 @@ webapi_purge(void *arg, int *ret)
|
||||
return COMMAND_END;
|
||||
}
|
||||
|
||||
/* Thread: library */
|
||||
static enum command_state
|
||||
webapi_pl_save(void *arg, int *ret)
|
||||
{
|
||||
const char *uri;
|
||||
char *endpoint_uri;
|
||||
json_object *response;
|
||||
|
||||
uri = arg;
|
||||
endpoint_uri = get_playlist_endpoint_uri(uri);
|
||||
|
||||
response = request_endpoint_with_token_refresh(endpoint_uri);
|
||||
if (!response)
|
||||
{
|
||||
*ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*ret = saved_playlist_add(response, 0, 1, SPOTIFY_REQUEST_TYPE_DEFAULT, NULL);
|
||||
|
||||
jparse_free(response);
|
||||
|
||||
out:
|
||||
free(endpoint_uri);
|
||||
|
||||
return COMMAND_END;
|
||||
}
|
||||
|
||||
/* Thread: library */
|
||||
static enum command_state
|
||||
webapi_pl_remove(void *arg, int *ret)
|
||||
{
|
||||
const char *uri;
|
||||
struct playlist_info *pli;
|
||||
int plid;
|
||||
|
||||
uri = arg;
|
||||
pli = db_pl_fetch_bypath(uri);
|
||||
|
||||
if (!pli)
|
||||
{
|
||||
DPRINTF(E_LOG, L_SPOTIFY, "Playlist '%s' not found, can't delete\n", uri);
|
||||
|
||||
*ret = -1;
|
||||
return COMMAND_END;
|
||||
}
|
||||
|
||||
DPRINTF(E_LOG, L_SPOTIFY, "Removing playlist '%s' (%s)\n", pli->title, uri);
|
||||
|
||||
plid = pli->id;
|
||||
|
||||
free_pli(pli, 0);
|
||||
|
||||
db_spotify_pl_delete(plid);
|
||||
cleanup_spotify_files();
|
||||
*ret = 0;
|
||||
|
||||
return COMMAND_END;
|
||||
}
|
||||
|
||||
void
|
||||
spotifywebapi_fullrescan(void)
|
||||
{
|
||||
@ -2203,30 +2085,6 @@ spotifywebapi_purge(void)
|
||||
library_exec_async(webapi_purge, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
spotifywebapi_pl_save(const char *uri)
|
||||
{
|
||||
if (scanning || !token_valid())
|
||||
{
|
||||
DPRINTF(E_DBG, L_SPOTIFY, "Scanning spotify saved tracks still in progress, ignoring update trigger for single playlist '%s'\n", uri);
|
||||
return;
|
||||
}
|
||||
|
||||
library_exec_async(webapi_pl_save, strdup(uri));
|
||||
}
|
||||
|
||||
void
|
||||
spotifywebapi_pl_remove(const char *uri)
|
||||
{
|
||||
if (scanning || !token_valid())
|
||||
{
|
||||
DPRINTF(E_DBG, L_SPOTIFY, "Scanning spotify saved tracks still in progress, ignoring remove trigger for single playlist '%s'\n", uri);
|
||||
return;
|
||||
}
|
||||
|
||||
library_exec_async(webapi_pl_remove, strdup(uri));
|
||||
}
|
||||
|
||||
char *
|
||||
spotifywebapi_artwork_url_get(const char *uri, int max_w, int max_h)
|
||||
{
|
||||
|
@ -53,10 +53,6 @@ void
|
||||
spotifywebapi_rescan(void);
|
||||
void
|
||||
spotifywebapi_purge(void);
|
||||
void
|
||||
spotifywebapi_pl_save(const char *uri);
|
||||
void
|
||||
spotifywebapi_pl_remove(const char *uri);
|
||||
char *
|
||||
spotifywebapi_artwork_url_get(const char *uri, int max_w, int max_h);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user