Commit 9ec06910 authored by Max Kellermann's avatar Max Kellermann

input,playlist/despotify: convert to C++

parent 7d21d60d
...@@ -79,8 +79,6 @@ mpd_headers = \ ...@@ -79,8 +79,6 @@ mpd_headers = \
src/decoder/pcm_decoder_plugin.h \ src/decoder/pcm_decoder_plugin.h \
src/input_plugin.h \ src/input_plugin.h \
src/input_stream.h \ src/input_stream.h \
src/input/despotify_input_plugin.h \
src/despotify_utils.h \
src/text_input_stream.h \ src/text_input_stream.h \
src/icy_server.h \ src/icy_server.h \
src/ls.h \ src/ls.h \
...@@ -106,7 +104,6 @@ mpd_headers = \ ...@@ -106,7 +104,6 @@ mpd_headers = \
src/playlist/asx_playlist_plugin.h \ src/playlist/asx_playlist_plugin.h \
src/playlist/rss_playlist_plugin.h \ src/playlist/rss_playlist_plugin.h \
src/playlist/lastfm_playlist_plugin.h \ src/playlist/lastfm_playlist_plugin.h \
src/playlist/despotify_playlist_plugin.h \
src/playlist/cue_playlist_plugin.h \ src/playlist/cue_playlist_plugin.h \
src/poison.h \ src/poison.h \
src/riff.h \ src/riff.h \
...@@ -311,7 +308,7 @@ endif ...@@ -311,7 +308,7 @@ endif
if ENABLE_DESPOTIFY if ENABLE_DESPOTIFY
src_mpd_SOURCES += \ src_mpd_SOURCES += \
src/despotify_utils.c src/DespotifyUtils.cxx src/DespotifyUtils.hxx
endif endif
if ENABLE_INOTIFY if ENABLE_INOTIFY
...@@ -756,7 +753,9 @@ libinput_a_SOURCES += \ ...@@ -756,7 +753,9 @@ libinput_a_SOURCES += \
endif endif
if ENABLE_DESPOTIFY if ENABLE_DESPOTIFY
libinput_a_SOURCES += src/input/despotify_input_plugin.c libinput_a_SOURCES += \
src/input/DespotifyInputPlugin.cxx \
src/input/DespotifyInputPlugin.hxx
endif endif
...@@ -938,7 +937,9 @@ libplaylist_plugins_a_SOURCES += src/playlist/lastfm_playlist_plugin.c ...@@ -938,7 +937,9 @@ libplaylist_plugins_a_SOURCES += src/playlist/lastfm_playlist_plugin.c
endif endif
if ENABLE_DESPOTIFY if ENABLE_DESPOTIFY
libplaylist_plugins_a_SOURCES += src/playlist/despotify_playlist_plugin.c libplaylist_plugins_a_SOURCES += \
src/playlist/DespotifyPlaylistPlugin.cxx \
src/playlist/DespotifyPlaylistPlugin.hxx
endif endif
if ENABLE_SOUNDCLOUD if ENABLE_SOUNDCLOUD
...@@ -1189,16 +1190,11 @@ test_run_filter_SOURCES = test/run_filter.c \ ...@@ -1189,16 +1190,11 @@ test_run_filter_SOURCES = test/run_filter.c \
src/AudioCompress/compress.c src/AudioCompress/compress.c
if ENABLE_DESPOTIFY if ENABLE_DESPOTIFY
test_read_tags_SOURCES += \ test_read_tags_SOURCES += src/DespotifyUtils.cxx
src/despotify_utils.c test_run_input_SOURCES += src/DespotifyUtils.cxx
test_run_input_SOURCES += \ test_dump_text_file_SOURCES += src/DespotifyUtils.cxx
src/despotify_utils.c test_dump_playlist_SOURCES += src/DespotifyUtils.cxx
test_dump_text_file_SOURCES += \ test_run_decoder_SOURCES += src/DespotifyUtils.cxx
src/despotify_utils.c
test_dump_playlist_SOURCES += \
src/despotify_utils.c
test_run_decoder_SOURCES += \
src/despotify_utils.c
endif endif
if ENABLE_ENCODER if ENABLE_ENCODER
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,12 +17,15 @@ ...@@ -17,12 +17,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "despotify_utils.h" #include "DespotifyUtils.hxx"
#include "tag.h" #include "tag.h"
#include "conf.h" #include "conf.h"
#include <glib.h> #include <glib.h>
extern "C" {
#include <despotify.h> #include <despotify.h>
}
static struct despotify_session *g_session; static struct despotify_session *g_session;
static void (*registered_callbacks[8])(struct despotify_session *, static void (*registered_callbacks[8])(struct despotify_session *,
...@@ -116,24 +119,25 @@ struct despotify_session *mpd_despotify_get_session(void) ...@@ -116,24 +119,25 @@ struct despotify_session *mpd_despotify_get_session(void)
if (user == NULL || passwd == NULL) { if (user == NULL || passwd == NULL) {
g_debug("disabling despotify because account is not configured"); g_debug("disabling despotify because account is not configured");
return NULL; return nullptr;
} }
if (!despotify_init()) { if (!despotify_init()) {
g_debug("Can't initialize despotify\n"); g_debug("Can't initialize despotify\n");
return false; return nullptr;
} }
g_session = despotify_init_client(callback, NULL, g_session = despotify_init_client(callback, NULL,
high_bitrate, true); high_bitrate, true);
if (!g_session) { if (!g_session) {
g_debug("Can't initialize despotify client\n"); g_debug("Can't initialize despotify client\n");
return false; return nullptr;
} }
if (!despotify_authenticate(g_session, user, passwd)) { if (!despotify_authenticate(g_session, user, passwd)) {
g_debug("Can't authenticate despotify session\n"); g_debug("Can't authenticate despotify session\n");
despotify_exit(g_session); despotify_exit(g_session);
return false; return nullptr;
} }
return g_session; return g_session;
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#ifndef MPD_DESPOTIFY_H #ifndef MPD_DESPOTIFY_H
#define MPD_DESPOTIFY_H #define MPD_DESPOTIFY_H
#include <stdbool.h>
struct despotify_session; struct despotify_session;
struct ds_track; struct ds_track;
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#endif #endif
#ifdef ENABLE_DESPOTIFY #ifdef ENABLE_DESPOTIFY
#include "input/despotify_input_plugin.h" #include "input/DespotifyInputPlugin.hxx"
#endif #endif
#include <glib.h> #include <glib.h>
......
/* /*
* Copyright (C) 2011 The Music Player Daemon Project * Copyright (C) 2011-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,18 +18,21 @@ ...@@ -18,18 +18,21 @@
*/ */
#include "config.h" #include "config.h"
#include "input/despotify_input_plugin.h" #include "DespotifyInputPlugin.hxx"
#include "DespotifyUtils.hxx"
#include "input_internal.h" #include "input_internal.h"
#include "input_plugin.h" #include "input_plugin.h"
#include "tag.h" #include "tag.h"
#include "despotify_utils.h"
extern "C" {
#include <despotify.h>
}
#include <glib.h> #include <glib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <despotify.h>
#include <stdio.h> #include <stdio.h>
...@@ -220,11 +223,16 @@ input_despotify_tag(struct input_stream *is) ...@@ -220,11 +223,16 @@ input_despotify_tag(struct input_stream *is)
} }
const struct input_plugin input_plugin_despotify = { const struct input_plugin input_plugin_despotify = {
.name = "spt", "spt",
.open = input_despotify_open, nullptr,
.close = input_despotify_close, nullptr,
.read = input_despotify_read, input_despotify_open,
.eof = input_despotify_eof, input_despotify_close,
.seek = input_despotify_seek, nullptr,
nullptr,
.tag = input_despotify_tag, .tag = input_despotify_tag,
nullptr,
input_despotify_read,
input_despotify_eof,
input_despotify_seek,
}; };
/* /*
* Copyright (C) 2011 The Music Player Daemon Project * Copyright (C) 2011-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef INPUT_DESPOTIFY_H #ifndef INPUT_DESPOTIFY_HXX
#define INPUT_DESPOTIFY_H #define INPUT_DESPOTIFY_HXX
extern const struct input_plugin input_plugin_despotify; extern const struct input_plugin input_plugin_despotify;
......
/* /*
* Copyright (C) 2011 The Music Player Daemon Project * Copyright (C) 2011-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
*/ */
#include "config.h" #include "config.h"
#include "playlist/despotify_playlist_plugin.h" #include "DespotifyPlaylistPlugin.hxx"
#include "DespotifyUtils.hxx"
#include "playlist_plugin.h" #include "playlist_plugin.h"
#include "playlist_list.h" #include "playlist_list.h"
#include "conf.h" #include "conf.h"
...@@ -26,14 +27,16 @@ ...@@ -26,14 +27,16 @@
#include "tag.h" #include "tag.h"
#include "song.h" #include "song.h"
#include "input_stream.h" #include "input_stream.h"
#include "despotify_utils.h"
extern "C" {
#include <despotify.h>
}
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <despotify.h>
struct despotify_playlist { struct despotify_playlist {
struct playlist_provider base; struct playlist_provider base;
...@@ -131,7 +134,7 @@ despotify_playlist_open_uri(const char *url, G_GNUC_UNUSED GMutex *mutex, ...@@ -131,7 +134,7 @@ despotify_playlist_open_uri(const char *url, G_GNUC_UNUSED GMutex *mutex,
ctx = g_new(struct despotify_playlist, 1); ctx = g_new(struct despotify_playlist, 1);
ctx->list = NULL; ctx->list = nullptr;
ctx->session = session; ctx->session = session;
playlist_provider_init(&ctx->base, &despotify_playlist_plugin); playlist_provider_init(&ctx->base, &despotify_playlist_plugin);
...@@ -159,7 +162,7 @@ clean_playlist: ...@@ -159,7 +162,7 @@ clean_playlist:
g_slist_free(ctx->list); g_slist_free(ctx->list);
clean_none: clean_none:
return NULL; return nullptr;
} }
static void static void
...@@ -175,7 +178,7 @@ despotify_playlist_close(struct playlist_provider *_playlist) ...@@ -175,7 +178,7 @@ despotify_playlist_close(struct playlist_provider *_playlist)
{ {
struct despotify_playlist *ctx = (struct despotify_playlist *)_playlist; struct despotify_playlist *ctx = (struct despotify_playlist *)_playlist;
g_slist_foreach(ctx->list, track_free_callback, NULL); g_slist_foreach(ctx->list, track_free_callback, nullptr);
g_slist_free(ctx->list); g_slist_free(ctx->list);
g_free(ctx); g_free(ctx);
...@@ -186,13 +189,12 @@ static struct song * ...@@ -186,13 +189,12 @@ static struct song *
despotify_playlist_read(struct playlist_provider *_playlist) despotify_playlist_read(struct playlist_provider *_playlist)
{ {
struct despotify_playlist *ctx = (struct despotify_playlist *)_playlist; struct despotify_playlist *ctx = (struct despotify_playlist *)_playlist;
struct song *out;
if (!ctx->list) if (!ctx->list)
return NULL; return nullptr;
/* Remove the current track */ /* Remove the current track */
out = ctx->list->data; song *out = (song *)ctx->list->data;
ctx->list = g_slist_remove(ctx->list, out); ctx->list = g_slist_remove(ctx->list, out);
return out; return out;
...@@ -200,18 +202,22 @@ despotify_playlist_read(struct playlist_provider *_playlist) ...@@ -200,18 +202,22 @@ despotify_playlist_read(struct playlist_provider *_playlist)
static const char *const despotify_schemes[] = { static const char *const despotify_schemes[] = {
"spt", "spt",
NULL nullptr
}; };
const struct playlist_plugin despotify_playlist_plugin = { const struct playlist_plugin despotify_playlist_plugin = {
.name = "despotify", "despotify",
despotify_playlist_init,
despotify_playlist_finish,
.init = despotify_playlist_init, despotify_playlist_open_uri,
.finish = despotify_playlist_finish, nullptr,
.open_uri = despotify_playlist_open_uri, despotify_playlist_close,
.read = despotify_playlist_read, despotify_playlist_read,
.close = despotify_playlist_close,
.schemes = despotify_schemes, despotify_schemes,
nullptr,
nullptr,
}; };
/* /*
* Copyright (C) 2011 The Music Player Daemon Project * Copyright (C) 2011-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_PLAYLIST_DESPOTIFY_PLAYLIST_PLUGIN_H #ifndef MPD_PLAYLIST_DESPOTIFY_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_DESPOTIFY_PLAYLIST_PLUGIN_H #define MPD_PLAYLIST_DESPOTIFY_PLAYLIST_PLUGIN_HXX
extern const struct playlist_plugin despotify_playlist_plugin; extern const struct playlist_plugin despotify_playlist_plugin;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "playlist/m3u_playlist_plugin.h" #include "playlist/m3u_playlist_plugin.h"
#include "playlist/xspf_playlist_plugin.h" #include "playlist/xspf_playlist_plugin.h"
#include "playlist/lastfm_playlist_plugin.h" #include "playlist/lastfm_playlist_plugin.h"
#include "playlist/despotify_playlist_plugin.h" #include "playlist/DespotifyPlaylistPlugin.hxx"
#include "playlist/soundcloud_playlist_plugin.h" #include "playlist/soundcloud_playlist_plugin.h"
#include "playlist/pls_playlist_plugin.h" #include "playlist/pls_playlist_plugin.h"
#include "playlist/asx_playlist_plugin.h" #include "playlist/asx_playlist_plugin.h"
......
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