aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/despotify/DespotifyUtils.cxx39
-rw-r--r--src/lib/despotify/DespotifyUtils.hxx17
2 files changed, 34 insertions, 22 deletions
diff --git a/src/lib/despotify/DespotifyUtils.cxx b/src/lib/despotify/DespotifyUtils.cxx
index c765c5336..51ded7578 100644
--- a/src/lib/despotify/DespotifyUtils.cxx
+++ b/src/lib/despotify/DespotifyUtils.cxx
@@ -47,13 +47,15 @@ callback(struct despotify_session* ds, int sig,
void (*cb)(struct despotify_session *, int, void *, void *) = registered_callbacks[i];
void *cb_data = registered_callback_data[i];
- if (cb)
+ if (cb != nullptr)
cb(ds, sig, data, cb_data);
}
}
-bool mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int, void *, void *),
- void *cb_data)
+bool
+mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int,
+ void *, void *),
+ void *cb_data)
{
for (size_t i = 0; i < ARRAY_SIZE(registered_callbacks); ++i) {
if (!registered_callbacks[i]) {
@@ -67,7 +69,9 @@ bool mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int,
return false;
}
-void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int, void *, void *))
+void
+mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int,
+ void *, void *))
{
for (size_t i = 0; i < ARRAY_SIZE(registered_callbacks); ++i) {
if (registered_callbacks[i] == cb) {
@@ -79,19 +83,22 @@ void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, in
Tag
mpd_despotify_tag_from_track(const ds_track &track)
{
- char tracknum[20];
- char comment[80];
- char date[20];
-
if (!track.has_meta_data)
return Tag();
TagBuilder tag;
+
+ char tracknum[20];
snprintf(tracknum, sizeof(tracknum), "%d", track.tracknumber);
+
+ char date[20];
snprintf(date, sizeof(date), "%d", track.year);
+
+ char comment[80];
snprintf(comment, sizeof(comment), "Bitrate %d Kbps, %sgeo restricted",
track.file_bitrate / 1000,
track.geo_restricted ? "" : "not ");
+
tag.AddItem(TAG_TITLE, track.title);
tag.AddItem(TAG_ARTIST, track.artist->name);
tag.AddItem(TAG_TRACK, tracknum);
@@ -103,18 +110,16 @@ mpd_despotify_tag_from_track(const ds_track &track)
return tag.Commit();
}
-struct despotify_session *mpd_despotify_get_session(void)
+struct despotify_session *
+mpd_despotify_get_session()
{
- const char *user;
- const char *passwd;
- bool high_bitrate;
-
if (g_session)
return g_session;
- user = config_get_string(CONF_DESPOTIFY_USER, nullptr);
- passwd = config_get_string(CONF_DESPOTIFY_PASSWORD, nullptr);
- high_bitrate = config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true);
+ const char *const user =
+ config_get_string(CONF_DESPOTIFY_USER, nullptr);
+ const char *const passwd =
+ config_get_string(CONF_DESPOTIFY_PASSWORD, nullptr);
if (user == nullptr || passwd == nullptr) {
LogDebug(despotify_domain,
@@ -127,6 +132,8 @@ struct despotify_session *mpd_despotify_get_session(void)
return nullptr;
}
+ const bool high_bitrate =
+ config_get_bool(CONF_DESPOTIFY_HIGH_BITRATE, true);
g_session = despotify_init_client(callback, nullptr,
high_bitrate, true);
if (!g_session) {
diff --git a/src/lib/despotify/DespotifyUtils.hxx b/src/lib/despotify/DespotifyUtils.hxx
index 835b901a2..a21632bb8 100644
--- a/src/lib/despotify/DespotifyUtils.hxx
+++ b/src/lib/despotify/DespotifyUtils.hxx
@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_DESPOTIFY_H
-#define MPD_DESPOTIFY_H
+#ifndef MPD_DESPOTIFY_UTILS_HXX
+#define MPD_DESPOTIFY_UTILS_HXX
struct Tag;
struct despotify_session;
@@ -35,7 +35,8 @@ extern const class Domain despotify_domain;
* @return a pointer to the despotify session, or nullptr if it can't
* be initialized (e.g., if the configuration isn't supplied)
*/
-struct despotify_session *mpd_despotify_get_session(void);
+struct despotify_session *
+mpd_despotify_get_session();
/**
* Create a MPD tags structure from a spotify track
@@ -57,15 +58,19 @@ mpd_despotify_tag_from_track(const ds_track &track);
*
* @return true if the callback could be registered
*/
-bool mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int, void *, void *),
- void *cb_data);
+bool
+mpd_despotify_register_callback(void (*cb)(struct despotify_session *, int,
+ void *, void *),
+ void *cb_data);
/**
* Unregister a despotify callback.
*
* @param cb the callback to unregister.
*/
-void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int, void *, void *));
+void
+mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, int,
+ void *, void *));
#endif