[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:
chme
2022-05-28 06:42:29 +02:00
parent ccdcc0cbf9
commit efb9ba7767
3 changed files with 0 additions and 218 deletions

View File

@@ -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)
{

View File

@@ -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);