Commit 084fd8df authored by Max Kellermann's avatar Max Kellermann

playlist/soundcloud: use std::string

parent 328131b7
...@@ -32,10 +32,12 @@ ...@@ -32,10 +32,12 @@
#include <glib.h> #include <glib.h>
#include <yajl/yajl_parse.h> #include <yajl/yajl_parse.h>
#include <string>
#include <string.h> #include <string.h>
static struct { static struct {
char *apikey; std::string apikey;
} soundcloud_config; } soundcloud_config;
static constexpr Domain soundcloud_domain("soundcloud"); static constexpr Domain soundcloud_domain("soundcloud");
...@@ -43,8 +45,8 @@ static constexpr Domain soundcloud_domain("soundcloud"); ...@@ -43,8 +45,8 @@ static constexpr Domain soundcloud_domain("soundcloud");
static bool static bool
soundcloud_init(const config_param &param) soundcloud_init(const config_param &param)
{ {
soundcloud_config.apikey = param.DupBlockString("apikey"); soundcloud_config.apikey = param.GetBlockValue("apikey", "");
if (soundcloud_config.apikey == NULL) { if (soundcloud_config.apikey.empty()) {
LogDebug(soundcloud_domain, LogDebug(soundcloud_domain,
"disabling the soundcloud playlist plugin " "disabling the soundcloud playlist plugin "
"because API key is not set"); "because API key is not set");
...@@ -54,12 +56,6 @@ soundcloud_init(const config_param &param) ...@@ -54,12 +56,6 @@ soundcloud_init(const config_param &param)
return true; return true;
} }
static void
soundcloud_finish(void)
{
g_free(soundcloud_config.apikey);
}
/** /**
* Construct a full soundcloud resolver URL from the given fragment. * Construct a full soundcloud resolver URL from the given fragment.
* @param uri uri of a soundcloud page (or just the path) * @param uri uri of a soundcloud page (or just the path)
...@@ -79,7 +75,8 @@ soundcloud_resolve(const char* uri) { ...@@ -79,7 +75,8 @@ soundcloud_resolve(const char* uri) {
} }
ru = g_strconcat("http://api.soundcloud.com/resolve.json?url=", ru = g_strconcat("http://api.soundcloud.com/resolve.json?url=",
u, "&client_id=", soundcloud_config.apikey, NULL); u, "&client_id=",
soundcloud_config.apikey.c_str(), nullptr);
g_free(u); g_free(u);
return ru; return ru;
...@@ -212,7 +209,8 @@ static int handle_end_map(void *ctx) ...@@ -212,7 +209,8 @@ static int handle_end_map(void *ctx)
Song *s; Song *s;
char *u; char *u;
u = g_strconcat(data->stream_url, "?client_id=", soundcloud_config.apikey, NULL); u = g_strconcat(data->stream_url, "?client_id=",
soundcloud_config.apikey.c_str(), nullptr);
s = Song::NewRemote(u); s = Song::NewRemote(u);
g_free(u); g_free(u);
...@@ -356,10 +354,12 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond) ...@@ -356,10 +354,12 @@ soundcloud_open_uri(const char *uri, Mutex &mutex, Cond &cond)
char *u = NULL; char *u = NULL;
if (strcmp(arg, "track") == 0) { if (strcmp(arg, "track") == 0) {
u = g_strconcat("http://api.soundcloud.com/tracks/", u = g_strconcat("http://api.soundcloud.com/tracks/",
rest, ".json?client_id=", soundcloud_config.apikey, NULL); rest, ".json?client_id=",
soundcloud_config.apikey.c_str(), nullptr);
} else if (strcmp(arg, "playlist") == 0) { } else if (strcmp(arg, "playlist") == 0) {
u = g_strconcat("http://api.soundcloud.com/playlists/", u = g_strconcat("http://api.soundcloud.com/playlists/",
rest, ".json?client_id=", soundcloud_config.apikey, NULL); rest, ".json?client_id=",
soundcloud_config.apikey.c_str(), nullptr);
} else if (strcmp(arg, "url") == 0) { } else if (strcmp(arg, "url") == 0) {
/* Translate to soundcloud resolver call. libcurl will automatically /* Translate to soundcloud resolver call. libcurl will automatically
follow the redirect to the right resource. */ follow the redirect to the right resource. */
...@@ -409,7 +409,7 @@ const struct playlist_plugin soundcloud_playlist_plugin = { ...@@ -409,7 +409,7 @@ const struct playlist_plugin soundcloud_playlist_plugin = {
"soundcloud", "soundcloud",
soundcloud_init, soundcloud_init,
soundcloud_finish, nullptr,
soundcloud_open_uri, soundcloud_open_uri,
nullptr, nullptr,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment